diff options
| author | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-03-24 09:24:15 +0530 |
|---|---|---|
| committer | Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> | 2023-03-24 09:24:15 +0530 |
| commit | a9f2d88e1e5b1c7ddf524db8b5b185b8485f8d48 (patch) | |
| tree | 7f39667b6fc56bbf06adbbb3fc2aa6c54cfe27d1 /config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js | |
| parent | 3b29d138bee5e98c9536d3606de3e4b5378338f0 (diff) | |
| download | banglar-bhumi-utils-a9f2d88e1e5b1c7ddf524db8b5b185b8485f8d48.tar.gz banglar-bhumi-utils-a9f2d88e1e5b1c7ddf524db8b5b185b8485f8d48.zip | |
Improved some functionality.
Diffstat (limited to 'config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js')
| -rw-r--r-- | config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js | 19 |
1 files changed, 18 insertions, 1 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 index 6f3c9b3..2993c44 100644 --- a/config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js +++ b/config/webpack/plugins/inject-script-webpack-plugin/get-injection-code.js @@ -1 +1,18 @@ -module.exports = code => `(()=>{const o=new MutationObserver(()=>{let t=document.querySelector("head > script:nth-child(54)");if(t){let e=\`(()=>{${code.replaceAll("`","\\`")}})();\`;null==t.getAttribute("data-replaced")?(t.innerHTML=e,t.setAttribute("data-replaced","")):t.innerHTML+=e,o.disconnect()}});o.observe(document,{childList:!0,subtree:!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});})();`; +}; |
