From 61a96e327a815bda7fea4c5d2096dead901fdf33 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Fri, 10 Apr 2020 02:15:24 +0300 Subject: prevent injecting frontend multiple times --- ext/bg/js/search-frontend.js | 5 ++++- ext/fg/js/popup-nested.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js index 48326caf..18cb6060 100644 --- a/ext/bg/js/search-frontend.js +++ b/ext/bg/js/search-frontend.js @@ -54,13 +54,16 @@ function injectSearchFrontend() { async function main() { await yomichan.prepare(); + let optionsApplied = false; + const applyOptions = async () => { const optionsContext = { depth: 0, url: window.location.href }; const options = await apiOptionsGet(optionsContext); - if (!options.scanning.enableOnSearchPage) { return; } + if (!options.scanning.enableOnSearchPage || optionsApplied) { return; } + optionsApplied = true; window.frontendInitializationData = {depth: 1, proxy: false}; injectSearchFrontend(); diff --git a/ext/fg/js/popup-nested.js b/ext/fg/js/popup-nested.js index f193aa36..3ecdf50c 100644 --- a/ext/fg/js/popup-nested.js +++ b/ext/fg/js/popup-nested.js @@ -44,15 +44,24 @@ async function popupNestedInitialize(id, depth, parentFrameId, url) { } popupNestedInitialized = true; + let optionsApplied = false; + const applyOptions = async () => { const optionsContext = {depth, url}; const options = await apiOptionsGet(optionsContext); const popupNestingMaxDepth = options.scanning.popupNestingMaxDepth; - if (!(typeof popupNestingMaxDepth === 'number' && typeof depth === 'number' && depth < 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(); -- cgit v1.2.3