-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddscript.js
More file actions
26 lines (23 loc) · 813 Bytes
/
Copy pathaddscript.js
File metadata and controls
26 lines (23 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function scriptInjector() {
// inject a script to the passed node
function injectScriptToNode(scriptPath, node) {
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
const th = document.getElementsByTagName(node)[0];
const s = document.createElement('script');
s.setAttribute('type', 'text/javascript');
s.setAttribute('class', 'injectedScript');
s.innerHTML = this.responseText;
th.appendChild(s);
}
};
xhttp.open('GET', scriptPath, true);
xhttp.send();
}
injectScriptToNode('injector', 'body');
}
// inject after 1000 milli seconds
// setTimeout(scriptInjector, 1000);
// inject after load event
window.addEventListener('load', scriptInjector);