Last active
July 1, 2016 15:13
-
-
Save tapannallan/f4b71f1f2013769e17363dd982ed742c to your computer and use it in GitHub Desktop.
I like adblockers.. so..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(E) { | |
var u = true; | |
var H = true; | |
var j = ""; | |
var B = {}; | |
var x = "offset", | |
t = "client"; | |
var I = function() {}; | |
var q = false; | |
var v = false; | |
var o = (E.addEventListener === undefined); | |
var J = { | |
loopDelay: 50, | |
maxLoop: 5, | |
testRemoteList: true, | |
debug: true, | |
useLocalBait: true, | |
blockLists: [], | |
found: I, | |
notfound: I, | |
complete: I | |
}; | |
function w(Q) { | |
var N, O; | |
try { | |
N = JSON.parse(Q) | |
} catch (P) { | |
try { | |
O = new Function("return " + Q); | |
N = O() | |
} catch (P) { | |
g("Failed secondary JSON parse", true) | |
} | |
} | |
return N | |
} | |
var k = function(P) { | |
var Q = new XMLHttpRequest(); | |
this.success = P.success || I; | |
this.fail = P.fail || I; | |
var O = this; | |
var S = P.method || "get"; | |
this.abort = function() { | |
try { | |
Q.abort() | |
} catch (T) {} | |
}; | |
function N(T) { | |
if (Q.readyState == 4) { | |
if (Q.status == 200) { | |
O.success(Q.response) | |
} else { | |
O.fail(Q.status) | |
} | |
} | |
} | |
Q.onreadystatechange = N; | |
function R() { | |
Q.open(S, P.url, true); | |
Q.send() | |
} | |
R() | |
}; | |
var e = function() { | |
var O = this; | |
var N = {}; | |
this.addUrl = function(P) { | |
N[P] = { | |
url: P, | |
state: "pending", | |
format: null, | |
data: null, | |
result: null | |
}; | |
return N[P] | |
}; | |
this.setResult = function(P, S, R) { | |
var T = N[P]; | |
if (T == null) { | |
T = this.addUrl(P) | |
} | |
T.state = S; | |
if (R == null) { | |
T.result = null; | |
return | |
} | |
if (typeof R === "string") { | |
try { | |
R = w(R); | |
T.format = "json" | |
} catch (Q) { | |
T.format = "easylist" | |
} | |
} | |
T.data = R; | |
return T | |
} | |
}; | |
var D = []; | |
var G = null; | |
var A = { | |
cssClass: "pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links" | |
}; | |
var m = { | |
nullProps: [x + "Parent"], | |
zeroProps: [] | |
}; | |
m.zeroProps = [x + "Height", x + "Left", x + "Top", x + "Width", x + "Height", t + "Height", t + "Width"]; | |
var s = { | |
quick: null, | |
remote: null | |
}; | |
var y = null; | |
var p = { | |
test: 0, | |
download: 0 | |
}; | |
function L(N) { | |
return typeof(N) == "function" | |
} | |
function l(O, R) { | |
var Q, P, S, N = R; | |
var T = document; | |
S = T.createElement(O); | |
if (N) { | |
for (Q in N) { | |
if (N.hasOwnProperty(Q)) { | |
S.setAttribute(Q, N[Q]) | |
} | |
} | |
} | |
return S | |
} | |
function r(P, N, O) { | |
if (o) { | |
P.attachEvent("on" + N, O) | |
} else { | |
P.addEventListener(N, O, false) | |
} | |
} | |
function g(O, N) { | |
if (!J.debug && !N) { | |
return | |
} | |
if (E.console && E.console.log) { | |
if (N) { | |
console.error("[ABD] " + O) | |
} else { | |
console.log("[ABD] " + O) | |
} | |
} | |
} | |
var b = []; | |
function a(O) { | |
var P, N; | |
n.addUrl(O); | |
P = new k({ | |
url: O, | |
success: function(T) { | |
g("downloaded file " + O); | |
N = n.setResult(O, "success", T); | |
try { | |
var S = 0, | |
U = 0; | |
var R = function(V) { | |
if (!v) { | |
c(V, true); | |
return true | |
} | |
return false | |
}; | |
if (y == true) { | |
return | |
} | |
if (R(N.data)) { | |
return | |
} else { | |
g("Pause before test execution"); | |
S = setInterval(function() { | |
if (R(N.data) || U++ > 5) { | |
clearInterval(S) | |
} | |
}, 250) | |
} | |
} catch (Q) { | |
g(Q.message + " url: " + O, true) | |
} | |
}, | |
fail: function(Q) { | |
g(Q, true); | |
n.setResult(O, "error", null) | |
} | |
}); | |
b.push(P) | |
} | |
function d() { | |
var O, N; | |
var P = J; | |
for (O = 0; O < P.blockLists.length; O++) { | |
N = P.blockLists[O]; | |
a(N) | |
} | |
} | |
function i() { | |
var N, O; | |
for (N = b.length - 1; N >= 0; N--) { | |
O = b.pop(); | |
O.abort() | |
} | |
} | |
function c(O, N) { | |
g("start beginTest"); | |
if (y == true) { | |
return | |
} | |
v = true; | |
M(O); | |
if (!N) { | |
s.quick = "testing" | |
} else { | |
s.remote = "testing" | |
} | |
p.test = setTimeout(function() { | |
f(O, 1) | |
}, 5); | |
if (!N && J.testRemoteList) { | |
d() | |
} | |
} | |
function M(R) { | |
var Q, S = document, | |
N = S.body; | |
var P; | |
var O = "width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;"; | |
if (R == null || typeof(R) == "string") { | |
g("invalid bait being cast"); | |
return | |
} | |
if (R.style != null) { | |
O += R.style | |
} | |
G = l("div", { | |
"class": R.cssClass, | |
style: O | |
}); | |
g("adding bait node to DOM"); | |
N.appendChild(G); | |
for (Q = 0; Q < m.nullProps.length; Q++) { | |
P = G[m.nullProps[Q]] | |
} | |
for (Q = 0; Q < m.zeroProps.length; Q++) { | |
P = G[m.zeroProps[Q]] | |
} | |
} | |
function f(V, T) { | |
var O, N, U; | |
var Q = document.body; | |
var W = false; | |
var S = null; | |
if (G == null) { | |
g("recast bait"); | |
M(V || A) | |
} | |
if (typeof(V) == "string") { | |
g("invalid bait used", true); | |
if (z()) { | |
setTimeout(function() { | |
v = false | |
}, 5) | |
} | |
return | |
} | |
if (p.test > 0) { | |
clearTimeout(p.test); | |
p.test = 0 | |
} | |
if (Q.getAttribute("abp") !== null) { | |
g("found adblock body attribute"); | |
W = true; | |
S = "body_abp_attr" | |
} | |
if (!W) { | |
for (O = 0; O < m.nullProps.length; O++) { | |
if (G[m.nullProps[O]] == null) { | |
W = true; | |
g("found adblock null attr: " + m.nullProps[O]); | |
S = "null_attr " + m.nullProps[O]; | |
break | |
} | |
if (W == true) { | |
break | |
} | |
} | |
for (O = 0; O < m.zeroProps.length; O++) { | |
if (W == true) { | |
break | |
} | |
if (G[m.zeroProps[O]] == 0) { | |
W = true; | |
S = "zero_attr " + m.zeroProps[O]; | |
g("found adblock zero attr: " + m.zeroProps[O]) | |
} | |
} | |
} | |
if (!W) { | |
if (window.getComputedStyle !== undefined) { | |
var P = window.getComputedStyle(G, null); | |
if (P.getPropertyValue("display") == "none" || P.getPropertyValue("visibility") == "hidden") { | |
W = true; | |
S = "computedStyle indicator"; | |
g("found adblock computedStyle indicator") | |
} | |
} | |
} | |
q = true; | |
if (W || T++ >= J.maxLoop) { | |
y = W; | |
try { | |
if (W) { | |
B.blockerDetected(S, T) | |
} else {} | |
} catch (R) { | |
g(R.message) | |
} | |
g("exiting test loop - value: " + y); | |
K(); | |
if (z()) { | |
setTimeout(function() { | |
v = false | |
}, 5) | |
} | |
} else { | |
p.test = setTimeout(function() { | |
f(V, T) | |
}, J.loopDelay) | |
} | |
} | |
function z() { | |
if (G === null) { | |
return true | |
} | |
try { | |
if (L(G.remove)) { | |
G.remove() | |
} | |
document.body.removeChild(G) | |
} catch (N) {} | |
G = null; | |
return true | |
} | |
function F() { | |
if (p.test > 0) { | |
clearTimeout(p.test) | |
} | |
if (p.download > 0) { | |
clearTimeout(p.download) | |
} | |
i(); | |
z() | |
} | |
function K() { | |
var P, N; | |
if (y === null) { | |
return | |
} | |
for (P = 0; P < D.length; P++) { | |
N = D[P]; | |
try { | |
if (N != null) { | |
if (L(N.complete)) { | |
N.complete(y) | |
} | |
if (y && L(N.found)) { | |
N.found() | |
} else { | |
if (y === false && L(N.notfound)) { | |
N.notfound() | |
} | |
} | |
} | |
} catch (O) { | |
g("Failure in notify listeners " + O.Message, true) | |
} | |
} | |
} | |
function h() { | |
var N = true; | |
var O; | |
if (document.readyState) { | |
if (document.readyState == "complete") { | |
N = true | |
} | |
} | |
O = function() { | |
if (J.useLocalBait) { | |
c(A, false) | |
} else { | |
g("ignoreing local bait - download remote"); | |
d() | |
} | |
}; | |
if (N) { | |
O() | |
} else { | |
r(E, "load", O) | |
} | |
} | |
var n; | |
var C = { | |
init: function(Q) { | |
var P, O, N; | |
if (!Q) { | |
return | |
} | |
N = { | |
complete: I, | |
found: I, | |
notfound: I | |
}; | |
for (P in Q) { | |
if (Q.hasOwnProperty(P)) { | |
if (P == "complete" || P == "found" || P == "notFound") { | |
N[P.toLowerCase()] = Q[P] | |
} else { | |
J[P] = Q[P] | |
} | |
} | |
} | |
D.push(N); | |
n = new e(); | |
h() | |
} | |
}; | |
E.detector = C; | |
B = { | |
key: { | |
BLOCKER: "AdBlocker", | |
FOUND: "Found", | |
NOT_FOUND: "NotFound", | |
DETECT: "IABDetect" | |
}, | |
recordEvent: function(O, Q, N, P) { | |
if (!u) { | |
return | |
} | |
if (window.ga) { | |
ga("send", "event", O, Q, N, P) | |
} | |
}, | |
redirect: function() { | |
if (!H) { | |
return | |
} | |
var N = document.getElementById("block-detector"); | |
if (N) { | |
var O = N.getAttribute("data-redirect"); | |
if (O) { | |
window.location = O | |
} | |
} else { | |
window.location = "/blocked.cms" | |
} | |
}, | |
blockerDetected: function(P, O) { | |
var N = B.key; | |
if (navigator.userAgent.indexOf("Firefox") != -1 && location.host == "timesofindia.indiatimes.com" && location.href.indexOf("/articleshow/") != -1) { | |
if (window.canRun === undefined) { | |
B.recordEvent(N.DETECT, N.FOUND, P, O); | |
B.redirect() | |
} | |
} else { | |
B.recordEvent(N.DETECT, N.FOUND, P, O); | |
B.redirect() | |
} | |
}, | |
blockerNotDetected: function() { | |
var N = B.key | |
} | |
} | |
})(window); | |
window.detector.init({}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment