Skip to content

Commit ad9db34

Browse files
committed
v0.5.3&修复脚本更新bug&配置面板bug
1 parent 56fb8f3 commit ad9db34

File tree

10 files changed

+81
-49
lines changed

10 files changed

+81
-49
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
node_modules
22
build/report/
33
build/scriptcat/src/*.js
4+
build/scriptcat/src/*
45
build/scriptcat/**.html
56
build/scriptcat/src/*.txt
67
build/scriptcat/src/*.ttf

build/scriptcat/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "ScriptCat",
4-
"version": "0.5.2",
4+
"version": "0.5.3",
55
"description": "脚本猫,一个用户脚本的框架,可编写脚本每天帮你自动处理事务.",
66
"background": {
77
"page": "background.html"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptcat",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
55
"scripts": {
66
"test": "jest",

src/apps/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const ExtVersion = "0.5.2";
1+
export const ExtVersion = "0.5.3";
22

33
export const Server="https://sc.icodef.com/";
44

src/apps/grant/frontend.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ export class FrontendGrant implements ScriptContext {
7777
};
7878
if (callback) {
7979
this.request.set(grant.request, (grant: Grant) => {
80+
callback(grant);
8081
if (grant.error) {
8182
throw grant.name + ': ' + grant.value + ' ErrCode:' + grant.error + ' ErrMsg:' + grant.errorMsg;
8283
}
83-
callback(grant);
8484
});
8585
}
8686
this.browserMsg.send("grant", grant);
@@ -138,6 +138,10 @@ export class FrontendGrant implements ScriptContext {
138138
}
139139

140140
this.postRequest('GM_xmlhttpRequest', [param], (grant: Grant) => {
141+
if (grant.error) {
142+
details.onerror && details.onerror(grant.errorMsg);
143+
return;
144+
}
141145
switch (grant.data.type) {
142146
case 'load':
143147
details.onload && details.onload(grant.data.data);
@@ -457,10 +461,10 @@ export class SandboxContext extends FrontendGrant {
457461
};
458462
if (callback) {
459463
this.request.set(grant.request, (grant: Grant) => {
464+
callback(grant);
460465
if (grant.error) {
461466
throw grant.name + ': ' + grant.value + ' ErrCode:' + grant.error + ' ErrMsg:' + grant.errorMsg;
462467
}
463-
callback(grant);
464468
});
465469
}
466470
top!.postMessage(grant, '*');

src/apps/script/manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ export class ScriptManager {
205205
this.loadResouce(script);
206206
copyScript(script, oldScript);
207207
script.updatetime = new Date().getTime();
208+
await this.scriptModel.save(script);
208209
if (script.status == SCRIPT_STATUS_ENABLE) {
209210
await this.disableScript(script);
210211
await this.enableScript(script);
211212
}
212-
await this.scriptModel.save(script);
213213
return resolve(true);
214214
});
215215
}

src/apps/script/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export function loadScriptByUrl(url: string): Promise<ScriptUrlInfo | undefined>
8686
export function copyScript(script: Script, old: Script) {
8787
script.id = old.id;
8888
script.createtime = old.createtime;
89-
script.status = old.status;
9089
script.checktime = old.checktime;
9190
script.lastruntime = old.lastruntime;
9291
script.delayruntime = old.delayruntime;

src/background.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ get(Server + "api/v1/system/version", (str) => {
8787
let resp = JSON.parse(str);
8888
if (resp.data.notice !== items['oldNotice']) {
8989
chrome.storage.local.set({
90-
notice: resp.data.notice
90+
notice: resp.data.notice,
9191
});
9292
}
93+
chrome.storage.local.set({
94+
version: resp.data.version,
95+
});
9396
});
9497
});
9598
setInterval(() => {
@@ -101,6 +104,9 @@ setInterval(() => {
101104
notice: resp.data.notice
102105
});
103106
}
107+
chrome.storage.local.set({
108+
version: resp.data.version,
109+
});
104110
});
105111
});
106112
}, 600000)

src/views/pages/Option/tabs/ScriptList.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ import { mdiClockTimeFourOutline, mdiAlertCircleOutline } from "@mdi/js";
503503
504504
import BgCloud from "@components/BgCloud.vue";
505505
import { App } from "@App/apps/app";
506+
import { mode } from "crypto-js";
506507
507508
dayjs.locale("zh-cn");
508509
dayjs.extend(relativeTime);
@@ -713,14 +714,14 @@ export default class ScriptList extends Vue {
713714
let item = script.config![name][itemKey];
714715
let key = name + "." + itemKey;
715716
let model: Value | undefined;
716-
if (script?.namespace) {
717+
if (script.metadata["storagename"]) {
717718
model = await this.valueModel.findOne({
718-
namespace: script.namespace,
719+
storageName: script.metadata["storagename"][0],
719720
key: key,
720721
});
721722
} else {
722723
model = await this.valueModel.findOne({
723-
scriptId: script?.id,
724+
scriptId: script.id,
724725
key: key,
725726
});
726727
}
@@ -732,18 +733,18 @@ export default class ScriptList extends Vue {
732733
} else {
733734
model = {
734735
id: 0,
735-
scriptId: script?.id || 0,
736+
scriptId: script.id,
736737
storageName:
737-
(script?.metadata["storage"] &&
738-
script?.metadata["storagename"][0]) ||
738+
(script.metadata["storagename"] &&
739+
script.metadata["storagename"][0]) ||
739740
"",
740741
key: key,
741742
value: item.value,
742743
createtime: new Date().getTime(),
743744
};
744745
}
745746
this.valueModel.save(model);
746-
MsgCenter.connect(ScriptValueChange, model);
747+
MsgCenter.connect(ScriptValueChange, { model: model, tabid: undefined });
747748
}
748749
success();
749750
}

src/views/pages/Popup/index.vue

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@
5555
</v-list>
5656
</v-menu>
5757
</v-app-bar>
58-
<v-main class="content" style="max-height: 500px; overflow-y: scroll; padding: 6px">
58+
<v-main
59+
class="content"
60+
style="max-height: 500px; overflow-y: scroll; padding: 6px"
61+
>
5962
<v-card
6063
id="notice"
6164
v-show="isShowNotice"
@@ -85,7 +88,20 @@
8588
<span class="v-text d-flex" style="color: #fff"
8689
>当前版本: {{ version }} {{ isdebug ? "debug" : "" }}</span
8790
>
88-
<span class="v-text d-flex" style="color: #fff">已是最新版本</span>
91+
<span
92+
v-if="version == remoteVersion"
93+
class="v-text d-flex"
94+
style="color: #fff"
95+
>已是最新版本</span
96+
>
97+
<a
98+
v-else
99+
class="v-text d-flex"
100+
style="color: #e3ff00; text-decoration: none"
101+
href="https://github.com/scriptscat/scriptcat/releases"
102+
target="_blank"
103+
>有新的版本</a
104+
>
89105
</div>
90106
</v-footer>
91107
</v-app>
@@ -132,6 +148,7 @@ export default class Popup extends Vue {
132148
tabs = null;
133149
134150
version = ExtVersion;
151+
remoteVersion = "";
135152
isdebug = process.env.NODE_ENV == "development";
136153
137154
panel = [0];
@@ -188,42 +205,46 @@ export default class Popup extends Vue {
188205
}
189206
190207
created() {
191-
chrome.storage.local.get(["notice", "oldNotice"], (items) => {
208+
chrome.storage.local.get(["notice", "oldNotice", "version"], (items) => {
192209
this.notice = items["notice"];
193210
this.oldNotice = items["oldNotice"];
211+
this.remoteVersion = items["version"];
194212
});
195-
chrome.tabs.query({ active: true, lastFocusedWindow: true }, async (tabs) => {
196-
MsgCenter.sendMessage(
197-
RequestTabRunScript,
198-
{
199-
tabId: tabs[0].id,
200-
url: tabs[0].url,
201-
},
202-
(val) => {
203-
this.scripts = val.run;
204-
this.menu = val.runMenu || {};
205-
this.bgMenu = val.bgMenu || {};
206-
// 将有菜单的后台脚本,放到运行脚本中
207-
this.scriptConrtoller
208-
.scriptList((where) => {
209-
return where
210-
.where("type")
211-
.anyOf([SCRIPT_TYPE_BACKGROUND, SCRIPT_TYPE_CRONTAB]);
212-
})
213-
.then((result) => {
214-
this.bgScripts = result;
215-
let map = new Map();
216-
result.forEach((val) => {
217-
map.set(val.id, val);
213+
chrome.tabs.query(
214+
{ active: true, lastFocusedWindow: true },
215+
async (tabs) => {
216+
MsgCenter.sendMessage(
217+
RequestTabRunScript,
218+
{
219+
tabId: tabs[0].id,
220+
url: tabs[0].url,
221+
},
222+
(val) => {
223+
this.scripts = val.run;
224+
this.menu = val.runMenu || {};
225+
this.bgMenu = val.bgMenu || {};
226+
// 将有菜单的后台脚本,放到运行脚本中
227+
this.scriptConrtoller
228+
.scriptList((where) => {
229+
return where
230+
.where("type")
231+
.anyOf([SCRIPT_TYPE_BACKGROUND, SCRIPT_TYPE_CRONTAB]);
232+
})
233+
.then((result) => {
234+
this.bgScripts = result;
235+
let map = new Map();
236+
result.forEach((val) => {
237+
map.set(val.id, val);
238+
});
239+
for (const id in this.bgMenu) {
240+
this.scripts.push(map.get(parseInt(id)));
241+
this.menu[id] = this.bgMenu[id];
242+
}
218243
});
219-
for (const id in this.bgMenu) {
220-
this.scripts.push(map.get(parseInt(id)));
221-
this.menu[id] = this.bgMenu[id];
222-
}
223-
});
224-
}
225-
);
226-
});
244+
}
245+
);
246+
}
247+
);
227248
}
228249
}
229250
</script>

0 commit comments

Comments
 (0)