From ad9db340ae7e5c1f8f4a4648586743f932f26299 Mon Sep 17 00:00:00 2001 From: CodFrm Date: Fri, 10 Sep 2021 14:21:06 +0800 Subject: [PATCH] =?UTF-8?q?v0.5.3&=E4=BF=AE=E5=A4=8D=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E6=9B=B4=E6=96=B0bug&=E9=85=8D=E7=BD=AE=E9=9D=A2=E6=9D=BFbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + build/scriptcat/manifest.json | 2 +- package.json | 2 +- src/apps/config.ts | 2 +- src/apps/grant/frontend.ts | 8 +- src/apps/script/manager.ts | 2 +- src/apps/script/utils.ts | 1 - src/background.ts | 8 +- src/views/pages/Option/tabs/ScriptList.vue | 15 ++-- src/views/pages/Popup/index.vue | 89 +++++++++++++--------- 10 files changed, 81 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 24409fd6..75567ce9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules build/report/ build/scriptcat/src/*.js +build/scriptcat/src/* build/scriptcat/**.html build/scriptcat/src/*.txt build/scriptcat/src/*.ttf diff --git a/build/scriptcat/manifest.json b/build/scriptcat/manifest.json index 5dae0921..b2aa54c1 100644 --- a/build/scriptcat/manifest.json +++ b/build/scriptcat/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "ScriptCat", - "version": "0.5.2", + "version": "0.5.3", "description": "脚本猫,一个用户脚本的框架,可编写脚本每天帮你自动处理事务.", "background": { "page": "background.html" diff --git a/package.json b/package.json index 4f686daa..e5f7e343 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scriptcat", - "version": "0.5.2", + "version": "0.5.3", "description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!", "scripts": { "test": "jest", diff --git a/src/apps/config.ts b/src/apps/config.ts index a9886ee1..32027ca2 100644 --- a/src/apps/config.ts +++ b/src/apps/config.ts @@ -1,4 +1,4 @@ -export const ExtVersion = "0.5.2"; +export const ExtVersion = "0.5.3"; export const Server="https://sc.icodef.com/"; diff --git a/src/apps/grant/frontend.ts b/src/apps/grant/frontend.ts index b2865389..148ba39c 100644 --- a/src/apps/grant/frontend.ts +++ b/src/apps/grant/frontend.ts @@ -77,10 +77,10 @@ export class FrontendGrant implements ScriptContext { }; if (callback) { this.request.set(grant.request, (grant: Grant) => { + callback(grant); if (grant.error) { throw grant.name + ': ' + grant.value + ' ErrCode:' + grant.error + ' ErrMsg:' + grant.errorMsg; } - callback(grant); }); } this.browserMsg.send("grant", grant); @@ -138,6 +138,10 @@ export class FrontendGrant implements ScriptContext { } this.postRequest('GM_xmlhttpRequest', [param], (grant: Grant) => { + if (grant.error) { + details.onerror && details.onerror(grant.errorMsg); + return; + } switch (grant.data.type) { case 'load': details.onload && details.onload(grant.data.data); @@ -457,10 +461,10 @@ export class SandboxContext extends FrontendGrant { }; if (callback) { this.request.set(grant.request, (grant: Grant) => { + callback(grant); if (grant.error) { throw grant.name + ': ' + grant.value + ' ErrCode:' + grant.error + ' ErrMsg:' + grant.errorMsg; } - callback(grant); }); } top!.postMessage(grant, '*'); diff --git a/src/apps/script/manager.ts b/src/apps/script/manager.ts index a1f25040..53491134 100644 --- a/src/apps/script/manager.ts +++ b/src/apps/script/manager.ts @@ -205,11 +205,11 @@ export class ScriptManager { this.loadResouce(script); copyScript(script, oldScript); script.updatetime = new Date().getTime(); + await this.scriptModel.save(script); if (script.status == SCRIPT_STATUS_ENABLE) { await this.disableScript(script); await this.enableScript(script); } - await this.scriptModel.save(script); return resolve(true); }); } diff --git a/src/apps/script/utils.ts b/src/apps/script/utils.ts index 0956a68c..eb5ed4c1 100644 --- a/src/apps/script/utils.ts +++ b/src/apps/script/utils.ts @@ -86,7 +86,6 @@ export function loadScriptByUrl(url: string): Promise export function copyScript(script: Script, old: Script) { script.id = old.id; script.createtime = old.createtime; - script.status = old.status; script.checktime = old.checktime; script.lastruntime = old.lastruntime; script.delayruntime = old.delayruntime; diff --git a/src/background.ts b/src/background.ts index c55205ab..0a289d3e 100644 --- a/src/background.ts +++ b/src/background.ts @@ -87,9 +87,12 @@ get(Server + "api/v1/system/version", (str) => { let resp = JSON.parse(str); if (resp.data.notice !== items['oldNotice']) { chrome.storage.local.set({ - notice: resp.data.notice + notice: resp.data.notice, }); } + chrome.storage.local.set({ + version: resp.data.version, + }); }); }); setInterval(() => { @@ -101,6 +104,9 @@ setInterval(() => { notice: resp.data.notice }); } + chrome.storage.local.set({ + version: resp.data.version, + }); }); }); }, 600000) diff --git a/src/views/pages/Option/tabs/ScriptList.vue b/src/views/pages/Option/tabs/ScriptList.vue index 62c061f2..dd1ad6d2 100644 --- a/src/views/pages/Option/tabs/ScriptList.vue +++ b/src/views/pages/Option/tabs/ScriptList.vue @@ -503,6 +503,7 @@ import { mdiClockTimeFourOutline, mdiAlertCircleOutline } from "@mdi/js"; import BgCloud from "@components/BgCloud.vue"; import { App } from "@App/apps/app"; +import { mode } from "crypto-js"; dayjs.locale("zh-cn"); dayjs.extend(relativeTime); @@ -713,14 +714,14 @@ export default class ScriptList extends Vue { let item = script.config![name][itemKey]; let key = name + "." + itemKey; let model: Value | undefined; - if (script?.namespace) { + if (script.metadata["storagename"]) { model = await this.valueModel.findOne({ - namespace: script.namespace, + storageName: script.metadata["storagename"][0], key: key, }); } else { model = await this.valueModel.findOne({ - scriptId: script?.id, + scriptId: script.id, key: key, }); } @@ -732,10 +733,10 @@ export default class ScriptList extends Vue { } else { model = { id: 0, - scriptId: script?.id || 0, + scriptId: script.id, storageName: - (script?.metadata["storage"] && - script?.metadata["storagename"][0]) || + (script.metadata["storagename"] && + script.metadata["storagename"][0]) || "", key: key, value: item.value, @@ -743,7 +744,7 @@ export default class ScriptList extends Vue { }; } this.valueModel.save(model); - MsgCenter.connect(ScriptValueChange, model); + MsgCenter.connect(ScriptValueChange, { model: model, tabid: undefined }); } success(); } diff --git a/src/views/pages/Popup/index.vue b/src/views/pages/Popup/index.vue index c1c7b3a7..6f4a673c 100644 --- a/src/views/pages/Popup/index.vue +++ b/src/views/pages/Popup/index.vue @@ -55,7 +55,10 @@ - + 当前版本: {{ version }} {{ isdebug ? "debug" : "" }} - 已是最新版本 + 已是最新版本 + 有新的版本 @@ -132,6 +148,7 @@ export default class Popup extends Vue { tabs = null; version = ExtVersion; + remoteVersion = ""; isdebug = process.env.NODE_ENV == "development"; panel = [0]; @@ -188,42 +205,46 @@ export default class Popup extends Vue { } created() { - chrome.storage.local.get(["notice", "oldNotice"], (items) => { + chrome.storage.local.get(["notice", "oldNotice", "version"], (items) => { this.notice = items["notice"]; this.oldNotice = items["oldNotice"]; + this.remoteVersion = items["version"]; }); - chrome.tabs.query({ active: true, lastFocusedWindow: true }, async (tabs) => { - MsgCenter.sendMessage( - RequestTabRunScript, - { - tabId: tabs[0].id, - url: tabs[0].url, - }, - (val) => { - this.scripts = val.run; - this.menu = val.runMenu || {}; - this.bgMenu = val.bgMenu || {}; - // 将有菜单的后台脚本,放到运行脚本中 - this.scriptConrtoller - .scriptList((where) => { - return where - .where("type") - .anyOf([SCRIPT_TYPE_BACKGROUND, SCRIPT_TYPE_CRONTAB]); - }) - .then((result) => { - this.bgScripts = result; - let map = new Map(); - result.forEach((val) => { - map.set(val.id, val); + chrome.tabs.query( + { active: true, lastFocusedWindow: true }, + async (tabs) => { + MsgCenter.sendMessage( + RequestTabRunScript, + { + tabId: tabs[0].id, + url: tabs[0].url, + }, + (val) => { + this.scripts = val.run; + this.menu = val.runMenu || {}; + this.bgMenu = val.bgMenu || {}; + // 将有菜单的后台脚本,放到运行脚本中 + this.scriptConrtoller + .scriptList((where) => { + return where + .where("type") + .anyOf([SCRIPT_TYPE_BACKGROUND, SCRIPT_TYPE_CRONTAB]); + }) + .then((result) => { + this.bgScripts = result; + let map = new Map(); + result.forEach((val) => { + map.set(val.id, val); + }); + for (const id in this.bgMenu) { + this.scripts.push(map.get(parseInt(id))); + this.menu[id] = this.bgMenu[id]; + } }); - for (const id in this.bgMenu) { - this.scripts.push(map.get(parseInt(id))); - this.menu[id] = this.bgMenu[id]; - } - }); - } - ); - }); + } + ); + } + ); } }