Skip to content

Commit b477640

Browse files
committed
✨ 兼容暴力猴导出脚本包
1 parent 429dd55 commit b477640

File tree

6 files changed

+147
-59
lines changed

6 files changed

+147
-59
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.8.0",
4+
"version": "0.8.1",
55
"description": "脚本猫,一个用户脚本的框架,可编写脚本每天帮你自动处理事务.",
66
"background": {
77
"page": "background.html"

src/apps/script/controller.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v5 as uuidv5 } from 'uuid';
1+
import { v4 as uuidv4 } from 'uuid';
22
import {
33
SCRIPT_STATUS_ENABLE,
44
SCRIPT_STATUS_DISABLE,
@@ -74,12 +74,15 @@ export class ScriptController {
7474
// eslint-disable-next-line @typescript-eslint/no-misused-promises
7575
return new Promise(async resolve => {
7676
if (script.id) {
77-
resolve(script.id);
78-
MsgCenter.sendMessage(ScriptReinstall, script);
77+
MsgCenter.sendMessage(ScriptReinstall, script, () => {
78+
resolve(script.id);
79+
});
7980
} else {
8081
await this.scriptModel.save(script);
8182
resolve(script.id);
82-
MsgCenter.sendMessage(ScriptInstall, script);
83+
MsgCenter.sendMessage(ScriptInstall, script, () => {
84+
resolve(script.id);
85+
});
8386
}
8487
});
8588
}
@@ -280,7 +283,7 @@ export class ScriptController {
280283
}
281284
const script: Script = {
282285
id: 0,
283-
uuid: uuid || uuidv5(url, uuidv5.URL),
286+
uuid: uuid || uuidv4(),
284287
name: metadata['name'][0],
285288
code: code,
286289
author: metadata['author'] && metadata['author'][0],

src/pkg/utils/backup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export class ZipBackup extends JsonBackup implements Backup {
408408
await this.getAndSet(scriptMap, name, async (val: ImportScript) => {
409409
return new Promise(resolve => {
410410
const handler = async () => {
411-
const file = zip.file(key);
411+
const file = zip.files[key];
412412
if (file) {
413413
val.source = await file.async('string');
414414
if (val.enabled === undefined) {

src/pkg/utils/utils.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,14 @@ export function base64ToBlob(dataURI: string) {
282282
}
283283

284284
export function base64ToStr(base64: string): string {
285-
return decodeURIComponent(atob(base64).split('').map(function (c) {
286-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
287-
}).join(''));
285+
try {
286+
return decodeURIComponent(atob(base64).split('').map(function (c) {
287+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
288+
}).join(''));
289+
} catch (e) {
290+
console.log(e);
291+
}
292+
return '';
288293
}
289294

290295
export function strToBase64(str: string): string {

src/views/pages/Import/index.vue

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<div class="control d-flex justify-start" style="margin: 10px 0">
1111
<v-btn
1212
@click="importFile"
13-
:loading="importLoading"
14-
:disabled="importLoading"
13+
:loading="importLoading || loading"
14+
:disabled="importLoading || loading"
1515
depressed
1616
small
1717
color="primary"
@@ -46,8 +46,29 @@
4646
<div class="text-subtitle-2">
4747
脚本导入进度: {{ scriptNum }}/{{ selectedScript.length }}
4848
</div>
49-
<div v-if="loading" class="text-subtitle-2">
50-
脚本加载进度: {{ cur }}/{{ total }}
49+
<div
50+
v-if="loading"
51+
class="text-subtitle-2"
52+
style="margin-left: 10px"
53+
>
54+
加载进度: {{ cur }}/{{ total }}
55+
</div>
56+
</div>
57+
<div
58+
class="control d-flex justify-start align-center"
59+
style="margin: 10px 0"
60+
>
61+
<div class="subtitle-2">请选择你要导入的订阅:</div>
62+
<v-checkbox
63+
v-model="isSelectAllScript"
64+
label="全选"
65+
color="secondary"
66+
@change="selectAllSubscribe"
67+
style="margin: 0 10px; padding: 0"
68+
hide-details
69+
></v-checkbox>
70+
<div class="text-subtitle-2">
71+
订阅导入进度: {{ subscribeNum }}/{{ selectedSubscribe.length }}
5172
</div>
5273
</div>
5374
<v-list two-line>
@@ -62,9 +83,9 @@
6283
<v-list-item-title
6384
v-html="
6485
item.name +
65-
(item.background
66-
? '<img src=\'/assets/logo.png\' width=\'16px\'/>'
67-
: '')
86+
(item.background
87+
? '<img src=\'/assets/logo.png\' width=\'16px\'/>'
88+
: '')
6889
"
6990
>
7091
</v-list-item-title>
@@ -116,23 +137,6 @@
116137
class="script-list"
117138
style="border-top: 1px dashed"
118139
>
119-
<div
120-
class="control d-flex justify-start align-center"
121-
style="margin: 10px 0"
122-
>
123-
<div class="subtitle-2">请选择你要导入的订阅:</div>
124-
<v-checkbox
125-
v-model="isSelectAllScript"
126-
label="全选"
127-
color="secondary"
128-
@change="selectAllSubscribe"
129-
style="margin: 0 10px; padding: 0"
130-
hide-details
131-
></v-checkbox>
132-
<div class="text-subtitle-2">
133-
订阅导入进度: {{ subscribeNum }}/{{ selectedSubscribe.length }}
134-
</div>
135-
</div>
136140
<v-list two-line>
137141
<v-list-item-group
138142
v-model="selectedScript"
@@ -297,11 +301,11 @@ export default class Index extends Vue {
297301
};
298302
let [newScript, oldScript] = await this.scriptCtrl.prepareScriptByCode(
299303
importScript.source,
300-
script.download_url
304+
script.download_url,
301305
);
302306
if (typeof oldScript === 'string' || !newScript) {
303307
script.error = <string>oldScript || 'error';
304-
this.scripts.push(script);
308+
this.selectedScript.push(this.scripts.push(script) - 1);
305309
continue;
306310
}
307311
if (oldScript) {
@@ -314,7 +318,7 @@ export default class Index extends Vue {
314318
script.hasOld = oldScript ? true : false;
315319
script.script = newScript;
316320
script.background = newScript?.type !== 1;
317-
this.scripts.push(script);
321+
this.selectedScript.push(this.scripts.push(script) - 1);
318322
}
319323
let importSubscribe;
320324
while ((importSubscribe = backup.ReadSubscribe())) {
@@ -330,7 +334,7 @@ export default class Index extends Vue {
330334
);
331335
if (typeof oldSub === 'string' || !newSub) {
332336
subscribe.error = <string>oldSub || 'error';
333-
this.subscribes.push(subscribe);
337+
this.selectedSubscribe.push(this.subscribes.push(subscribe) - 1);
334338
continue;
335339
}
336340
if (oldSub) {
@@ -339,7 +343,7 @@ export default class Index extends Vue {
339343
newSub.scripts = importSubscribe.scripts;
340344
subscribe.subscribe = newSub;
341345
subscribe.hasOld = oldSub ? true : false;
342-
this.subscribes.push(subscribe);
346+
this.selectedSubscribe.push(this.subscribes.push(subscribe) - 1);
343347
}
344348
this.selectAll();
345349
this.selectAllSubscribe();
@@ -411,6 +415,7 @@ export default class Index extends Vue {
411415
let handle = async () => {
412416
let script = scriptInfo.script;
413417
if (!script) {
418+
console.log('error',scriptInfo);
414419
return;
415420
}
416421
script.status = scriptInfo.enabled
@@ -451,6 +456,9 @@ export default class Index extends Vue {
451456
};
452457
void importValue();
453458
}
459+
} else {
460+
this.scriptNum += 1;
461+
wait.done();
454462
}
455463
};
456464
try {

0 commit comments

Comments
 (0)