aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
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
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')
-rw-r--r--ext/bg/js/search-main.js41
-rw-r--r--ext/bg/search.html1
2 files changed, 12 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);
diff --git a/ext/bg/search.html b/ext/bg/search.html
index 8ed6c838..52915b76 100644
--- a/ext/bg/search.html
+++ b/ext/bg/search.html
@@ -86,6 +86,7 @@
<script src="/mixed/js/display-context.js"></script>
<script src="/mixed/js/display.js"></script>
<script src="/mixed/js/display-generator.js"></script>
+ <script src="/mixed/js/dynamic-loader.js"></script>
<script src="/mixed/js/media-loader.js"></script>
<script src="/mixed/js/scroll.js"></script>
<script src="/mixed/js/text-scanner.js"></script>