Skip to content

Commit 16d8776

Browse files
committed
optimize - run script with event chain -> load full script content
1 parent dace73f commit 16d8776

File tree

5 files changed

+774
-731
lines changed

5 files changed

+774
-731
lines changed

popup/index.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {
33
getCurrentTab,
44
isFunction,
55
removeAccents,
6-
runScriptInCurrentTab,
76
setActiveScript,
87
trackEvent,
98
debounce,
109
Storage,
1110
checkWillRun,
11+
runScriptInTabWithEventChain,
1212
} from "../scripts/helpers/utils.js";
1313
import { checkForUpdate } from "./helpers/checkForUpdate.js";
1414
import {
@@ -270,10 +270,12 @@ function createScriptButton(script, isFavorite = false) {
270270
if (script.infoLink) {
271271
const infoBtn = document.createElement("i");
272272
infoBtn.className = "fa-regular fa-circle-question";
273-
infoBtn.title = t({
274-
en: "View info/demo",
275-
vi: "Xem giới thiệu/demo",
276-
});
273+
if (typeof script.infoLink === "string") {
274+
infoBtn.title = t({
275+
en: "View info/demo",
276+
vi: "Xem giới thiệu/demo",
277+
});
278+
}
277279
infoBtn.onclick = (e) => {
278280
e.stopPropagation();
279281
e.preventDefault();
@@ -391,14 +393,24 @@ async function runScript(script) {
391393
await script.popupScript.onClick();
392394

393395
if (isFunction(script.pageScript?.onClick))
394-
await runScriptInCurrentTab(script.pageScript?.onClick, null, "MAIN");
396+
await runScriptInTabWithEventChain({
397+
target: {
398+
tabId: tab.id,
399+
},
400+
scriptIds: [script.id],
401+
eventChain: "pageScript.onClick",
402+
world: "MAIN",
403+
});
395404

396405
if (isFunction(script.contentScript?.onClick))
397-
await runScriptInCurrentTab(
398-
script.contentScript?.onClick,
399-
null,
400-
"ISOLATED"
401-
);
406+
await runScriptInTabWithEventChain({
407+
target: {
408+
tabId: tab.id,
409+
},
410+
scriptIds: [script.id],
411+
eventChain: "contentScript.onClick",
412+
world: "ISOLATED",
413+
});
402414
} catch (e) {
403415
alert("ERROR: run script " + e);
404416
}

0 commit comments

Comments
 (0)