(scriptMetadata)
| 587 | } |
| 588 | |
| 589 | async function runScript(scriptMetadata) { |
| 590 | if (checkIsPreview(scriptMetadata)) return; |
| 591 | |
| 592 | let tab = await getCurrentTab(); |
| 593 | let willRun = checkBlackWhiteList(scriptMetadata, tab.url); |
| 594 | |
| 595 | // ⚡ LAZY LOAD: Load full script on-demand |
| 596 | const script = await loadFullScript(scriptMetadata.id); |
| 597 | |
| 598 | if (willRun) { |
| 599 | recentScriptsSaver.add(scriptMetadata); |
| 600 | trackEvent(scriptMetadata.id); |
| 601 | |
| 602 | try { |
| 603 | if (isFunction(script.popupScript?.onClick)) { |
| 604 | await script.popupScript.onClick(); |
| 605 | } |
| 606 | } catch (e) { |
| 607 | showError(e); |
| 608 | } |
| 609 | |
| 610 | let isRunInTab = false; |
| 611 | [ |
| 612 | ["MAIN", "pageScript", "onClick", false], |
| 613 | ["MAIN", "pageScript", "onClick_", true], |
| 614 | ["ISOLATED", "contentScript", "onClick", false], |
| 615 | ["ISOLATED", "contentScript", "onClick_", true], |
| 616 | ].forEach(([world, context, func, allFrames]) => { |
| 617 | if (isFunction(script?.[context]?.[func])) { |
| 618 | isRunInTab = true; |
| 619 | runScriptInTabWithEventChain({ |
| 620 | target: { |
| 621 | tabId: tab.id, |
| 622 | ...(allFrames ? { allFrames: true } : {}), |
| 623 | }, |
| 624 | scriptIds: [script.id], |
| 625 | eventChain: context + "." + func, |
| 626 | world: world, |
| 627 | }).catch(showError); |
| 628 | } |
| 629 | }); |
| 630 | |
| 631 | if (isInNewTab && isRunInTab) { |
| 632 | // focus to targeTab |
| 633 | await chrome.windows.update(tab.windowId, { |
| 634 | focused: true, |
| 635 | }); |
| 636 | } |
| 637 | } else { |
| 638 | let text = ""; |
| 639 | [ |
| 640 | [script?.whiteList, t({ vi: "Chỉ chạy tại", en: "Only run at" })], |
| 641 | [script?.blackList, t({ vi: "Không chạy tại", en: "Not run at" })], |
| 642 | ].forEach(([list, title]) => { |
| 643 | if (list?.length) { |
| 644 | text += `${title}:<br/> |
| 645 | <ul> |
| 646 | ${list.map((_) => "<li><i>" + _ + "</i></li>").join("")} |
no test coverage detected