aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/utils
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-03-24 11:36:54 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-03-24 11:36:54 +0530
commitfeac7acb91a78b117241abdd0a5d80f778e15f06 (patch)
treeebee27b43105aeed1048e86afb1e6e3d2b7e1075 /config/webpack/utils
parenta9f2d88e1e5b1c7ddf524db8b5b185b8485f8d48 (diff)
downloadbanglar-bhumi-utils-feac7acb91a78b117241abdd0a5d80f778e15f06.tar.gz
banglar-bhumi-utils-feac7acb91a78b117241abdd0a5d80f778e15f06.zip
Overriding the javascript on the page instead of locally replacing it.
Diffstat (limited to 'config/webpack/utils')
-rw-r--r--config/webpack/utils/get-injection-code.js23
-rw-r--r--config/webpack/utils/script-runtime.js1
2 files changed, 24 insertions, 0 deletions
diff --git a/config/webpack/utils/get-injection-code.js b/config/webpack/utils/get-injection-code.js
new file mode 100644
index 0000000..71afa93
--- /dev/null
+++ b/config/webpack/utils/get-injection-code.js
@@ -0,0 +1,23 @@
+module.exports.getInjectionCode = (code, front) => {
+ 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]);
+ }
+
+ const concatenationCode = front
+ ? "t.innerHTML=i+t.innerHTML"
+ : "t.innerHTML+=i";
+
+ return `(()=>{let e=new MutationObserver(()=>{let t=document.querySelector("head > script:nth-child(54)");if(t){let i=\`(()=>{${finalCode}})();\`;${concatenationCode},e.disconnect()}});e.observe(document,{childList:!0,subtree:!0})})();`;
+};
diff --git a/config/webpack/utils/script-runtime.js b/config/webpack/utils/script-runtime.js
index 8215ba2..f424168 100644
--- a/config/webpack/utils/script-runtime.js
+++ b/config/webpack/utils/script-runtime.js
@@ -2,6 +2,7 @@ module.exports.getScriptRuntimeFromType = scriptType => {
switch (scriptType) {
case "before":
case "injected":
+ case "injected-before":
return "document_start";
case "rendered":