From ede65398032a4cd7b1191133b0977072c2e9e90a Mon Sep 17 00:00:00 2001 From: Cashew Date: Tue, 26 Dec 2023 14:05:36 +0700 Subject: [PATCH 1/5] remove IIFEs --- ext/js/accessibility/google-docs.js | 10 ++++++++-- ext/js/app/content-script-wrapper.js | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ext/js/accessibility/google-docs.js b/ext/js/accessibility/google-docs.js index 4bc398ff91..2551b5d065 100644 --- a/ext/js/accessibility/google-docs.js +++ b/ext/js/accessibility/google-docs.js @@ -16,7 +16,8 @@ * along with this program. If not, see . */ -(async () => { +/** */ +async function main() { // Reentrant check // @ts-expect-error - Checking a property to the global object if (self.googleDocsAccessibilitySetup) { return; } @@ -71,4 +72,9 @@ script.textContent = `(${inject.toString()})();`; parent.appendChild(script); parent.removeChild(script); -})(); +} + +await main(); + +// Empty export to enable top level await +export {}; diff --git a/ext/js/app/content-script-wrapper.js b/ext/js/app/content-script-wrapper.js index 795d3d8b9b..a2fd8cb9b2 100644 --- a/ext/js/app/content-script-wrapper.js +++ b/ext/js/app/content-script-wrapper.js @@ -16,8 +16,14 @@ * along with this program. If not, see . */ -(async () => { +/** */ +async function main() { const src = chrome.runtime.getURL('js/app/content-script-main.js'); // eslint-disable-next-line no-unsanitized/method await import(src); -})(); +} + +await main(); + +// Empty export to enable top-level await +export {}; From 0bdccdd2edd9ced4daf044bc71ee272a2c5cd7bd Mon Sep 17 00:00:00 2001 From: Cashew Date: Tue, 26 Dec 2023 14:10:15 +0700 Subject: [PATCH 2/5] Move IIFE into function --- ext/js/yomitan.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ext/js/yomitan.js b/ext/js/yomitan.js index 2fbe99cc33..7505c0caf6 100644 --- a/ext/js/yomitan.js +++ b/ext/js/yomitan.js @@ -21,8 +21,10 @@ import {CrossFrameAPI} from './comm/cross-frame-api.js'; import {EventDispatcher, deferPromise, invokeMessageHandler, log} from './core.js'; import {ExtensionError} from './core/extension-error.js'; -// Set up chrome alias if it's not available (Edge Legacy) -if ((() => { +/** + * @returns {boolean} + */ +function checkChromeNotAvailable() { let hasChrome = false; let hasBrowser = false; try { @@ -36,7 +38,10 @@ if ((() => { // NOP } return (hasBrowser && !hasChrome); -})()) { +} + +// Set up chrome alias if it's not available (Edge Legacy) +if (checkChromeNotAvailable()) { // @ts-expect-error - objects should have roughly the same interface // eslint-disable-next-line no-global-assign chrome = browser; From c70c8a2b13ef748395b2bad008f3443fe20f2d34 Mon Sep 17 00:00:00 2001 From: Cashew Date: Tue, 26 Dec 2023 22:20:12 +0700 Subject: [PATCH 3/5] revert google-docs.js to IIFE --- ext/js/accessibility/google-docs.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ext/js/accessibility/google-docs.js b/ext/js/accessibility/google-docs.js index 2551b5d065..4bc398ff91 100644 --- a/ext/js/accessibility/google-docs.js +++ b/ext/js/accessibility/google-docs.js @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -/** */ -async function main() { +(async () => { // Reentrant check // @ts-expect-error - Checking a property to the global object if (self.googleDocsAccessibilitySetup) { return; } @@ -72,9 +71,4 @@ async function main() { script.textContent = `(${inject.toString()})();`; parent.appendChild(script); parent.removeChild(script); -} - -await main(); - -// Empty export to enable top level await -export {}; +})(); From 449ddadbd1190134d9da00419683901c51893920 Mon Sep 17 00:00:00 2001 From: Cashew Date: Tue, 26 Dec 2023 22:45:41 +0700 Subject: [PATCH 4/5] add entry point jsdoc --- ext/js/app/content-script-wrapper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/js/app/content-script-wrapper.js b/ext/js/app/content-script-wrapper.js index a2fd8cb9b2..48e6956079 100644 --- a/ext/js/app/content-script-wrapper.js +++ b/ext/js/app/content-script-wrapper.js @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -/** */ +/** Entry point. */ async function main() { const src = chrome.runtime.getURL('js/app/content-script-main.js'); // eslint-disable-next-line no-unsanitized/method From 6653391c3dd4347457ad46833fa9a1241f60133b Mon Sep 17 00:00:00 2001 From: Cashew Date: Wed, 27 Dec 2023 17:36:15 +0700 Subject: [PATCH 5/5] revert content-script-wrapper --- ext/js/app/content-script-wrapper.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ext/js/app/content-script-wrapper.js b/ext/js/app/content-script-wrapper.js index 48e6956079..795d3d8b9b 100644 --- a/ext/js/app/content-script-wrapper.js +++ b/ext/js/app/content-script-wrapper.js @@ -16,14 +16,8 @@ * along with this program. If not, see . */ -/** Entry point. */ -async function main() { +(async () => { const src = chrome.runtime.getURL('js/app/content-script-main.js'); // eslint-disable-next-line no-unsanitized/method await import(src); -} - -await main(); - -// Empty export to enable top-level await -export {}; +})();