预先下载远程脚本

This commit is contained in:
fofolee 2022-04-29 20:58:38 +08:00
parent 363a39a36f
commit 3b278d0a79

View File

@ -69,6 +69,8 @@ export default {
frameInitHeight: 0,
childProcess: null,
timeStamp: null,
urlReg:
/^((ht|f)tps?):\/\/([\w\-]+(\.[\w\-]+)*\/)*[\w\-]+(\.[\w\-]+)*\/?(\?([\w\-\.,@?^=%&:\/~\+#]*)+)?/,
};
},
props: {
@ -102,7 +104,10 @@ export default {
},
async fire(currentCommand) {
currentCommand.cmd = this.assignSpecialVars(currentCommand.cmd);
this.enableHtml = currentCommand.output === "html";
if (currentCommand.output === "html") {
this.enableHtml = true;
currentCommand.cmd = await this.cacheScript(currentCommand.cmd);
}
let { hideWindow, outPlugin, action } =
outputTypes[currentCommand.output];
//
@ -123,7 +128,7 @@ export default {
{ enterData: this.$root.enterData }
);
} else if (currentCommand.program === "html") {
this.showRunResult(currentCommand.cmd, true, action);
this.showRunResult(currentCommand.cmd, true);
} else {
let option =
currentCommand.program === "custom"
@ -274,6 +279,19 @@ export default {
frameLoad(initHeight) {
this.frameInitHeight = initHeight;
},
//
async cacheScript(cmd) {
let html = quickcommand.htmlParse(cmd);
let scriptDoms = html.querySelectorAll("script");
for (let i = 0; i < scriptDoms.length; i++) {
let src = scriptDoms[i].src;
if (!this.urlReg.test(src)) continue;
let dest = window.getQuickcommandTempFile("js", "remoteScript_" + i);
await quickcommand.downloadFile(src, dest);
scriptDoms[i].src = "file://" + dest;
}
return html.documentElement.innerHTML;
},
},
unmounted() {
this.stopRun();