-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathappend_ourselves.js
34 lines (31 loc) · 1.09 KB
/
append_ourselves.js
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
26
27
28
29
30
31
32
33
34
var thisScript = /complete.js/;
var theScripts = document.getElementsByTagName('SCRIPT');
for (var i = 0 ; i < theScripts.length; i++) {
if(theScripts[i].src.match(thisScript)) {
var inForm = false;
var currentNode = theScripts[i].parentNode;
while (currentNode != null) {
if (currentNode.nodeType == 1) {
if (currentNode.tagName.toLowerCase() == 'form') {
inForm = true;
break;
}
}
/* always */
currentNode = currentNode.parentNode;
}
if (inForm) {
/* if we are inside a form, we do not want to create
another form tag. So replace our FORM tag with
a DIV.
*/
in_string = in_string.replace('<form ', '<div ');
in_string = in_string.replace('</form>', '</div>');
}
var my_div = document.createElement('DIV');
my_div.innerHTML = in_string;
theScripts[i].parentNode.insertBefore(my_div, theScripts[i]);
theScripts[i].parentNode.removeChild(theScripts[i]);
break;
}
}