Skip to content

Commit

Permalink
v0.5.3&修复脚本更新bug&配置面板bug
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Sep 10, 2021
1 parent 56fb8f3 commit ad9db34
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/scriptcat/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "ScriptCat",
"version": "0.5.2",
"version": "0.5.3",
"description": "脚本猫,一个用户脚本的框架,可编写脚本每天帮你自动处理事务.",
"background": {
"page": "background.html"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scriptcat",
"version": "0.5.2",
"version": "0.5.3",
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
"scripts": {
"test": "jest",
Expand Down
2 changes: 1 addition & 1 deletion src/apps/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const ExtVersion = "0.5.2";
export const ExtVersion = "0.5.3";

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

8 changes: 6 additions & 2 deletions src/apps/grant/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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, '*');
Expand Down
2 changes: 1 addition & 1 deletion src/apps/script/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
1 change: 0 additions & 1 deletion src/apps/script/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export function loadScriptByUrl(url: string): Promise<ScriptUrlInfo | undefined>
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;
Expand Down
8 changes: 7 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -101,6 +104,9 @@ setInterval(() => {
notice: resp.data.notice
});
}
chrome.storage.local.set({
version: resp.data.version,
});
});
});
}, 600000)
Expand Down
15 changes: 8 additions & 7 deletions src/views/pages/Option/tabs/ScriptList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
});
}
Expand All @@ -732,18 +733,18 @@ 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,
createtime: new Date().getTime(),
};
}
this.valueModel.save(model);
MsgCenter.connect(ScriptValueChange, model);
MsgCenter.connect(ScriptValueChange, { model: model, tabid: undefined });
}
success();
}
Expand Down
89 changes: 55 additions & 34 deletions src/views/pages/Popup/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
</v-list>
</v-menu>
</v-app-bar>
<v-main class="content" style="max-height: 500px; overflow-y: scroll; padding: 6px">
<v-main
class="content"
style="max-height: 500px; overflow-y: scroll; padding: 6px"
>
<v-card
id="notice"
v-show="isShowNotice"
Expand Down Expand Up @@ -85,7 +88,20 @@
<span class="v-text d-flex" style="color: #fff"
>当前版本: {{ version }} {{ isdebug ? "debug" : "" }}</span
>
<span class="v-text d-flex" style="color: #fff">已是最新版本</span>
<span
v-if="version == remoteVersion"
class="v-text d-flex"
style="color: #fff"
>已是最新版本</span
>
<a
v-else
class="v-text d-flex"
style="color: #e3ff00; text-decoration: none"
href="https://github.com/scriptscat/scriptcat/releases"
target="_blank"
>有新的版本</a
>
</div>
</v-footer>
</v-app>
Expand Down Expand Up @@ -132,6 +148,7 @@ export default class Popup extends Vue {
tabs = null;
version = ExtVersion;
remoteVersion = "";
isdebug = process.env.NODE_ENV == "development";
panel = [0];
Expand Down Expand Up @@ -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];
}
});
}
);
});
}
);
}
);
}
}
</script>
Expand Down

0 comments on commit ad9db34

Please sign in to comment.