From 6c93d1984fbfe4fc21df4d0675fb4a82f2991ea3 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 19 Apr 2020 14:21:43 -0400 Subject: [PATCH 1/8] Change frontend-initialize.js to content-script-main.js --- ext/bg/js/search-frontend.js | 2 +- ext/fg/js/{frontend-initialize.js => content-script-main.js} | 4 ++-- ext/fg/js/popup-nested.js | 2 +- ext/manifest.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename ext/fg/js/{frontend-initialize.js => content-script-main.js} (98%) diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js index e534e771..bda46a98 100644 --- a/ext/bg/js/search-frontend.js +++ b/ext/bg/js/search-frontend.js @@ -27,7 +27,7 @@ function injectSearchFrontend() { '/fg/js/popup.js', '/fg/js/popup-proxy-host.js', '/fg/js/frontend.js', - '/fg/js/frontend-initialize.js' + '/fg/js/content-script-main.js' ]; for (const src of scriptSrcs) { const node = document.querySelector(`script[src='${src}']`); diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/content-script-main.js similarity index 98% rename from ext/fg/js/frontend-initialize.js rename to ext/fg/js/content-script-main.js index 2df59e20..974320cc 100644 --- a/ext/fg/js/frontend-initialize.js +++ b/ext/fg/js/content-script-main.js @@ -61,7 +61,7 @@ async function createPopupProxy(depth, id, parentFrameId, url) { return popup; } -async function main() { +async function contentScriptMain() { await yomichan.prepare(); const data = window.frontendInitializationData || {}; @@ -130,4 +130,4 @@ async function main() { await applyOptions(); } -main(); +contentScriptMain(); diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js index c140f9c8..27482931 100644 --- a/ext/fg/js/popup-nested.js +++ b/ext/fg/js/popup-nested.js @@ -26,7 +26,7 @@ function injectPopupNested() { '/fg/js/popup.js', '/fg/js/popup-proxy.js', '/fg/js/frontend.js', - '/fg/js/frontend-initialize.js' + '/fg/js/content-script-main.js' ]; for (const src of scriptSrcs) { const script = document.createElement('script'); diff --git a/ext/manifest.json b/ext/manifest.json index d383dab0..4f35b03c 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -31,7 +31,7 @@ "fg/js/popup-proxy.js", "fg/js/popup-proxy-host.js", "fg/js/frontend.js", - "fg/js/frontend-initialize.js" + "fg/js/content-script-main.js" ], "match_about_blank": true, "all_frames": true From 3c8eb9eee009ebe265fbae3f7d7ac0d74fcbdd94 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 19 Apr 2020 14:26:44 -0400 Subject: [PATCH 2/8] Create background-main.js --- ext/bg/background.html | 3 ++- ext/bg/js/backend.js | 3 --- ext/bg/js/background-main.js | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 ext/bg/js/background-main.js diff --git a/ext/bg/background.html b/ext/bg/background.html index f1006f8d..3446d9ce 100644 --- a/ext/bg/background.html +++ b/ext/bg/background.html @@ -24,6 +24,7 @@ + @@ -45,6 +46,6 @@ - + diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 8a19203f..d23fda10 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -1054,6 +1054,3 @@ class Backend { } } } - -window.yomichanBackend = new Backend(); -window.yomichanBackend.prepare(); diff --git a/ext/bg/js/background-main.js b/ext/bg/js/background-main.js new file mode 100644 index 00000000..c000c38d --- /dev/null +++ b/ext/bg/js/background-main.js @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2020 Yomichan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* global + * Backend + */ + +async function main() { + window.yomichanBackend = new Backend(); + await window.yomichanBackend.prepare(); +} + +main(); From 3edaf319da31ef943ada9661eb67019a75e6b7ac Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 19 Apr 2020 14:27:15 -0400 Subject: [PATCH 3/8] Rename context.js to context-main.js --- ext/bg/context.html | 2 +- ext/bg/js/{context.js => context-main.js} | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) rename ext/bg/js/{context.js => context-main.js} (95%) diff --git a/ext/bg/context.html b/ext/bg/context.html index 0e50ed7c..394869b1 100644 --- a/ext/bg/context.html +++ b/ext/bg/context.html @@ -185,6 +185,6 @@ - + diff --git a/ext/bg/js/context.js b/ext/bg/js/context-main.js similarity index 95% rename from ext/bg/js/context.js rename to ext/bg/js/context-main.js index e3d4ad4a..67bb4e18 100644 --- a/ext/bg/js/context.js +++ b/ext/bg/js/context-main.js @@ -51,7 +51,7 @@ function setupButtonEvents(selector, command, url) { } } -window.addEventListener('DOMContentLoaded', async () => { +async function mainInner() { await yomichan.prepare(); showExtensionInfo(); @@ -86,4 +86,10 @@ window.addEventListener('DOMContentLoaded', async () => { } }, 10); }); -}); +} + +async function main() { + window.addEventListener('DOMContentLoaded', mainInner, false); +} + +main(); From 4d3d5d9ccb1c8ffbac0be0dc348790b34f68a564 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 19 Apr 2020 14:28:07 -0400 Subject: [PATCH 4/8] Rename search-frontend.js to search-main.js Also move DisplaySearch creation into the main() function. --- ext/bg/js/{search-frontend.js => search-main.js} | 4 ++++ ext/bg/js/search.js | 8 -------- ext/bg/search.html | 3 ++- 3 files changed, 6 insertions(+), 9 deletions(-) rename ext/bg/js/{search-frontend.js => search-main.js} (95%) diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-main.js similarity index 95% rename from ext/bg/js/search-frontend.js rename to ext/bg/js/search-main.js index bda46a98..91c39222 100644 --- a/ext/bg/js/search-frontend.js +++ b/ext/bg/js/search-main.js @@ -16,6 +16,7 @@ */ /* global + * DisplaySearch * apiOptionsGet */ @@ -54,6 +55,9 @@ function injectSearchFrontend() { async function main() { await yomichan.prepare(); + const displaySearch = new DisplaySearch(); + await displaySearch.prepare(); + let optionsApplied = false; const applyOptions = async () => { diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 871c576b..266cccc8 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -72,12 +72,6 @@ class DisplaySearch extends Display { ]); } - static create() { - const instance = new DisplaySearch(); - instance.prepare(); - return instance; - } - async prepare() { try { await super.prepare(); @@ -376,5 +370,3 @@ class DisplaySearch extends Display { } } } - -DisplaySearch.instance = DisplaySearch.create(); diff --git a/ext/bg/search.html b/ext/bg/search.html index fe88e264..9a824776 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -94,6 +94,7 @@ - + + From 7c578f75827ae0a72b13f04b8342fd8129f702d4 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 19 Apr 2020 14:28:29 -0400 Subject: [PATCH 5/8] Create popup-preview-frame-main.js --- .../js/settings/popup-preview-frame-main.js | 27 +++++++++++++++++++ ext/bg/js/settings/popup-preview-frame.js | 11 -------- ext/bg/settings-popup-preview.html | 2 ++ 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 ext/bg/js/settings/popup-preview-frame-main.js diff --git a/ext/bg/js/settings/popup-preview-frame-main.js b/ext/bg/js/settings/popup-preview-frame-main.js new file mode 100644 index 00000000..e6e4727f --- /dev/null +++ b/ext/bg/js/settings/popup-preview-frame-main.js @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2019-2020 Yomichan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* global + * SettingsPopupPreview + */ + +async function main() { + const instance = new SettingsPopupPreview(); + await instance.prepare(); +} + +main(); diff --git a/ext/bg/js/settings/popup-preview-frame.js b/ext/bg/js/settings/popup-preview-frame.js index fba114e2..420a7c5a 100644 --- a/ext/bg/js/settings/popup-preview-frame.js +++ b/ext/bg/js/settings/popup-preview-frame.js @@ -41,12 +41,6 @@ class SettingsPopupPreview { ]); } - static create() { - const instance = new SettingsPopupPreview(); - instance.prepare(); - return instance; - } - async prepare() { // Setup events window.addEventListener('message', this.onMessage.bind(this), false); @@ -178,8 +172,3 @@ class SettingsPopupPreview { this.setInfoVisible(!this.popupShown); } } - -SettingsPopupPreview.instance = SettingsPopupPreview.create(); - - - diff --git a/ext/bg/settings-popup-preview.html b/ext/bg/settings-popup-preview.html index f33ecedf..66475b7c 100644 --- a/ext/bg/settings-popup-preview.html +++ b/ext/bg/settings-popup-preview.html @@ -129,5 +129,7 @@ + + From 9ca906ef900dacfd10a548757d8a2b842a549088 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 19 Apr 2020 14:29:29 -0400 Subject: [PATCH 6/8] Create float-main.js --- ext/fg/float.html | 3 ++- ext/fg/js/float-main.js | 26 ++++++++++++++++++++++++++ ext/fg/js/float.js | 2 -- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 ext/fg/js/float-main.js diff --git a/ext/fg/float.html b/ext/fg/float.html index c8ea9b67..85c806fd 100644 --- a/ext/fg/float.html +++ b/ext/fg/float.html @@ -56,7 +56,8 @@ - + + diff --git a/ext/fg/js/float-main.js b/ext/fg/js/float-main.js new file mode 100644 index 00000000..b752cdee --- /dev/null +++ b/ext/fg/js/float-main.js @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 Yomichan Authors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* global + * DisplayFloat + */ + +async function main() { + new DisplayFloat(); +} + +main(); diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index 5c2c50c2..18d15a72 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -189,5 +189,3 @@ class DisplayFloat extends Display { } } } - -DisplayFloat.instance = new DisplayFloat(); From d106c638ed69b2c72895c1040b0e7bea2e31cdb7 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 21 Apr 2020 18:38:55 -0400 Subject: [PATCH 7/8] Move popup-nested content into float-main --- ext/fg/float.html | 1 - ext/fg/js/float-main.js | 48 ++++++++++++++++++++++++++++ ext/fg/js/popup-nested.js | 67 --------------------------------------- 3 files changed, 48 insertions(+), 68 deletions(-) delete mode 100644 ext/fg/js/popup-nested.js diff --git a/ext/fg/float.html b/ext/fg/float.html index 85c806fd..07c3c9e6 100644 --- a/ext/fg/float.html +++ b/ext/fg/float.html @@ -56,7 +56,6 @@ - diff --git a/ext/fg/js/float-main.js b/ext/fg/js/float-main.js index b752cdee..072c86e0 100644 --- a/ext/fg/js/float-main.js +++ b/ext/fg/js/float-main.js @@ -17,8 +17,56 @@ /* global * DisplayFloat + * apiOptionsGet */ +function injectPopupNested() { + const scriptSrcs = [ + '/mixed/js/text-scanner.js', + '/fg/js/frontend-api-sender.js', + '/fg/js/popup.js', + '/fg/js/popup-proxy.js', + '/fg/js/frontend.js', + '/fg/js/content-script-main.js' + ]; + for (const src of scriptSrcs) { + const script = document.createElement('script'); + script.async = false; + script.src = src; + document.body.appendChild(script); + } +} + +async function popupNestedInitialize(id, depth, parentFrameId, url) { + let optionsApplied = false; + + const applyOptions = async () => { + const optionsContext = {depth, url}; + const options = await apiOptionsGet(optionsContext); + const popupNestingMaxDepth = options.scanning.popupNestingMaxDepth; + + const maxPopupDepthExceeded = !( + typeof popupNestingMaxDepth === 'number' && + typeof depth === 'number' && + depth < popupNestingMaxDepth + ); + if (maxPopupDepthExceeded || optionsApplied) { + return; + } + + optionsApplied = true; + + window.frontendInitializationData = {id, depth, parentFrameId, url, proxy: true}; + injectPopupNested(); + + yomichan.off('optionsUpdated', applyOptions); + }; + + yomichan.on('optionsUpdated', applyOptions); + + await applyOptions(); +} + async function main() { new DisplayFloat(); } diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js deleted file mode 100644 index 27482931..00000000 --- a/ext/fg/js/popup-nested.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2019-2020 Yomichan Authors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/* global - * apiOptionsGet - */ - -function injectPopupNested() { - const scriptSrcs = [ - '/mixed/js/text-scanner.js', - '/fg/js/frontend-api-sender.js', - '/fg/js/popup.js', - '/fg/js/popup-proxy.js', - '/fg/js/frontend.js', - '/fg/js/content-script-main.js' - ]; - for (const src of scriptSrcs) { - const script = document.createElement('script'); - script.async = false; - script.src = src; - document.body.appendChild(script); - } -} - -async function popupNestedInitialize(id, depth, parentFrameId, url) { - let optionsApplied = false; - - const applyOptions = async () => { - const optionsContext = {depth, url}; - const options = await apiOptionsGet(optionsContext); - const popupNestingMaxDepth = options.scanning.popupNestingMaxDepth; - - const maxPopupDepthExceeded = !( - typeof popupNestingMaxDepth === 'number' && - typeof depth === 'number' && - depth < popupNestingMaxDepth - ); - if (maxPopupDepthExceeded || optionsApplied) { - return; - } - - optionsApplied = true; - - window.frontendInitializationData = {id, depth, parentFrameId, url, proxy: true}; - injectPopupNested(); - - yomichan.off('optionsUpdated', applyOptions); - }; - - yomichan.on('optionsUpdated', applyOptions); - - await applyOptions(); -} From d8276a9d5d119edf1747593608d3e135947019f0 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 22 Apr 2020 21:42:20 -0400 Subject: [PATCH 8/8] Use IIFE for entry points --- ext/bg/js/background-main.js | 6 ++---- ext/bg/js/context-main.js | 6 ++---- ext/bg/js/search-main.js | 6 ++---- ext/bg/js/settings/popup-preview-frame-main.js | 6 ++---- ext/fg/js/content-script-main.js | 6 ++---- ext/fg/js/float-main.js | 6 ++---- 6 files changed, 12 insertions(+), 24 deletions(-) diff --git a/ext/bg/js/background-main.js b/ext/bg/js/background-main.js index c000c38d..24117f4e 100644 --- a/ext/bg/js/background-main.js +++ b/ext/bg/js/background-main.js @@ -19,9 +19,7 @@ * Backend */ -async function main() { +(async () => { window.yomichanBackend = new Backend(); await window.yomichanBackend.prepare(); -} - -main(); +})(); diff --git a/ext/bg/js/context-main.js b/ext/bg/js/context-main.js index 67bb4e18..e2086a96 100644 --- a/ext/bg/js/context-main.js +++ b/ext/bg/js/context-main.js @@ -88,8 +88,6 @@ async function mainInner() { }); } -async function main() { +(async () => { window.addEventListener('DOMContentLoaded', mainInner, false); -} - -main(); +})(); diff --git a/ext/bg/js/search-main.js b/ext/bg/js/search-main.js index 91c39222..38b6d99a 100644 --- a/ext/bg/js/search-main.js +++ b/ext/bg/js/search-main.js @@ -52,7 +52,7 @@ function injectSearchFrontend() { } } -async function main() { +(async () => { await yomichan.prepare(); const displaySearch = new DisplaySearch(); @@ -78,6 +78,4 @@ async function main() { yomichan.on('optionsUpdated', applyOptions); await applyOptions(); -} - -main(); +})(); diff --git a/ext/bg/js/settings/popup-preview-frame-main.js b/ext/bg/js/settings/popup-preview-frame-main.js index e6e4727f..86c2814c 100644 --- a/ext/bg/js/settings/popup-preview-frame-main.js +++ b/ext/bg/js/settings/popup-preview-frame-main.js @@ -19,9 +19,7 @@ * SettingsPopupPreview */ -async function main() { +(async () => { const instance = new SettingsPopupPreview(); await instance.prepare(); -} - -main(); +})(); diff --git a/ext/fg/js/content-script-main.js b/ext/fg/js/content-script-main.js index 974320cc..14285536 100644 --- a/ext/fg/js/content-script-main.js +++ b/ext/fg/js/content-script-main.js @@ -61,7 +61,7 @@ async function createPopupProxy(depth, id, parentFrameId, url) { return popup; } -async function contentScriptMain() { +(async () => { await yomichan.prepare(); const data = window.frontendInitializationData || {}; @@ -128,6 +128,4 @@ async function contentScriptMain() { window.addEventListener('fullscreenchange', applyOptions, false); await applyOptions(); -} - -contentScriptMain(); +})(); diff --git a/ext/fg/js/float-main.js b/ext/fg/js/float-main.js index 072c86e0..f056f707 100644 --- a/ext/fg/js/float-main.js +++ b/ext/fg/js/float-main.js @@ -67,8 +67,6 @@ async function popupNestedInitialize(id, depth, parentFrameId, url) { await applyOptions(); } -async function main() { +(async () => { new DisplayFloat(); -} - -main(); +})();