Skip to content

Commit

Permalink
✨ 兼容暴力猴导出脚本包
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Jan 14, 2022
1 parent 429dd55 commit b477640
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 59 deletions.
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.8.0",
"version": "0.8.1",
"description": "脚本猫,一个用户脚本的框架,可编写脚本每天帮你自动处理事务.",
"background": {
"page": "background.html"
Expand Down
13 changes: 8 additions & 5 deletions src/apps/script/controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { v5 as uuidv5 } from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import {
SCRIPT_STATUS_ENABLE,
SCRIPT_STATUS_DISABLE,
Expand Down Expand Up @@ -74,12 +74,15 @@ export class ScriptController {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
return new Promise(async resolve => {
if (script.id) {
resolve(script.id);
MsgCenter.sendMessage(ScriptReinstall, script);
MsgCenter.sendMessage(ScriptReinstall, script, () => {
resolve(script.id);
});
} else {
await this.scriptModel.save(script);
resolve(script.id);
MsgCenter.sendMessage(ScriptInstall, script);
MsgCenter.sendMessage(ScriptInstall, script, () => {
resolve(script.id);
});
}
});
}
Expand Down Expand Up @@ -280,7 +283,7 @@ export class ScriptController {
}
const script: Script = {
id: 0,
uuid: uuid || uuidv5(url, uuidv5.URL),
uuid: uuid || uuidv4(),
name: metadata['name'][0],
code: code,
author: metadata['author'] && metadata['author'][0],
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/utils/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export class ZipBackup extends JsonBackup implements Backup {
await this.getAndSet(scriptMap, name, async (val: ImportScript) => {
return new Promise(resolve => {
const handler = async () => {
const file = zip.file(key);
const file = zip.files[key];
if (file) {
val.source = await file.async('string');
if (val.enabled === undefined) {
Expand Down
11 changes: 8 additions & 3 deletions src/pkg/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,14 @@ export function base64ToBlob(dataURI: string) {
}

export function base64ToStr(base64: string): string {
return decodeURIComponent(atob(base64).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
try {
return decodeURIComponent(atob(base64).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
} catch (e) {
console.log(e);
}
return '';
}

export function strToBase64(str: string): string {
Expand Down
66 changes: 37 additions & 29 deletions src/views/pages/Import/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<div class="control d-flex justify-start" style="margin: 10px 0">
<v-btn
@click="importFile"
:loading="importLoading"
:disabled="importLoading"
:loading="importLoading || loading"
:disabled="importLoading || loading"
depressed
small
color="primary"
Expand Down Expand Up @@ -46,8 +46,29 @@
<div class="text-subtitle-2">
脚本导入进度: {{ scriptNum }}/{{ selectedScript.length }}
</div>
<div v-if="loading" class="text-subtitle-2">
脚本加载进度: {{ cur }}/{{ total }}
<div
v-if="loading"
class="text-subtitle-2"
style="margin-left: 10px"
>
加载进度: {{ cur }}/{{ total }}
</div>
</div>
<div
class="control d-flex justify-start align-center"
style="margin: 10px 0"
>
<div class="subtitle-2">请选择你要导入的订阅:</div>
<v-checkbox
v-model="isSelectAllScript"
label="全选"
color="secondary"
@change="selectAllSubscribe"
style="margin: 0 10px; padding: 0"
hide-details
></v-checkbox>
<div class="text-subtitle-2">
订阅导入进度: {{ subscribeNum }}/{{ selectedSubscribe.length }}
</div>
</div>
<v-list two-line>
Expand All @@ -62,9 +83,9 @@
<v-list-item-title
v-html="
item.name +
(item.background
? '<img src=\'/assets/logo.png\' width=\'16px\'/>'
: '')
(item.background
? '<img src=\'/assets/logo.png\' width=\'16px\'/>'
: '')
"
>
</v-list-item-title>
Expand Down Expand Up @@ -116,23 +137,6 @@
class="script-list"
style="border-top: 1px dashed"
>
<div
class="control d-flex justify-start align-center"
style="margin: 10px 0"
>
<div class="subtitle-2">请选择你要导入的订阅:</div>
<v-checkbox
v-model="isSelectAllScript"
label="全选"
color="secondary"
@change="selectAllSubscribe"
style="margin: 0 10px; padding: 0"
hide-details
></v-checkbox>
<div class="text-subtitle-2">
订阅导入进度: {{ subscribeNum }}/{{ selectedSubscribe.length }}
</div>
</div>
<v-list two-line>
<v-list-item-group
v-model="selectedScript"
Expand Down Expand Up @@ -297,11 +301,11 @@ export default class Index extends Vue {
};
let [newScript, oldScript] = await this.scriptCtrl.prepareScriptByCode(
importScript.source,
script.download_url
script.download_url,
);
if (typeof oldScript === 'string' || !newScript) {
script.error = <string>oldScript || 'error';
this.scripts.push(script);
this.selectedScript.push(this.scripts.push(script) - 1);
continue;
}
if (oldScript) {
Expand All @@ -314,7 +318,7 @@ export default class Index extends Vue {
script.hasOld = oldScript ? true : false;
script.script = newScript;
script.background = newScript?.type !== 1;
this.scripts.push(script);
this.selectedScript.push(this.scripts.push(script) - 1);
}
let importSubscribe;
while ((importSubscribe = backup.ReadSubscribe())) {
Expand All @@ -330,7 +334,7 @@ export default class Index extends Vue {
);
if (typeof oldSub === 'string' || !newSub) {
subscribe.error = <string>oldSub || 'error';
this.subscribes.push(subscribe);
this.selectedSubscribe.push(this.subscribes.push(subscribe) - 1);
continue;
}
if (oldSub) {
Expand All @@ -339,7 +343,7 @@ export default class Index extends Vue {
newSub.scripts = importSubscribe.scripts;
subscribe.subscribe = newSub;
subscribe.hasOld = oldSub ? true : false;
this.subscribes.push(subscribe);
this.selectedSubscribe.push(this.subscribes.push(subscribe) - 1);
}
this.selectAll();
this.selectAllSubscribe();
Expand Down Expand Up @@ -411,6 +415,7 @@ export default class Index extends Vue {
let handle = async () => {
let script = scriptInfo.script;
if (!script) {
console.log('error',scriptInfo);
return;
}
script.status = scriptInfo.enabled
Expand Down Expand Up @@ -451,6 +456,9 @@ export default class Index extends Vue {
};
void importValue();
}
} else {
this.scriptNum += 1;
wait.done();
}
};
try {
Expand Down
Loading

0 comments on commit b477640

Please sign in to comment.