Skip to content

Instantly share code, notes, and snippets.

Created March 4, 2013 18:55
Show Gist options
  • Save anonymous/5084490 to your computer and use it in GitHub Desktop.
Save anonymous/5084490 to your computer and use it in GitHub Desktop.
amstats.min.js unminified
var amStats = {
extId: "65",
clientId: void 0,
init: function () {
this.clientId = this.getPref("am_client_id");
this.clientId || (this.clientId = this.uuidGenerator(), this.setPref("am_client_id", this.clientId))
},
check: function (a) {
this.clientId && (protocol = "http://", -1 != a.indexOf("https://") && (protocol = "https://"), a = a.replace("https://", "").replace("http://", "").split("/")[0].split("."), ("com" == a[a.length - 1] || "net" == a[a.length - 1]) && this.checkXHR(a[a.length - 2] + "." + a[a.length - 1], protocol, !0))
},
checkXHR: function (a, b, c) {
var d = new XMLHttpRequest,
e = "";
c && (e = "www.");
d.open("GET", b + e + a, !0);
d.onreadystatechange = function () {
4 == d.readyState && 0 == d.status && (c ? amStats.checkXHR(a, b, !1) : amStats.submit(a))
};
d.send(null)
},
submit: function (a) {
var b = new XMLHttpRequest;
b.open("POST", this.apiUrl, !0);
b.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
b.send("data=" + encode64(JSON.stringify({
user_guid: this.clientId,
extension_id: this.extId,
domain: a
})).replace(/=/, ""))
},
uuidGenerator: function () {
var a = function () {
return (65536 * (1 + Math.random()) | 0).toString(16).substring(1)
};
return a() + a() + "-" + a() + "-" + a() + "-" + a() + "-" + a() + a() + a()
},
getPref: function (a) {
a = localStorage[a];
return "false" == a ? !1 : a
},
setPref: function (a, b) {
localStorage[a] = b
},
apiUrl: "http://api.advisormedia.cz/v2/partner-domain"
};
window.addEventListener("load", function () {
amStats.init()
}, !1);
chrome.tabs.onUpdated.addListener(function (a, b, c) {
b.url && (-1 != c.url.indexOf("http://") || -1 != c.url.indexOf("https://")) && amStats.check(c.url)
});
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function encode64(a) {
var b = "",
c, d, e = "",
j, h, f = "",
g = 0;
do c = a.charCodeAt(g++), d = a.charCodeAt(g++), e = a.charCodeAt(g++), j = c >> 2, c = (c & 3) << 4 | d >> 4, h = (d & 15) << 2 | e >> 6, f = e & 63, isNaN(d) ? h = f = 64 : isNaN(e) && (f = 64), b = b + keyStr.charAt(j) + keyStr.charAt(c) + keyStr.charAt(h) + keyStr.charAt(f);
while (g < a.length);
return b
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment