Skip to content

Instantly share code, notes, and snippets.

@dhchow
Created February 24, 2011 00:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhchow/841496 to your computer and use it in GitHub Desktop.
Save dhchow/841496 to your computer and use it in GitHub Desktop.
prettified script located at http://tcr.tynt.com/ti.js which hijacks copy and paste and modifies its contents
//v13 © 2010 Tynt
var Tynt = Tynt || [];
if (typeof Tynt.TIL == "undefined") {
(function () {
var Ka = function () {
var i = document,
m = i.body,
p = i.documentElement,
aa = eval("/*@cc_on!@*/false"),
ba = function (a, b) {
for (var c = "", e = 0; e < b; e++) c += a;
return c
},
u = ba("a", 50),
v = "w." + (Tynt.e || "") + "ic.tynt.com",
ca = "p." + (Tynt.e || "") + "ic.tynt.com",
pa = (Tynt.e || "") + "ac.tynt.com/?id=" + u,
s = function () {
return (new Date).getTime()
},
D = function (a) {
return a.replace(/^\s+|\s+$/g, "")
},
M = function (a, b) {
for (var c in a) if (a.hasOwnProperty(c)) b[c] = a[c]
},
w = function (a, b, c) {
a = i.createElement(a);
M(b, a);
M(c, a.style);
return a
},
q, N;
if (window.addEventListener) {
q = function (a, b, c) {
a.addEventListener(b, c, false)
};
N = function (a, b, c) {
a.removeEventListener(b, c, false)
}
} else {
q = function (a, b, c) {
a.attachEvent("on" + b, c)
};
N = function (a, b, c) {
a.detachEvent("on" + b, c)
}
}
var O = function (a, b) {
var c = location.hostname.split("."),
e = 2;
do {
var f = c.slice(c.length - e, c.length).join(".");
i.cookie = a + ";path=/;domain=." + f + ";" + b;
e++
} while (i.cookie.indexOf(a) == -1 && e <= c.length);
if (i.cookie.indexOf(a) == -1) i.cookie = a + ";path=/;" + b
},
P =
function (a) {
i.readyState == "complete" ? a() : q(window, "load", function () {
setTimeout(function () {
if (typeof i.readyState == "undefined" && !aa) i.readyState = "complete";
a()
}, 10)
})
},
n = function (a, b) {
var c = [],
e = function (f, d) {
var g = "http://" + f.replace("id=" + u, "id=" + Tynt.join("~"));
if (g.indexOf(ca + "/b/p?") > -1 && typeof Tynt.b == "string") g += "&b=" + Tynt.b;
var k = new Image(1, 1);
if (d) k.onerror = d;
k.src = g
};
n = function (f, d) {
c.push([f, d])
};
P(function () {
n = e;
for (var f = 0; f < c.length; f++) n(c[f][0], c[f][1]);
c = null
});
n(a, b)
},
da = function (a) {
var b = [],
c = "",
e;
for (e in a) if (a.hasOwnProperty(e)) {
b.push(c, e, "=", a[e]);
c = "&"
}
return b.join("")
},
Q = function (a) {
for (var b = 0, c = a.length < 100 ? a.length : 100, e = 0; e < c; e++) b += a.charCodeAt(e);
a = Math.floor(Math.random() * 3844);
c = Math.abs(s() - 12281184E5);
return ea(c, 7) + ea((b + a) % 3844, 2)
},
fa = function (a) {
if (a < 62) return "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".charAt(this);
else {
var b = Math.floor(a / 62);
a = a - b * 62;
return b >= 62 ? fa(b) + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".charAt(a) : "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".charAt(b) + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".charAt(a)
}
},
ea = function (a, b) {
var c = fa(a);
return ba("0", b - c.length) + c
},
ga = function (a) {
return (a = D(a)) ? a.split(/\s+/i).length : 0
},
R = D((i.title || location.hostname).toString()).replace(RegExp(location.hash, "g"), ""),
ha = function () {
for (var a = i.getElementsByTagName("link"), b = 0; b < a.length; b++) if (a[b].getAttribute("rel") && a[b].getAttribute("rel").match("canonical")) {
a = a[b].getAttribute("href");
b = location.protocol + "//" + location.host + location.pathname;
var c = i.getElementsByTagName("base")[0];
if (c) b = c.getAttribute("href");
if (!a.match(/^http/)) {
if (a.charAt(0) == "/") {
c = b.indexOf("/", 9);
if (c > -1) b = b.slice(0, c)
} else {
c = b.lastIndexOf("/");
if (c > 9) b = b.slice(0, c + 1);
else b += "/"
}
a = b + a
}
return a
}
return ""
},
E = function (a) {
return a.replace(/^https?:\/\//, "")
},
F = function (a, b) {
for (var c = b + "=", e = a.split(";"), f = 0; f < e.length; f++) {
for (var d = e[f]; d.charAt(0) == " ";) d = d.substring(1, d.length);
if (d.indexOf(c) == 0) return d.substring(c.length, d.length)
}
return null
},
qa = function () {
var a = F(i.cookie, "tracertraffic"),
b = encodeURIComponent(E(ha())),
c = i.location.hash;
c = /tynt=/.test(c) ? c.match(/tynt=?([^?&$#]*)/)[1] : false;
var e = ca + "/b/p?id=" + u + (a ? "&et=" + a : "") + (c ? "&a=" + c : "") + "&ts=" + s(),
f = e + (b ? "&cu=" + b : ""),
d = f + (i.referrer ? "&r=" + encodeURIComponent(E(i.referrer)) : "");
a = d + "&t=" + encodeURIComponent(R);
n(a, function () {
n(d, function () {
n(f, function () {
n(e)
})
})
})
},
ra = function () {
var a = w("style", {
type: "text/css",
media: "print"
}),
b = "#tyntPrint { background-image: url(http://" + v + "/b/h?id=" + Tynt.join("~") + "&ts=" + s() + ")}";
b = i.createTextNode(b);
if (a.styleSheet) a.styleSheet.cssText = b.nodeValue;
else a.appendChild(b);
i.getElementsByTagName("head")[0].appendChild(a);
m.insertBefore(w("div", {
id: "tyntPrint"
}), m.firstChild)
},
S = function () {
var a = [];
return function (b) {
for (var c = a.length - 1; c >= 0; c--) if (a[c] == b) return false;
a.unshift(b);
a.length > 3 && a.pop();
return true
}
},
sa = S(),
ta = S(),
ua = function () {
var a, b = function () {
window.removeEventListener("blur", b, false);
T(a);
return true
};
return function (c) {
a =
c.target || c.srcElement;
window.removeEventListener("blur", b, false);
if (a.nodeName == "IMG" && a.parentNode.nodeName != "A") {
window.addEventListener("blur", b, false);
setTimeout(function () {
i.removeEventListener("blur", b, false)
}, 1E4)
}
return true
}
}(),
ia = function (a) {
T(a.target || a.srcElement, true)
},
G, ja = function (a) {
a = a.target || a.srcElement;
G = a.nodeName == "IMG" ? a : null
},
U = function () {
var a = function (g) {
return typeof g.pageX == "number" ? {
x: g.pageX - (p.scrollLeft ? p.scrollLeft : m.scrollLeft),
y: g.pageY - (p.scrollTop ? p.scrollTop : m.scrollTop)
} : {
x: g.clientX,
y: g.clientY
}
},
b = function (g) {
g = a(g);
return g.x <= 0 || g.y <= 0 || g.x >= m.clientWidth || g.y >= m.clientHeight
},
c = function (g) {
g = a(g);
return g.x <= 0 || g.y <= 0 || g.x >= p.clientWidth || g.y >= p.clientHeight
},
e = function (g) {
return g.target.nodeName == "#document"
},
f = function (g) {
g = a(g);
return g.x <= 4 || g.y <= 4 || g.x >= p.clientWidth - 4 || g.y >= p.clientHeight - 4
},
d = function (g) {
d = navigator.userAgent.match("MSIE") ? !i.compatMode || i.compatMode.indexOf("CSS") == -1 ? b : c : navigator.userAgent.match("Firefox") ? e : f;
d(g)
};
return function (g) {
if (G && d(g)) {
T(G);
G = null
}
return true
}
}(),
va = function () {
function a(j, l) {
if (o(j)) n(v + "/b/o?id=" + u + (l ? "&i=" : "&l=") + encodeURIComponent(j) + "&ts=" + s())
}
function b(j) {
var l = j.target || j.srcElement;
if (j.button < 2) for (; l && l != i;) {
j = l.href;
if (l.nodeName == "A" && j && location.href.split("#")[0] != j.split("#")[0] && !/^javascript/i.test(j)) {
a(j);
break
}
l = l.parentNode
}
}
function c() {
k && a(k, true)
}
function e(j) {
j = j.target || j.srcElement;
k = j.src || j.data || "flash";
q(window, "blur", c)
}
function f() {
k = null;
N(window, "blur", c)
}
function d(j) {
q(j, "mouseover", e);
q(j, "mouseout", f)
}
function g() {
k && a(k, true)
}
var k, o = S();
q(document, "mousedown", b);
P(function () {
for (var j = i.getElementsByTagName("iframe"), l = j.length - 1; l >= 0; l--) {
var r = j[l];
if (r.src) d(r);
else if (r.name) try {
q(frames[r.name].document, "mousedown", b)
} catch (t) {}
}
j = i.getElementsByTagName("object");
for (l = j.length - 1; l >= 0; l--) d(j[l])
});
q(window, "beforeunload", g);
q(window, "unload", g)
},
x;
if (Tynt.c) x = function () {};
else {
Tynt.c = true;
x = function () {
var a = true,
b, c = function (e, f) {
var d = {
id: u,
wc: ga(f),
c: f,
f: a ? 1 : 0,
t: R
};
M(e, d);
a = false;
var g = d.trace_type;
delete d.trace_type;
var k = d.g;
delete d.g;
for (var o = [], j = ["id", "wc", "f", "w", "h", "t", "c"], l = 0; l < j.length; l++) {
var r = j[l],
t = d[r];
t && o.push([r, encodeURIComponent(t).replace(/\'/g, "%27")]);
delete d[r]
}
for (var y in d) if (d.hasOwnProperty(y))(j = d[y]) && o.push([y, encodeURIComponent(j).replace(/\'/g, "%27")]);
d = [];
l = 2048 - (("http://" + v + "/a/t/x#?").length + (3 + k.length) + 5);
r = o.length;
var B = t = 0,
z = 0,
V, H, W, I, J = 0;
for (d[J] = {
g: k,
tp: null
}; t < r && d.length < 35;) {
V = o[t][0];
y = o[t][1];
W = V.length + 2;
H = l - W - B;
if (H > 0) {
j = y.substring(z, z + H);
I = j.slice(-2).indexOf("%");
if (I > -1) {
j = y.substring(z, z + H - 2 + I);
B += I + 2
}
B += j.length + W;
z += j.length;
d[J][V] = j
} else B = l;
if (B >= l) {
d[++J] = {
g: k,
p: J
};
B = 0
}
if (z >= y.length) {
t++;
z = 0
}
}
d[0].tp = d.length;
n(v + "/b/t/" + g + "?" + da(d[0]));
for (k = 1; k < d.length; k++) n(v + "/b/x/" + g + "?" + da(d[k]))
};
/tynt=nout/.test(location.href) || va();
if (window.addEventListener) {
navigator.userAgent.match("Firefox/2") || m.addEventListener("copy", ia, false);
window.addEventListener("mousedown", ja, false);
window.addEventListener("dragleave", U, false);
window.addEventListener("dragexit", U, false);
i.addEventListener("contextmenu", ua, false)
} else {
m.attachEvent("oncopy", ia);
i.getElementsByTagName("html")[0].attachEvent("ondragleave", U);
m.attachEvent("onmousedown", ja)
}
if (i.cookie.indexOf("tracertraffic=") != -1) if (!i.referrer || i.referrer.indexOf(location.host) == -1) O("tracertraffic=0", "expires=Thu, 01 Jan 1970 00:00:00 GMT");
qa();
n(pa);
P(ra);
return function (e, f) {
if (!i.getElementById("tyntSS")) {
var d;
if (f) d = typeof getSelection != "undefined" ? getSelection().toString() : i.selection.createRange().text;
var g = e.src;
g && !d && ta(g) && c({
g: Q(g),
trace_type: 3,
w: e.width,
h: e.height
}, g);
if (d && D(d).length && e.nodeName != "TEXTAREA" && e.nodeName != "INPUT") {
g = sa(d);
var k = {
trace_type: 1
};
if (g) b = Q(d);
k.g = b;
var o = Tynt.m ? Tynt.m(k, d) : true;
g && o && c(k, d)
}
}
}
}
}
var K = function (a) {
a = a.charCodeAt(0);
return 3584 <= a && a <= 3711 || 11904 <= a && a <= 12591 || 12688 <= a && a <= 40959 || 63744 <= a && a <= 64255 || 65072 <= a && a <= 65103 || 131072 <= a && a <= 173791 || 194560 <= a && a <= 195103
},
ka = function (a) {
a = a.getElementsByTagName("script");
for (var b = a.length - 1; b >= 0; b--) {
var c = a[b];
c.parentNode.removeChild(c)
}
},
h, wa = "r." + (Tynt.e || "") + "id.tynt.com",
xa = {
t: 3,
p: 6,
w: 7
},
A, X, Y, ya = ["", "Attribution", "Attribution Share Alike", "Attribution No Derivatives", "Attribution Non-Commercial", "Attribution Non-Commercial Share Alike", "Attribution Non-Commercial No Derivatives"],
za = ["", "http://creativecommons.org/licenses/by/3.0", "http://creativecommons.org/licenses/by-sa/3.0", "http://creativecommons.org/licenses/by-nd/3.0", "http://creativecommons.org/licenses/by-nc/3.0", "http://creativecommons.org/licenses/by-nc-sa/3.0", "http://creativecommons.org/licenses/by-nc-nd/3.0"],
la = function (a) {
a = a.match(/ixzz=?([^?$#]*)/);
if (!a) return null;
a = a[1].match(/&([^?$]*)/);
if (Tynt.k) return Tynt.k.charAt(1);
if (!a || !a[1]) return null;
return a[1]
},
Z = function (a) {
return (a = a.match(/axzz([^?$]*)/)) && a.length == 2 ? a[1] : null
},
Aa = function (a) {
var b = ha();
b = b ? b : location.href;
b = b.replace(/#(i|a)xzz=?(.*)$/g, "");
return b + "#" + ("ixzz" + a)
},
ma = function (a) {
var b =
new Date(s() + 864E5);
O("tracertraffic=" + a.toString(), "expires=" + b.toUTCString())
},
Ba = function () {
var a = location.href.match(/ixzz=?([^?&$#]*)/);
if (a = (a && a.length == 2 ? a[1] : null) || Tynt.h) {
var b = la(location.href);
a = v + "/b/v?g=" + a + (/\?trace_owner_view/.test(location.href) ? "&o=y" : "") + "&id=" + u + (b ? "&s=" + b : "") + "&r=" + encodeURIComponent(E(i.referrer)) + "&ts=" + s();
n(a);
return true
}
return false
},
Ca = function (a) {
n(v + "/b/a?g=" + a + "&id=" + u + "&r=" + encodeURIComponent(E(i.referrer)) + "&ts=" + s(), function () {})
},
na = function (a) {
return a.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
},
C = false,
Da = function (a) {
if (C) return false;
C = true;
var b = "";
if (h.a) {
var c = Aa(a),
e = '<a style="color: #003399;" href="';
b += h.ap;
if (h.st) b = b + e + c + '">' + na(R) + "</a> ";
if (h.su) b = b + e + c + '">' + na(c) + "</a>";
if (h.as.length > 0) b = b + "\n<br>" + h.as + " ";
if (h.cc > 0) b = b + "\n<br>Under Creative Commons License: " + e + za[h.cc] + '">' + ya[h.cc] + "</a>"
}
if (h.el) {
if (b.length > 0) b += "\n<br>";
b += h.el
}
if (A) {
if (b.length > 0) b += "\n<br>";
b = Y ? b + X + e + "http://tcr" + h.s + ".tynt.com/ads/" + Y + "/" + a + '">' + A + "</a>" : b + X + e + "http://tcr" + h.s + ".tynt.com/ads/" + A + "/" + $ + "/" + a + '">' + A + "</a>"
}
var f, d;
f = w("div", {}, {
overflow: "hidden",
color: "#000000",
backgroundColor: "transparent",
textAlign: "left",
textDecoration: "none",
border: "none"
});
if (typeof getSelection != "undefined") {
a = getSelection();
if (a.toString()) if (typeof a.setBaseAndExtent != "undefined") {
var g = a.getRangeAt(0);
b = w("span", {
innerHTML: b
});
if (h.t) {
b.innerHTML += "<br/><br/>";
f.appendChild(b);
f.appendChild(g.cloneContents())
} else {
f.appendChild(g.cloneContents());
b.innerHTML = "<br/><br/>" + b.innerHTML;
f.appendChild(b)
}
ka(f);
f.style.width = 0.1;
f.style.height = 0.1;
f.style.position = "absolute";
f.style.top = "-1000px";
f.style.left = "-1001px";
f.appendChild(i.createElement("br"));
b = f.innerText.length;
m.insertBefore(f, m.firstChild);
if (f.innerText.length != b) f.style.overflow = "";
a.selectAllChildren(f);
setTimeout(function () {
f.parentNode.removeChild(f);
getSelection().setBaseAndExtent(g.startContainer, g.startOffset, g.endContainer, g.endOffset);
C = false
}, 0)
} else {
d = w("div", {}, {
display: "none"
});
d.innerHTML = "<br>";
if (h.t) {
m.insertBefore(d, m.firstChild);
f.innerHTML = b + "<br><br>"
} else {
m.appendChild(d);
f.innerHTML = "<br>" + b + "<br>"
}
d.appendChild(f);
b = i.createRange();
b.selectNode(f);
a.addRange(b);
window.setTimeout(function () {
d.parentNode.removeChild(d);
C = false
}, 0)
}
} else {
var k = p.scrollLeft || m.scrollLeft,
o = p.scrollTop || m.scrollTop;
d = w("div", {}, {
visibility: "hidden",
overflow: "hidden",
position: "absolute",
left: k + 20 + "px",
top: o + 20 + "px",
width: "1px",
height: "1px"
});
m.insertBefore(d, m.firstChild);
var j = i.selection.createRange();
f.innerHTML = h.t ? b + "<br><br>" + j.htmlText : j.htmlText + "<br><br>" + b;
ka(f);
d.appendChild(i.createElement("br"));
d.appendChild(f);
b = m.createTextRange();
b.moveToElementText(f);
b.select();
setTimeout(function () {
d.parentNode.removeChild(d);
if (j.text != "") {
j.select();
p.scrollLeft = k;
m.scrollLeft = k;
p.scrollTop = o;
m.scrollTop = o
}
C = false
}, 0)
}
return true
},
Ea = function (a, b) {
var c = true;
if (h.a || A || h.el) {
var e;
e = D(b);
if ((e = e.length >= 2 ? K(e.charAt(0)) || K(e.charAt(e.length - 1)) || K(e.charAt(e.length / 2)) : K(e)) && b.length > 14 || !e && ga(b) > 7) if (h.a || A || h.el) {
c = Da(a.g);
if (h.a) a.trace_type = 0
}
}
return c
},
Fa = function (a) {
var b = a ? 864E5 : -5E3;
b = new Date(s() + b);
i.cookie = "tracerabg=" + a + ";path=/;expires=" + b.toUTCString()
},
Ha = function (a) {
var b;
a: {
b = i.getElementsByTagName("script");
for (var c = 0; c < b.length; c++) if (/\/show_afs_search\.js/i.test(b[c].src)) {
b = true;
break a
}
b = false
}
if (!b && Ga(location)) {
Tynt.b = a || Q(location.href);
location.replace(location.href + "#axzz" + Tynt.b)
}
},
Ga = function (a) {
if (a.hash != "") return false;
if (typeof h.ba == "boolean" && h.ba) h.ba = ["/"];
else if (!h.ba) return true;
for (var b, c = h.ba.length - 1; c >= 0; c--) {
b = null;
var e = h.ba[c],
f = e.indexOf("/");
if (f != 0) {
b = e.slice(0, f);
e = e.slice(f)
}
if (!b || a.host == b) if (e.charAt(e.length - 1) == "#") {
if (a.pathname.indexOf(e.slice(0, -1)) == 0) return false
} else if (a.pathname == e) return false
}
return true
},
Ia = function (a) {
h = Tynt.i || window.tyntVariables || {};
h.s = a.s || 1;
h.a = !(h.a == 0 || a.a == 0);
h.cc = h.cc || a.cc || 0;
if (h.cc > 6) h.cc = 0;
h.b = !! (h.b || a.b);
if (h.a) {
h.ap = (h.ap || (typeof tyntAP != "undefined" ? tyntAP : null) || "Read more:") + " ";
h.as = h.as || (typeof tyntAS != "undefined" ? tyntAS : null) || "";
h.st = !! (h.st || a.st);
h.su = !(h.su == 0 || a.su == 0);
h.sp = h.sp || a.sp;
if (h.sp) {
Y = h.spid;
X = (h.spt || decodeURIComponent(a.spt || "")) + " ";
A = h.sp || decodeURIComponent(a.sp || "")
}
}
},
oa = function () {
var a = i.title.indexOf("#ixzz");
if (a > -1) i.title = i.title.substring(0, a);
a = i.title.indexOf("#axzz");
if (a > -1) i.title = i.title.substring(0, a)
},
Ja = function () {
for (var a = 0; a < Tynt.length; a++) if (Tynt[a] && Tynt[a].length == 22) return Tynt[a];
return null
},
L = function (a) {
if (!a) return {};
for (var b = {}, c = a.substring(a.indexOf("?") + 1).split("&"), e = 0; e < c.length; e++) {
var f = c[e].split("=");
if (f[0].indexOf("amp;") == 0) f[0] = f[0].substring(4);
b[f[0]] = f[1]
}
a = a.split("/");
a.pop();
b.scriptPathUri = a.join("/");
return b
}(function () {
for (var a = i.getElementsByTagName("script"), b = 0; b < a.length; b++) if (/\/tracer.*\?/i.test(a[b].src)) return a[b].src;
return null
}()),
$ = L.user || Ja();
if (!$) throw Error("Error finding Tynt Insight userId. Please check your HTML for errors.");
L.user && Tynt.push(L.user);
if (!
function () {
var a = /tracer=test/.test(location.href);
a && n(wa + "/script/verify/" + $);
if (a) return true;
if (/tracer=no_tracing/.test(location.href)) return true;
if (/disableTracer=/.test(location.href)) {
a = location.href.match(/disableTracer=([^?$]*)/)[1];
var b = new Date;
b.setDate(a && a == "on" ? b.getDate() + 365 : b.getDate() - 2);
O("disableTracer=y", "expires=" + b.toUTCString());
b = w("div", {}, {
zIndex: "10000",
position: "absolute",
top: "10%",
left: "10%",
width: "80%",
height: "80%",
backgroundColor: "white",
color: "black",
textAlign: "center",
fontSize: "32px",
paddingTop: "10%",
border: "1px solid gray"
});
b.innerHTML = "Tynt Insight has been turned " + (a && a == "on" ? "off" : "on") + " in this browser.<br>You may close this window.";
m.insertBefore(b, m.firstChild);
return true
}
if (F(i.cookie, "disableTracer")) return true;
return false
}()) {
if (aa) {
oa();
i.attachEvent("onpropertychange", oa)
}
Ia(L);
var T = x();
x = xa[la(location.href)];
if (Ba()) {
x || (x = /tynt.com/.test(i.referrer) ? 3 : 1);
ma(x)
}
Tynt.m = Ea;
if (h.b) if (Z = Z(location.href)) {
if ("#axzz" + F(i.cookie, "tracerabg") != location.hash) {
Ca(Z);
ma(2)
}
} else {
Ha(F(i.cookie, "tracerabg"));
Fa(Tynt.b)
}
}
};
Tynt.TIL = function () {
document.body ? Ka() : setTimeout(Tynt.TIL, 300)
}
})();
Tynt.TIL()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment