-
Notifications
You must be signed in to change notification settings - Fork 1
/
m3.js
66 lines (65 loc) · 1.41 KB
/
m3.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
s = s.split(",");
var text = []
document.write = function (t) {
text.push(t);
}
var i = 0, ii = s.length;
var addText = function (elName) {
var f = function () {
console.debug("writing to ", elName);
var c;
if (elName) {
c = document.getElementById(elName);
} else {
c = document.body;
}
console.debug(c, !c);
if (c) {
console.debug(text);
c.innerHTML += text.join("\n");
text=[];
i++;
console.debug(i, ii);
if (i < ii) {
doNext();
}
} else {
console.debug("waiting for element to exist");
setTimeout(f, 10);
}
};
return f;
}
var doNext = function () {
var p;
try {
p = pos;
p = pos.split(",").length > i ? pos.split(",")[i] : pos.split(",")[0];
} catch (e1) {
try {
p = pos.split(",")[0];
} catch (e2) {
p = null;
}
}
console.debug("doNext", p, s[i]);
var el = document.createElement("script");
el.src="../"+s[i];
el.defer="true";
el.onload = function () {
addText(p)();
}
var beenRun = false;
el.onreadystatechange = function () {
console.debug(this.readyState, s[i]);
if (beenRun) return;
if ((this.readyState === "complete") ||
(this.readyState === "loaded")) {
beenRun = true;
console.debug(document.getElementById);
addText(p)();
}
};
document.getElementsByTagName("head")[0].appendChild(el);
}
doNext();