Skip to content

Commit daff97c

Browse files
committed
fix bug & ui 调整
1 parent 4a68852 commit daff97c

File tree

18 files changed

+143
-142
lines changed

18 files changed

+143
-142
lines changed

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.4.1",
4+
"version": "0.4.2",
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.4.1",
3+
"version": "0.4.2",
44
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
55
"scripts": {
66
"test": "jest",

public/popup.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
margin: 0;
2323
padding: 0;
2424
border: 0;
25-
width: 500px;
25+
width: 450px;
2626
/* height: 500px; */
27-
min-height: 100px;
27+
min-height: 150px;
2828
max-height: 800px;
2929
/* overflow-y: auto; */
3030
/* overflow: hidden; */

scripts/pack.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ var AdmZip = require("adm-zip");
33
var pjson = require('../package.json');
44
const { execSync } = require("child_process");
55

6+
// 处理manifest version
7+
let str = fs.readFileSync("./build/scriptcat/manifest.json").toString();
8+
str = str.replace(/"version": "(.*?)"/, '"version": "' + pjson.version + '"');
9+
fs.writeFileSync("./build/scriptcat/manifest.json", str);
10+
11+
// 处理config.ts version
12+
str = fs.readFileSync("./src/apps/config.ts").toString();
13+
str = str.replace(/ExtVersion = "(.*?)";/, 'ExtVersion = "' + pjson.version + '";');
14+
fs.writeFileSync("./src/apps/config.ts", str);
15+
616
execSync("npm run build");
717

818
execSync("npm run build-no-split");
919

10-
// 处理manifest version
11-
let jsonStr = fs.readFileSync("./build/scriptcat/manifest.json").toString();
12-
jsonStr = jsonStr.replace(/"version": "(.*?)"/, '"version": "' + pjson.version + '"');
13-
fs.writeFileSync("./build/scriptcat/manifest.json", jsonStr);
14-
1520
// 处理 ts.worker.js 和 editor.worker.js
1621
let list = fs.readdirSync("./build/scriptcat/src");
1722
let monaco = [];

src/apps/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const ExtVersion = "0.4.2";

src/apps/script/background.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export class Background {
2222

2323
public disableScript(script: Script): Promise<void> {
2424
return new Promise(async resolve => {
25-
sandbox.postMessage({ action: 'stop', data: script, isdebug: false }, '*');
25+
sandbox.postMessage({ action: 'disable', data: script}, '*');
2626
function listener(event: MessageEvent) {
27-
if (event.data.action != "stop") {
27+
if (event.data.action != "disable") {
2828
return;
2929
}
3030
resolve();

src/apps/script/controller.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { v5 as uuidv5 } from 'uuid';
2-
import { SCRIPT_STATUS_ENABLE, SCRIPT_STATUS_DISABLE, Script, SCRIPT_RUN_STATUS_COMPLETE, SCRIPT_STATUS_PREPARE, SCRIPT_TYPE_BACKGROUND, SCRIPT_TYPE_CRONTAB, SCRIPT_TYPE_NORMAL } from "@App/model/do/script";
2+
import { SCRIPT_STATUS_ENABLE, SCRIPT_STATUS_DISABLE, Script, SCRIPT_RUN_STATUS_COMPLETE, SCRIPT_STATUS_PREPARE, SCRIPT_TYPE_BACKGROUND, SCRIPT_TYPE_CRONTAB, SCRIPT_TYPE_NORMAL, SCRIPT_ORIGIN_LOCAL } from "@App/model/do/script";
33
import { ScriptModel } from "@App/model/script";
44
import { Page } from "@App/pkg/utils";
55
import { ScriptExec, ScriptStatusChange, ScriptStop, ScriptUninstall, ScriptReinstall, ScriptInstall, RequestInstallInfo, ScriptCheckUpdate, RequestConfirmInfo } from "../msg-center/event";
@@ -117,36 +117,6 @@ export class ScriptController {
117117
});
118118
}
119119

120-
public loadScriptByUrl(url: string): Promise<ScriptUrlInfo | undefined> {
121-
return new Promise(resolve => {
122-
axios.get(url, {
123-
headers: {
124-
'Cache-Control': 'no-cache'
125-
}
126-
}).then((response): ScriptUrlInfo | undefined => {
127-
if (response.status != 200) {
128-
return undefined;
129-
}
130-
let ok = parseMetadata(response.data);
131-
if (!ok) {
132-
return undefined;
133-
}
134-
let uuid = uuidv5(url, uuidv5.URL);
135-
let ret = {
136-
url: url,
137-
code: response.data,
138-
uuid: uuid
139-
};
140-
App.Cache.set("install:" + uuid, ret);
141-
return ret;
142-
}).then((val) => {
143-
resolve(val);
144-
}).catch((e) => {
145-
resolve(undefined);
146-
});
147-
});
148-
}
149-
150120
public prepareScriptByCode(code: string, url: string): Promise<[Script | undefined, Script | undefined]> {
151121
return new Promise(async resolve => {
152122
let metadata = parseMetadata(code);
@@ -192,7 +162,7 @@ export class ScriptController {
192162
checktime: 0,
193163
};
194164
let old = await this.scriptModel.findByUUID(script.uuid);
195-
if (!old) {
165+
if (!old && !script.origin.startsWith(SCRIPT_ORIGIN_LOCAL)) {
196166
old = await this.scriptModel.findByName(script.name);
197167
}
198168
if (old) {

src/apps/script/manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ export class ScriptManager {
569569
onclick: (info, tab) => {
570570
// 通信发送
571571
chrome.tabs.sendMessage(tab.id!, {
572-
"action": "exec", "uuid": script.uuid,
572+
"action": ScriptExec, "uuid": script.uuid,
573573
});
574574
},
575575
documentUrlPatterns: script.metadata['match'],

src/background.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ function sandboxLoad(event: MessageEvent) {
4343
}
4444
scripts.scriptList({ status: SCRIPT_STATUS_ENABLE }).then((items) => {
4545
items.forEach((value: Script) => {
46-
// 只开启后台脚本
47-
if (value.type != SCRIPT_TYPE_NORMAL) {
48-
scripts.enableScript(value);
49-
}
46+
scripts.enableScript(value);
5047
});
5148
});
5249
window.removeEventListener("message", sandboxLoad);

src/content.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ chrome.runtime.sendMessage("runScript", (event: any) => {
1919
browserMsg.send(ScriptValueChange, msg);
2020
})
2121
chrome.runtime.onMessage.addListener((event) => {
22-
console.log(event);
2322
switch (event.action) {
24-
case 'exec':
23+
case ScriptExec:
2524
browserMsg.send(ScriptExec, event.uuid);
2625
break;
2726
}

src/sandbox.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ async function execScript(
2626
): Promise<boolean> {
2727
return new Promise(async (resolve) => {
2828
//使用SandboxContext接管postRequest
29-
let key: any;
30-
if (type == "debug") {
31-
key = "script:debug:" + script.id;
32-
} else {
33-
key = "script:" + script.id;
34-
}
3529
script.delayruntime = 0;
3630
context.CAT_setRunError("", 0);
3731
script.lastruntime = new Date().getTime();
@@ -183,25 +177,38 @@ async function exec(script: ScriptCache, isdebug: boolean) {
183177
return top.postMessage({ action: "exec", data: "" }, "*");
184178
}
185179

186-
async function stop(script: Script, isdebug: boolean) {
180+
async function disable(script: Script) {
187181
let context = <SandboxContext>(
188-
await App.Cache.get("script:" + (isdebug ? "debug:" : "") + script.id)
182+
await App.Cache.get("script:" + script.id)
189183
);
190184
if (context) {
191185
context.destruct();
192186
}
193187
if (script.type != SCRIPT_TYPE_CRONTAB) {
194-
return top.postMessage({ action: "stop" }, "*");
188+
return top.postMessage({ action: "disable" }, "*");
195189
}
196190
let list = cronjobMap.get(script.id);
197191
if (!list) {
198-
return top.postMessage({ action: "stop" }, "*");
192+
return top.postMessage({ action: "disable" }, "*");
199193
}
200194
list.forEach((val) => {
201195
val.stop();
202196
});
203197
cronjobMap.delete(script.id);
198+
return top.postMessage({ action: "disable" }, "*");
199+
}
204200

201+
async function stop(script: Script, isdebug: boolean) {
202+
let context = <SandboxContext>(
203+
await App.Cache.get("script:" + (isdebug ? "debug:" : "") + script.id)
204+
);
205+
if (context) {
206+
if (script.type == SCRIPT_TYPE_CRONTAB) {
207+
context.CAT_runComplete();
208+
} else {
209+
context.destruct();
210+
}
211+
}
205212
return top.postMessage({ action: "stop" }, "*");
206213
}
207214

@@ -221,14 +228,18 @@ window.addEventListener("message", (event) => {
221228
start(event.data.data);
222229
break;
223230
}
224-
case "stop": {
225-
stop(event.data.data, event.data.isdebug);
231+
case "disable": {
232+
disable(event.data.data);
226233
break;
227234
}
228235
case "exec": {
229236
exec(event.data.data, event.data.isdebug);
230237
break;
231238
}
239+
case "stop": {
240+
stop(event.data.data, event.data.isdebug);
241+
break;
242+
}
232243
case ScriptValueChange: {
233244
AppEvent.trigger(ScriptValueChange, event.data.value);
234245
}

src/types/script.d.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/views/components/Tab/Tab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { Component, Prop, Provide, Vue, Watch } from "vue-property-decorator";
66
import CloseButton from "./CloseButton.vue";
77
import TabPane from "./TabPane";
88

9-
interface ITabItem {}
9+
interface ITabItem { }
1010

11-
const noop = () => {};
11+
const noop = () => { };
1212

1313
@Component({
1414
components: {

src/views/pages/Option/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,19 @@ export default class App extends Vue {
260260
render() {
261261
return (
262262
<VApp>
263+
<v-app-bar color="#1296DB" dense dark>
264+
<v-app-bar-nav-icon></v-app-bar-nav-icon>
265+
266+
<v-toolbar-title>ScriptCat</v-toolbar-title>
267+
<v-spacer></v-spacer>
268+
</v-app-bar>
263269
<div
264270
style={{
265271
height: "100%",
266272
display: "flex",
267273
flexDirection: "column",
268274
}}
269275
>
270-
<Carousel />
271-
<Snackbar />
272-
273276
<Tab ref="tabRef" onTabRemove={this.handleTabRemove}>
274277
{this.allTabs.map((tab) => {
275278
const { title, icon, content, tabKey, ...rest } = tab;

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@
300300
>
301301
<div v-for="(log, i) in logs" :key="i">
302302
{{ log.level }} {{ formatTime(log.createtime) }} -
303-
{{ log.message }}
303+
<div v-html="log.message" style="display: inline"></div>
304304
</div>
305305
<div class="d-flex justify-center" style="padding: 4px">
306306
<div>
@@ -501,8 +501,15 @@ export default class ScriptList extends Vue {
501501
this.showlog = true;
502502
this.logs = await this.scriptController.getScriptLog(
503503
item.id,
504-
new Page(1, 20, "asc")
504+
new Page(1, 20, "desc")
505505
);
506+
this.logs = this.logs.reverse();
507+
setTimeout(() => {
508+
let el = document.querySelector("#log-show");
509+
if (el) {
510+
el.scrollTop = el.scrollHeight;
511+
}
512+
}, 1000);
506513
}
507514
508515
async clearLog(item: Script) {

src/views/pages/Popup/ScriptList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
</template>
7777

7878
<template v-else>
79-
<v-list-item @click="scriptController.exec(script.id, false)">
79+
<v-list-item @click="scriptController.stop(script.id, false)">
8080
<v-list-item-icon>
8181
<v-icon>mdi-stop</v-icon>
8282
</v-list-item-icon>

0 commit comments

Comments
 (0)