diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-08 18:51:39 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-02-08 18:51:39 +0530 |
| commit | 915947e3e7ab7c1fa07596ab4b13bf6e1cc50b76 (patch) | |
| tree | 8e8a7137d2177dc52da83a5af9e8f7b442ed4a71 /config/webpack/plugins/inject-script-webpack-plugin.js | |
| parent | 4993aaf41e132dd0805bf6c487901d9f2aecfcfe (diff) | |
| download | banglar-bhumi-utils-915947e3e7ab7c1fa07596ab4b13bf6e1cc50b76.tar.gz banglar-bhumi-utils-915947e3e7ab7c1fa07596ab4b13bf6e1cc50b76.zip | |
Cleaned code.
Diffstat (limited to 'config/webpack/plugins/inject-script-webpack-plugin.js')
| -rw-r--r-- | config/webpack/plugins/inject-script-webpack-plugin.js | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/config/webpack/plugins/inject-script-webpack-plugin.js b/config/webpack/plugins/inject-script-webpack-plugin.js index 6568514..213e691 100644 --- a/config/webpack/plugins/inject-script-webpack-plugin.js +++ b/config/webpack/plugins/inject-script-webpack-plugin.js @@ -1,23 +1,6 @@ const { sources } = require("webpack"); const terser = require("terser"); -const propectualIndexOf = (string, characterList, start) => { - if (start > 0) { - let i = 0; - let x = start; - while (i < characterList.length) { - x = string.indexOf(characterList[i], x + 1); - if (x < 0) { - return -1; - } - i++; - } - return x; - } else { - return -1; - } -}; - class InjectScriptPlugin { constructor({ onload, isFirst }) { this.onload = !!onload; @@ -36,11 +19,11 @@ class InjectScriptPlugin { for (const assetName in assets) { if (assetName.endsWith(".js")) { let currentAssetContent = compilation.getAsset(assetName).source.source(); - let start = ` - const observer = new MutationObserver(mutations => { - const script = document.querySelector("head > script:nth-child(54)"); - if (script) { - script.innerHTML + let start = `(() => { + const o = new MutationObserver(() => { + const s = document.querySelector("head > script:nth-child(54)"); + if (s) { + s.innerHTML `; let end = ""; if (!this.isFirst) { @@ -52,11 +35,11 @@ class InjectScriptPlugin { end += "});"; } end += `\`; - observer.disconnect(); + o.disconnect(); } }); - observer.observe(document, {childList: true, subtree: true}); - `; + o.observe(document, {childList: true, subtree: true}); + })();`; const content = (await terser.minify(currentAssetContent.replaceAll("`", "\\`"))).code; compilation.updateAsset( assetName, |
