aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-17 01:31:25 +0300
committerGitHub <noreply@github.com>2020-04-17 01:31:25 +0300
commite6053eefa594524c7adcec4986a5a2c499adf192 (patch)
tree5a42ad3163455eda4306fbb5964f8b7fec20bf82 /ext/bg
parentbf971be15bf8787f992f03bb5943e3ee32c1583a (diff)
parentb6f7f8c02637cef9cadd4ab2b9f253c42903aee6 (diff)
Merge pull request #439 from siikamiika/popup-live-toggle
Popup live toggle
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/search-frontend.js40
-rw-r--r--ext/bg/js/search-query-parser.js2
2 files changed, 28 insertions, 14 deletions
diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js
index 9cc1436f..e534e771 100644
--- a/ext/bg/js/search-frontend.js
+++ b/ext/bg/js/search-frontend.js
@@ -19,18 +19,7 @@
* apiOptionsGet
*/
-async function searchFrontendSetup() {
- await yomichan.prepare();
-
- const optionsContext = {
- depth: 0,
- url: window.location.href
- };
- const options = await apiOptionsGet(optionsContext);
- if (!options.scanning.enableOnSearchPage) { return; }
-
- window.frontendInitializationData = {depth: 1, proxy: false};
-
+function injectSearchFrontend() {
const scriptSrcs = [
'/mixed/js/text-scanner.js',
'/fg/js/frontend-api-receiver.js',
@@ -62,4 +51,29 @@ async function searchFrontendSetup() {
}
}
-searchFrontendSetup();
+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 || optionsApplied) { return; }
+ optionsApplied = true;
+
+ window.frontendInitializationData = {depth: 1, proxy: false, isSearchPage: true};
+ injectSearchFrontend();
+
+ yomichan.off('optionsUpdated', applyOptions);
+ };
+
+ yomichan.on('optionsUpdated', applyOptions);
+
+ await applyOptions();
+}
+
+main();
diff --git a/ext/bg/js/search-query-parser.js b/ext/bg/js/search-query-parser.js
index 01a0ace5..f90c68ee 100644
--- a/ext/bg/js/search-query-parser.js
+++ b/ext/bg/js/search-query-parser.js
@@ -27,7 +27,7 @@
class QueryParser extends TextScanner {
constructor({getOptionsContext, setContent, setSpinnerVisible}) {
- super(document.querySelector('#query-parser-content'), [], []);
+ super(document.querySelector('#query-parser-content'), () => [], []);
this.getOptionsContext = getOptionsContext;
this.setContent = setContent;