PluginProbe
Taboola / 2.2.2
Taboola v2.2.2
1.0.4 1.0.5 1.0.6 1.0.8 2.0.1 2.0.2 2.1.0 2.1.1 2.2.2 2.2.3 3.0.0 3.0.1 3.0.2 3.1.0 trunk 1.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.2 1.0.3
taboola / js / js_inject.js

js_inject.js in Taboola 2.2.2, at js/js_inject.js

81 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 function insertAfter(newNode, referenceNode) {
2 referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
3 }
4 function getElementByXPath(xPath, doc){
5 if(!doc) doc = document;
6 if(doc.evaluate) return doc.evaluate(xPath, document, null, 9, null).singleNodeValue;
7 // for IE
8 while(xPath.charAt(0) == '/') xPath = xPath.substr(1);
9 var prevElem = doc;
10 var arr = xPath.split('/');
11 for(var i=0; i<arr.length; i++){
12 var step = arr[i].split(/(\w*)\[(\d*)\]/gi).filter(function(v){ return !(v==''||v.match(/\s/gi)) },this);
13 var elem = step[0];
14 var elemNum = step[1]?step[1]-1:0; // -1 since xpath is 1 based
15 if(i<arr.length-1) prevElem = prevElem.getElementsByTagName(elem)[elemNum];
16 else return prevElem.getElementsByTagName(elem)[elemNum];
17 }
18 }
19
20
21 /**
22 * Copyright (c) Mozilla Foundation http://www.mozilla.org/
23 * This code is available under the terms of the MIT License
24 */
25 if (!Array.prototype.filter) {
26 Array.prototype.filter = function(fun /*, thisp*/) {
27 var len = this.length >>> 0;
28 if (typeof fun != "function") {
29 throw new TypeError();
30 }
31
32 var res = [];
33 var thisp = arguments[1];
34 for (var i = 0; i < len; i++) {
35 if (i in this) {
36 var val = this[i]; // in case fun mutates this
37 if (fun.call(thisp, val, i, this)) {
38 res.push(val);
39 }
40 }
41 }
42
43 return res;
44 };
45 }
46 /* END MIT License code */
47
48 function injectWidgetByXpath(xpath){
49
50 var n = getElementByXPath(xpath);
51
52 // Default placement in case the xpath location is not found
53 if (n==null){
54 n = document.getElementById("tbdefault");
55 }
56 innerInject(n);
57 }
58
59 function injectWidgetByMarker(markerId){
60 var markerNode = document.getElementById(markerId);
61 innerInject(markerNode.parentNode);
62 }
63
64 function innerInject(node){
65
66 var c = document.createElement("span");
67 var s = document.createElement("script");
68
69 // Notice that minifier will replce single quotes to double quotes. here it must remain with single quotes
70 var noticeForDeveloper = "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";
71 c.innerHTML = '{{HTML}}';
72 s.innerHTML = "{{SCRIPT}}";
73
74 insertAfter(c,node);
75 insertAfter(s,c);
76 }
77
78
79
80
81