| 1 |
|
| 2 |
function insertAfter(e, t) { |
| 3 |
t.parentNode.insertBefore(e, t.nextSibling) |
| 4 |
} |
| 5 |
|
| 6 |
function getElementByXPath(e, t) { |
| 7 |
if (!t) t = document; |
| 8 |
if (t.evaluate) return t.evaluate(e, document, null, 9, null).singleNodeValue; |
| 9 |
while (e.charAt(0) == "/") e = e.substr(1); |
| 10 |
var n = t; |
| 11 |
var r = e.split("/"); |
| 12 |
for (var i = 0; i < r.length; i++) { |
| 13 |
var a = r[i].split(/(\w*)\[(\d*)\]/gi).filter(function(e) { |
| 14 |
return !(e == "" || e.match(/\s/gi)) |
| 15 |
}, this); |
| 16 |
var l = a[0]; |
| 17 |
var o = a[1] ? a[1] - 1 : 0; |
| 18 |
if (i < r.length - 1) n = n.getElementsByTagName(l)[o]; |
| 19 |
else return n.getElementsByTagName(l)[o] |
| 20 |
} |
| 21 |
} |
| 22 |
if (!Array.prototype.filter) { |
| 23 |
Array.prototype.filter = function(e) { |
| 24 |
var t = this.length >>> 0; |
| 25 |
if (typeof e != "function") { |
| 26 |
throw new TypeError |
| 27 |
} |
| 28 |
var n = []; |
| 29 |
var r = arguments[1]; |
| 30 |
for (var i = 0; i < t; i++) { |
| 31 |
if (i in this) { |
| 32 |
var a = this[i]; |
| 33 |
if (e.call(r, a, i, this)) { |
| 34 |
n.push(a) |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
return n |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
function injectWidgetByXpath(e) { |
| 43 |
var t = getElementByXPath(e); |
| 44 |
if (t == null) { |
| 45 |
t = document.getElementById("tbdefault") |
| 46 |
} |
| 47 |
innerInject(t) |
| 48 |
} |
| 49 |
|
| 50 |
function injectWidgetByMarker(e) { |
| 51 |
var t = document.getElementById(e); |
| 52 |
innerInject(t.parentNode) |
| 53 |
} |
| 54 |
|
| 55 |
function innerInject(e) { |
| 56 |
var t = document.createElement("span"); |
| 57 |
var n = document.createElement("script"); |
| 58 |
var r = "if JS crashes here, the first innerHTML value should be enclosed with single quotes instead of double, go to the minified version and change it"; |
| 59 |
t.innerHTML = "{{HTML}}"; |
| 60 |
n.innerHTML = "{{SCRIPT}}"; |
| 61 |
insertAfter(t, e); |
| 62 |
insertAfter(n, t) |
| 63 |
} |
| 64 |
|