From 3b278d0a7972e5727e4c4b1da6b12ec89462acf3 Mon Sep 17 00:00:00 2001 From: fofolee Date: Fri, 29 Apr 2022 20:58:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E5=85=88=E4=B8=8B=E8=BD=BD=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CommandRunResult.vue | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index afd0c26..33ed484 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -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();