aboutsummaryrefslogtreecommitdiffstats
path: root/config/webpack/utils/get-injection-code.js
blob: ec969c1afe9e19d18884b68a5b3d04902512477d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
module.exports.getInjectionCode = (code, front) => {
	let finalCode = code
		.replaceAll("\\", "\\\\")
		.replaceAll("`","\\`")
		.replaceAll("${", "\\${");

	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})})();`;
};