summaryrefslogtreecommitdiff
path: root/ext/bg/js/search-main.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-26 16:56:34 -0400
committerGitHub <noreply@github.com>2020-04-26 16:56:34 -0400
commit887d769786f2909dbd74e3465cef3551b780a49b (patch)
tree3ff18e6c82ba3bb85d797c06785d876a2485ad44 /ext/bg/js/search-main.js
parent4e0fc76fe1d4bf38cfbef370fcc55331108e0e0a (diff)
Use dynamicLoader for main (#481)
* Update style of search-main and float-main to have better parity * Use dynamicLoader to inject scripts and CSS
Diffstat (limited to 'ext/bg/js/search-main.js')
-rw-r--r--ext/bg/js/search-main.js41
1 files changed, 11 insertions, 30 deletions
diff --git a/ext/bg/js/search-main.js b/ext/bg/js/search-main.js
index 5e4d7a20..1075d46e 100644
--- a/ext/bg/js/search-main.js
+++ b/ext/bg/js/search-main.js
@@ -19,10 +19,14 @@
* DisplaySearch
* apiForwardLogsToBackend
* apiOptionsGet
+ * dynamicLoader
*/
-function injectSearchFrontend() {
- const scriptSrcs = [
+async function injectSearchFrontend() {
+ dynamicLoader.loadStyles([
+ '/fg/css/client.css'
+ ]);
+ await dynamicLoader.loadScripts([
'/mixed/js/text-scanner.js',
'/fg/js/frontend-api-receiver.js',
'/fg/js/frame-offset-forwarder.js',
@@ -30,27 +34,7 @@ function injectSearchFrontend() {
'/fg/js/popup-proxy-host.js',
'/fg/js/frontend.js',
'/fg/js/content-script-main.js'
- ];
- for (const src of scriptSrcs) {
- const node = document.querySelector(`script[src='${src}']`);
- if (node !== null) { continue; }
-
- const script = document.createElement('script');
- script.async = false;
- script.src = src;
- document.body.appendChild(script);
- }
-
- const styleSrcs = [
- '/fg/css/client.css'
- ];
- for (const src of styleSrcs) {
- const style = document.createElement('link');
- style.rel = 'stylesheet';
- style.type = 'text/css';
- style.href = src;
- document.head.appendChild(style);
- }
+ ]);
}
(async () => {
@@ -63,18 +47,15 @@ function injectSearchFrontend() {
let optionsApplied = false;
const applyOptions = async () => {
- const optionsContext = {
- depth: 0,
- url: window.location.href
- };
+ const optionsContext = {depth: 0, url: window.location.href};
const options = await apiOptionsGet(optionsContext);
if (!options.scanning.enableOnSearchPage || optionsApplied) { return; }
+
optionsApplied = true;
+ yomichan.off('optionsUpdated', applyOptions);
window.frontendInitializationData = {depth: 1, proxy: false, isSearchPage: true};
- injectSearchFrontend();
-
- yomichan.off('optionsUpdated', applyOptions);
+ await injectSearchFrontend();
};
yomichan.on('optionsUpdated', applyOptions);