diff options
Diffstat (limited to 'config/webpack/plugins/inject-script-webpack-plugin')
| -rw-r--r-- | config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js | 18 | ||||
| -rw-r--r-- | config/webpack/plugins/inject-script-webpack-plugin/index.js | 30 |
2 files changed, 0 insertions, 48 deletions
diff --git a/config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js b/config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js deleted file mode 100644 index 2993c44..0000000 --- a/config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports.getInjectionCode = code => { - const escapeSequences = [["\b", "\\b"], - ["\f", "\\f"], - ["\n", "\\n"], - ["\r", "\\r"], - ["\t", "\\t"], - ["\v", "\\v"] - ]; - let finalCode = code.replaceAll("`","\\`"); - - for (const escapeSequence of escapeSequences) { - finalCode = finalCode - .replaceAll(escapeSequence[1], "\\" + escapeSequence[1]) - .replaceAll(escapeSequence[0], escapeSequence[1]); - } - - return `(()=>{const o=new MutationObserver(()=>{let t=document.querySelector("head > script:nth-child(54)");if(t){let e=\`(()=>{${finalCode}})();\`;null==t.getAttribute("data-replaced")?(t.innerHTML=e,t.setAttribute("data-replaced","")):t.innerHTML+=e,o.disconnect()}});o.observe(document,{childList:!0,subtree:!0});})();`; -}; diff --git a/config/webpack/plugins/inject-script-webpack-plugin/index.js b/config/webpack/plugins/inject-script-webpack-plugin/index.js deleted file mode 100644 index a0ee1f7..0000000 --- a/config/webpack/plugins/inject-script-webpack-plugin/index.js +++ /dev/null @@ -1,30 +0,0 @@ -const { sources } = require("webpack"); -const terser = require("terser"); - -const { getInjectionCode } = webpackRequire("plugins/inject-script-webpack-plugin/get-injection-code"); - -class InjectScriptPlugin { - apply(compiler) { - compiler.hooks.compilation.tap("InjectScriptPlugin", compilation => { - compilation.hooks.processAssets.tapPromise( - { - name: "InjectScriptPlugin", - stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ANALYSE, - additionalAssets: true - }, - async assets => { - for (const assetName in assets) { - if (assetName.endsWith("injected.js")) { - compilation.updateAsset( - assetName, - new sources.RawSource(getInjectionCode(compilation.getAsset(assetName).source.source())) - ); - } - } - } - ); - }); - } -} - -module.exports = InjectScriptPlugin; |
