| @@ -1,63 +1,45 @@ | ||
| 1 | +! function() { | |
| 2 | + "use strict"; | |
| 1 | 3 | |
| 2 | -function insertAfter(e, t) { | |
| 3 | - t.parentNode.insertBefore(e, t.nextSibling) | |
| 4 | -} | |
| 4 | + function e(e, t) { | |
| 5 | + let n = t.parentNode; | |
| 6 | + n.lastChild === t ? n.appendChild(e) : n.insertBefore(e, t.nextSibling) | |
| 7 | + } | |
| 5 | 8 | |
| 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 | -} | |
| 9 | + function t(e, t = document) { | |
| 10 | + if (t.evaluate) return t.evaluate(e, t, null, 9, null).singleNodeValue; | |
| 11 | + e = e.replace(/^\/+/, ""); | |
| 12 | + let n = e.split("/"), | |
| 13 | + l = t; | |
| 14 | + for (let i = 0, r = n.length; i < r && l; i += 1) { | |
| 15 | + let a = /([^\[\]]+)(?:\[(\d+)\])?/.exec(n[i]); | |
| 16 | + if (!a) return null; | |
| 17 | + let [, u, o] = a, f = o ? o - 1 : 0; | |
| 18 | + l = l.getElementsByTagName(u)[f] || null | |
| 19 | + } | |
| 20 | + return l | |
| 21 | + } | |
| 41 | 22 | |
| 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 | -} | |
| 23 | + function n(t) { | |
| 24 | + if (!t) return; | |
| 25 | + let n = document.createDocumentFragment(), | |
| 26 | + l = document.createElement("span"), | |
| 27 | + i = document.createElement("script"); | |
| 28 | + l.insertAdjacentHTML("beforeend", "{{HTML}}"), i.text = "{{SCRIPT}}", n.appendChild(l), n.appendChild(i), e(n, t) | |
| 29 | + } | |
| 30 | + Array.prototype.filter || (Array.prototype.filter = function(e, t) { | |
| 31 | + if ("function" != typeof e) throw TypeError(); | |
| 32 | + let n = []; | |
| 33 | + for (let l = 0, i = this.length >>> 0; l < i; l += 1) | |
| 34 | + if (l in this) { | |
| 35 | + let r = this[l]; | |
| 36 | + e.call(t, r, l, this) && n.push(r) | |
| 37 | + } return n | |
| 38 | + }), window.insertAfter = e, window.getElementByXPath = t, window.injectWidgetByXpath = function e(l) { | |
| 39 | + let i = t(l) || document.getElementById("tbdefault"); | |
| 40 | + i && n(i) | |
| 41 | + }, window.injectWidgetByMarker = function e(t) { | |
| 42 | + let l = document.getElementById(t); | |
| 43 | + l && l.parentNode && n(l.parentNode) | |
| 44 | + }, window.innerInject = n | |
| 45 | +}(); | |