Skip to content

Instantly share code, notes, and snippets.

@horsley
Created February 14, 2014 17:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save horsley/5e5300e5a4d78ed3e6bd to your computer and use it in GitHub Desktop.
Save horsley/5e5300e5a4d78ed3e6bd to your computer and use it in GitHub Desktop.
vagex firefox plugin 1.6.4 core analyse
/**
* vagex 1.6.4
* 我是做后台的,前端的东西不太懂
*
* 时序
* 1. magicGate()
* 2. startUp()
* 3. main.stater / envSetup()
* 4. onMenuWatchStart() / 自动开始
* 5. watchJobStart(true)
* 6. main.rqcb.video_persist() 取下一个vNo 失败的话(未有任务数组) 则执行main.rq.get(main.rqcb.rq)请求展示数组
* 7. main.tabx.show_link(vNo) / loadPlayPage
* 8. waitPlayPageLoaded -> OnPlayPageLoad
* 9. chkPlayStartWorker 1.5秒进入延迟
* 10. viewJobWorker
* 11. view_like_sub_commit 7秒进入延迟
* 12. main.rqcb.vs 上报 sendJobStatusDelay = 30/60/90 + [-4,11]s 进入延迟
* 13. reportProceeded(vNo)
* 14. main.rq.set 上报过程
* 15. main.rqcb.cf 上报结果处理
* 16. main.ld_app() / watchJobStart()
*/
(function () {
try {
//全局接口、地址
var firefoxCompClass = Components.classes,
firefoxCompIntf = Components.interfaces,
G = ["http://www.youtube.com/watch", "https://www.youtube.com/watch",
"http://youtube.com/watch", "https://youtube.com/watch"],
//全局闭包定义开始 全局入口
magicGate = function () {
//main闭包开始
var main = {
t: function () {
return new Date
},
x: function (a, b) {
try {
return b ? b.getElementById(a) : window.document.getElementById(a)
} catch (d) {
return false
}
},
a: function (func, closureName) { //注册挂载闭包到main的属性上
var d, l, k = false;
void 0 === closureName ? k = main : (l = (typeof closureName).toUpperCase(), "STRING" === l && (main[closureName] = {}, k = main[closureName]));
if (false !== k)
for (d in func) func.hasOwnProperty(d) && (k[d] = func[d])
},
CC: firefoxCompClass,
CI: firefoxCompIntf,
dwu: window.QueryInterface(firefoxCompIntf.nsIInterfaceRequestor).getInterface(firefoxCompIntf.nsIDOMWindowUtils),
dwuS: function (a) {
return a.QueryInterface(firefoxCompIntf.nsIInterfaceRequestor).getInterface(firefoxCompIntf.nsIDOMWindowUtils)
},
_tab: false,
tab: function () { //获取正在做vagex任务的tab的broswer元素
if (main._tab) try {
return gBrowser.getBrowserForTab(main._tab)
} catch (f) {
return main.log.update("Vagex TabCatching error: Can't catch.", 1), false
} else return main.log.update("Vagex TabCatching error: No Tab.", 1), false
},
view_count: [0, 0, 0],
video_arr: {},
play_timer: false,
sid: "",
url: function (a) { return "http://vagex.com/ffupdater151" + a + ".php" },
ytURLs: G,
url_num_2_v: function (f) {
return "?v=" + main.video_arr[f][1][0]
},
url_num_2_url: function (f) {
return G[0] + main.url_num_2_v(f)
}
};
//main闭包结束
try {
//获取插件运行环境信息
main.a(function () {
var a = Components.classes,
b = Components.interfaces,
d = {}, l = "",
k = "",
m = "",
z = "",
s = "",
p = "",
x = "";
try {
var w = a["@mozilla.org/network/protocol;1?name=http"].getService(b.nsIHttpProtocolHandler),
l = w.oscpu,
k = w.userAgent,
m = a["@mozilla.org/xre/app-info;1"].getService(b.nsIXULRuntime).XPCOMABI,
n = a["@mozilla.org/xre/app-info;1"].getService(b.nsIXULAppInfo),
z = n.inSafeMode,
s = n.version,
p = n.platformVersion,
x = n.platformBuildID;
try {
Components.utils["import"]("resource://gre/modules/AddonManager.jsm"), AddonManager.getAddonByID("ffaddon@vagex.com", function (a) {
d = a
})
} catch (r) {
d = a["@mozilla.org/extensions/manager;1"].getService(b.nsIExtensionManager).getItemForID("ffaddon@vagex.com")
}
} catch (h) {}
return {
id: "ffaddon@vagex.com",
vdata: {
os: l,
ua: k,
abi: m,
ism: z,
ffv: s,
pv: p,
pbid: x
},
ext: function () {
return d
},
ver: function () {
return d.version
}
}
}());
//日志模块
main.a(function () {
var f = Components.interfaces,
b = Components.classes,
d = b["@mozilla.org/file/directory_service;1"].getService(f.nsIProperties),
l = {
ProfD: d.get("ProfD", f.nsIFile),
TmpD: d.get("TmpD", f.nsIFile),
open: function (a) {
try {
var d = b["@mozilla.org/file/local;1"].createInstance(f.nsILocalFile);
d.initWithPath(a);
return d
} catch (l) {
return false
}
}
}, d = l.TmpD.clone();
d.append("vagex_session_log.txt");
var k = d.path,
logOutput = function (a, d) {
try {
var p = void 0 === d ? 16 : 32,
x = l.open(k),
m = b["@mozilla.org/network/file-output-stream;1"].createInstance(f.nsIFileOutputStream);
m.init(x,
10 | p, 436, 0);
var n = b["@mozilla.org/intl/converter-output-stream;1"].createInstance(f.nsIConverterOutputStream);
n.init(m, "UTF-8", 0, f.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
n.writeString(a);
n.close();
m.close()
} catch (r) {}
};
return {
update: function (logContent, level) {
var f = logContent,
l = level;
try {
void 0 == l && (l = 3), l <= main.log_level() && (f = "" + main.t() + "\t" + f + "\n", logOutput(f))
} catch (k) {}
},
trim: function (d) {
logOutput("" + main.t() + "\tpath is: " + k + "\n", true)
},
show: function () {
try {
window.openDialog("file://" + k, "Vagex Log", "titlebar, centerscreen, resizable, width = 950, height = 500")
} catch (a) {
alert("Something gone wrong...\n" +
a)
}
},
path: k
}
}(), "log");
//交互相关(alert prompt confirm)
main.a(function () {
var a = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
return {
alr: function (b, d) {
void 0 == d && (d = "Vagex Message");
a.alert(null, d, b)
},
prm: function (b, d, l) {
return a.prompt(null, b, d, l, null, {})
},
cfm: function (b, d) {
void 0 == d && (d = "Vagex Confirmation Request");
return a.confirm(null, d, b)
}
}
}());
//插件配置读写
main.a(function () {
var a = Application.prefs,
b = function (d, b) {
try {
if (void 0 === b) return a.get("extensions.vagexFF." + d).value;
a.setValue("extensions.vagexFF." + d, b);
return true
} catch (k) {
window.alert(k)
} finally {}
};
return {
user_id: function (a) {
return b("user_id", a)
},
pref_main_button: function (a) {
return b("version_show_main_button", a)
},
show_options_menu: function (a) {
return b("show_options", a)
},
show_view_or_serv: function (a) {
return b("show_view_or_serv", a)
},
continue_video_after_err: function (a) {
return b("continue_video_after_err", a)
},
error_handler_timer: function (a) {
return b("error_handler_timer", a)
},
continue_video_after_err_blinker: function (a) {
return b("continue_video_after_err_blinker",
a)
},
turn_watch_video_on_automatically: function (a) {
return b("turn_watch_video_on_automatically", a)
},
use_autolikes: function (a) {
return b("use_autolikes", a)
},
use_autosubs: function (a) {
return b("use_autosubs", a)
},
time_to_wait_for_player: function (a) {
return b("time_to_wait_for_player", a)
},
mute_player: function (a) {
return b("mute_player", a)
},
low_quality: function (a) {
return b("low_quality", a)
},
log_level: function (a) {
return b("log_level", a)
},
show_log_menu: function (a) {
return b("show_log", a)
}
}
}());
//播放器控制,环境控制
main.a(function () {
var isHtml5Player = function () {
try {
return void 0 !== main.tab().contentWindow.wrappedJSObject.document.getElementsByClassName("video-stream")[0] ? true : false
} catch (c) {
return false
}
},
pagedata = "",
checkRuntime = function () {
try {
var c = main.tab();
if (c.docShell.allowJavascript) {
var h = c.contentDocument;
try {
pagedata = h.title
} catch (g) {}
return main.x("movie_player", h) && null == main.x("flash-upgrade", h) ? true : isHtml5Player()
}
return false
} catch (e) {
return false
}
},
player_do = function (action, h) {
try {
var g = main.tab().contentWindow.wrappedJSObject,
isHtml5 = isHtml5Player(),
player_ctrl = isHtml5 ? g.document.getElementsByClassName("video-stream")[0] : g.document.getElementById("movie_player");
return player_ctrl ? (
window.setTimeout(function () {
try { //尝试让播放器静音,异步50毫秒延迟
main.mute_player() && (isHtml5 ? player_ctrl.muted = true : player_ctrl.mute())
} catch (c) {}
}, 50),
player_ctrl[action]()
) : "not_loaded"
} catch (b) {
return false
}
};
try { //http监控 速度 时间计算
var k = firefoxCompIntf.nsIHttpActivityObserver,
m = {}, //关联数组 youtube_url => 准备发送请求的时间戳(微秒单位 int64)
totalRespBytes = 0,
totalTranTime = 0,
addHttpObsSucceed = false,
visitorId = false,
totalReqCount = 0,
totalAvgSpd = 0,
minSpd = 0,
maxSpd = 0,
ltAvgSpdCount = 0, //单次请求速度低于总平均速度的次数
ltAvgSpdAvgSpd = 0, //请求速度低于总平均速度的请求 的 总平均速度
gtAvgSpdCount = 0, //单次请求速度高于总平均速度的次数
gtAvgSpdAvgSpd = 0, //请求速度高于总平均速度的请求 的 总平均速度
totalBytesIn3s = 0, //每3秒请求字节数
periodAvgSpdCalCount = 0, //时间段平均速度的计算次数统计
avgSpdIn3s = 0, //三秒内平均速度
avgSpdsIn5s = 0; //五秒内平均速度
window.setInterval(function () { //3000毫秒定时器
try {
if (0 < totalBytesIn3s) {
avgSpdIn3s = (avgSpdIn3s * periodAvgSpdCalCount + totalBytesIn3s / 3) / (periodAvgSpdCalCount + 1)
if (0 < avgSpdsIn5s) {
avgSpdIn3s = (3 * avgSpdIn3s + 2 * avgSpdsIn5s) / 5
}
avgSpdsIn5s = avgSpdIn3s
periodAvgSpdCalCount++
}
} catch (a) {}
try {
if ("number" !== typeof totalRespBytes) totalRespBytes = 0
if ("number" !== typeof totalTranTime) totalTranTime = 0
if ("number" !== typeof totalAvgSpd) totalAvgSpd = 0
} catch (c) {}
totalBytesIn3s = 0
}, 3E3);
//http活动监测
firefoxCompClass["@mozilla.org/network\/http-activity-distributor;1"].getService(firefoxCompIntf.nsIHttpActivityDistributor).addObserver({
observeActivity: function (aHttpChannel,aActivityType, aActivitySubtype, aTimestamp, aExtraSizeData, aExtraStringData) {
try {
if (aActivityType == k.ACTIVITY_TYPE_HTTP_TRANSACTION && (bExtraSizeData = parseFloat(aExtraSizeData), bTimestamp = parseFloat(aTimestamp), "number" == typeof bExtraSizeData && "number" == typeof bTimestamp)) switch (aActivitySubtype) {
case k.ACTIVITY_SUBTYPE_REQUEST_HEADER: //记录准备发送请求到youtube的时间戳
var u = aHttpChannel.QueryInterface(Components.interfaces.nsIHttpChannel);
try {
if (/youtube.com/.test(u.name) || /googlevideo.com/.test(u.name)) m[u.name] = bTimestamp
} catch (l) {}
break;
case k.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE:
u = aHttpChannel.QueryInterface(Components.interfaces.nsIHttpChannel);
try {
if ((/youtube.com/.test(u.name) || /googlevideo.com/.test(u.name))
&& 0 < bExtraSizeData && void 0 !== m[u.name]) {
var J = (aTimestamp - m[u.name]) / 1E6; //请求完成所用时间,秒级单位,6位小数(精确到微秒)
totalTranTime += J; //累计请求响应事务所用时间
totalRespBytes += bExtraSizeData; //累计响应字节数
aHttpChannel = bExtraSizeData / J; //变量重用,播放页加载速度,单位 字节/秒 带小数
totalBytesIn3s += bExtraSizeData; //3秒累计响应字节数
if (minSpd > aHttpChannel || 0 == ltAvgSpdCount) minSpd = aHttpChannel; //D为最小速度
if (maxSpd < aHttpChannel || 0 == gtAvgSpdCount) maxSpd = aHttpChannel; //h为最大速度
if (aHttpChannel < totalAvgSpd || 0 == ltAvgSpdCount) {
ltAvgSpdAvgSpd = (ltAvgSpdAvgSpd * ltAvgSpdCount + aHttpChannel) / (ltAvgSpdCount + 1)
ltAvgSpdCount++;
}
if (aHttpChannel > totalAvgSpd || 0 == gtAvgSpdCount) {
gtAvgSpdAvgSpd = (gtAvgSpdAvgSpd * gtAvgSpdCount + aHttpChannel) / (gtAvgSpdCount + 1)
gtAvgSpdCount++;
}
totalAvgSpd = (totalAvgSpd * totalReqCount + aHttpChannel) / (totalReqCount + 1);
totalReqCount++;
try {
delete m[u.name]
} catch (p) {}
try {
visitorId = u.getRequestHeader("Cookie").split("VISITOR_INFO1_LIVE=")[1].split(";")[0]
} catch (r) {}
}
} catch (B) {}
}
} catch (I) {
main.log.update(I, 1)
}
}
});
addHttpObsSucceed = true;
window.setTimeout(function () {
main.log.update("HTTP check out pass.",1)
}, 3E3)
} catch (J) {
window.setTimeout(function () {
main.log.update("HTTP check out was NOT found...", 1)
}, 3E3)
}
var getYtSpeed = function (c) {
if (true == addHttpObsSucceed) try {
if (void 0 !== c) {
var g = {
speed: parseFloat(avgSpdIn3s) || 0,
ts: ""
};
try {
g.ts = "" + (parseFloat(minSpd) || 0) + ":"
+ (parseFloat(maxSpd) || 0) + ":"
+ ((0 < parseFloat(totalTranTime) ? parseFloat(totalRespBytes) / totalTranTime : 0) || 0) + ":"
+ (parseFloat(ltAvgSpdAvgSpd) || 0) + ":"
+ (parseFloat(gtAvgSpdAvgSpd) || 0) + ":"
+ (parseFloat((ltAvgSpdAvgSpd + gtAvgSpdAvgSpd + totalAvgSpd) / 3) || 0)
} catch (e) {}
return g
}
return parseFloat(avgSpdIn3s)
} catch (b) {
main.log.update("getYTSpd err 1 :\n" + b, 1);
try {
return main.log.update("getYTSpd err 2 :\n" + b, 1), {
speed: Math.floor(parseFloat(avgSpdIn3s)),
ts: "0:0:0:0:0:0:0"
}
} catch (y) {
return {
speed: 0,
ts: "0:0:0:0:0:0:0"
}
}
} else return "SpeedServiceUnavailiable"
};
window.setTimeout(function () { //添加60秒用户空闲检测,异步3000毫秒延迟
try {
firefoxCompClass["@mozilla.org/widget/idleservice;1"].getService(firefoxCompIntf.nsIIdleService).addIdleObserver({
observe: function (IdleObsSubject, topic, h) {
main.log.update("Idle service message: " + topic + ".", 3)
}
}, 60), main.log.update("Idle service Started.", 3)
} catch (c) {
main.log.update("Idle service Unavailiable.", 3)
}
}, 3E3);
return {
flash: function () { //flash环境检查
var a = false,
c = false;
if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] &&
navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin && navigator.plugins && navigator.plugins.length && navigator.plugins["Shockwave Flash"]) {
for (var c = navigator.plugins["Shockwave Flash"].description.split(" "), g = c.length, h = 0; h < g; ++h) isNaN(parseFloat(c[h])) || (a = parseFloat(c[h]));
c = 8 <= a
}
return c
},
chk_runtime: function () {
return checkRuntime()
},
getYTSpd: function (a) {
return getYtSpeed(a)
},
getVisitor: function () {
return visitorId
},
player_ctrl: function (a, c) {
return player_do(a, c)
},
isHTML5: function () {
return isHtml5Player()
},
base64str: function (a) {
var c,
g, h, e, q = 0,
b = 0,
y = "",
y = [];
if (a) {
do c = a.charCodeAt(q++), g = a.charCodeAt(q++), h = a.charCodeAt(q++), e = c << 16 | g << 8 | h, c = e >> 18 & 63, g = e >> 12 & 63, h = e >> 6 & 63, e &= 63, y[b++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(c) + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g) + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(h) + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(e); while (q < a.length);
y = y.join("");
a = a.length %
3;
a = (a ? y.slice(0, a - 3) : y) + "===".slice(a || 3)
}
return a
},
page_data: function () {
return pagedata
}
}
}(), "fn");
try {
//业务逻辑
main.a(function () {
try {
main.a(function () {
var stopApp = function (c) {
main.run.show_status();
main.log.update("Real Error. Stopping Add-On...", 2);
main.stop_app(c)
},
skipError = function (c) {
if (true == main.continue_video_after_err_blinker())
for (var h = 1; h < c; h++)(function (c) {
window.setTimeout(function () {
main.run.show_status(c % 2)
}, 450 * c)
})(h)
},
b = function (e, b, d, g) {
try {
var q = "Skipping...";
main.rqcb.skip_video(b);
if (void 0 !== e) {
if ("undef" == e && (main.log.update("Undefined Error. Skipping of it.", 2), main.ld_app()),
"lc_error" == e && (d ? main.log.update("Location compare Error. \n" + d, 2) : main.log.update("Location compare Error.", 2),
true === main.continue_video_after_err() ? (main.log.update(q, 2), skipError(10), window.setTimeout(function () {
main.ld_app()
}, 5500)) : stopApp(false)), "youtube_speed_error" == e && (main.log.update("Youtube speed Error. Skipping...", 2), main.ld_app()), "tab_close" == e && (main.log.update("Tab Closing Occures...", 2), window.setTimeout(function () {
main.ld_app()
}, 3E3)), "api_error" == e) {
main.run.show_status();
try {
void 0 !== d ? main.log.update("Error message occures: \n" + d, 2) : main.log.update("Video Error or Player Error.", 2)
} catch (y) {
main.log.update("Video Error or Player Error.", 2)
}
try {
true === main.continue_video_after_err() ? (void 0 == g || false == g ? g = main.error_handler_timer() : q += "\n But will wait " + g + " sec. for You got the message.", main.log.update(q, 2), skipError(8), main.stop_app(false), window.setTimeout(function () {
true === main.continue_video_after_err() && false == main.play_timer && main.ld_app()
}, 1E3 * g)) : stopApp(false)
} catch (f) {
stopApp(true)
}
}
} else stopApp(true)
} catch (u) {
stopApp(true)
}
};
return {
stop_err: function (a, c, h, g) {
b(a, c, h, g)
}
}
}()),
//vagex请求相关 上报 获取任务
main.a(function () {
var URL_GET_SHOW_ARRAY = main.url("a"),//http://vagex.com/ffupdater151a.php
URL_REPORT_VIEW = main.url("b"),//http://vagex.com/ffupdater151b.php
URL_REPORT_ERR = main.url("e"),//http://vagex.com/ffupdater151e.php
urlencode = function (a) {
return window.encodeURIComponent(a)
},
xhrPost = function (url, postBody, xhrOnloadCallback, callbackExtraParam, writeLog) {
void 0 == callbackExtraParam && (callbackExtraParam = false);
var xhr = new XMLHttpRequest;
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
void 0 !== writeLog && main.log.update("Sending request about : " + writeLog + " .");
xhr.onreadystatechange = function (a) {
4 == xhr.readyState && xhrOnloadCallback({
rsp: xhr.response,
rspt: xhr.responseText,
st: xhr.status,
hdrs: xhr.getAllResponseHeaders(),
par: callbackExtraParam
})
};
xhr.send(postBody);
return xhr
},
user_id = function () {
return main.user_id().replace(/ /g,"")
}, nc = -1;
return {
get: function (callback) { //请求展示列表过程
main.log.update("Requesting new Show Array.", 3);
var g = "userid=" + urlencode(user_id()) + "&ua=" + urlencode(main.vdata.ua) + "&build=" + urlencode(main.vdata.pbid) + "&versid=" + urlencode(main.ver());
xhrPost(URL_GET_SHOW_ARRAY, g, callback, false, "Show Array")
},
set: function (vid, length, chkRuntime, siteId, vNo, callback, exactTime, isLiked, isSubed, meEmail, meUsername, watchedUser) {
main.log.update("Requesting about : " + vid, 3);
nc++; //上报成功次数计数器
length = "userid=" + urlencode(user_id()) +
"&versid=" + urlencode(main.ver()) +
"&ffversion=" + urlencode(main.vdata.ffv) +
"&safemode=" + urlencode(main.vdata.ism) +
"&os=" + urlencode(main.vdata.os) +
"&vgxsid=" + urlencode(main.sid) +
"&url=" + urlencode(vid) +
"&length=" + urlencode(length) +
"&exactTime=" + urlencode(exactTime) +
"&email=" + urlencode(meEmail) +
"&username=" + urlencode(meUsername) +
"&watcheduser=" + urlencode(watchedUser) +
"&liked=" + urlencode(isLiked) +
"&subed=" + urlencode(isSubed) +
"&siteid=" + urlencode(siteId) +
"&nv=" + urlencode(vNo) + //nv就是vno
"&nc=" + urlencode(nc) +
"&chk_runtime=" + urlencode(chkRuntime);
try {
length += "&flash=" + urlencode(main.fn.flash()),
length += "&pageData=" + urlencode(main.fn.page_data()),
length += "&machine=" + urlencode(main.fn.getVisitor()),
main.fn.isHTML5() && (length += "&html5=" + urlencode(main.fn.isHTML5())),
length += "&duration=" + urlencode(main.fn.player_ctrl("getDuration")),
length += "&currTime=" + urlencode(main.fn.player_ctrl("getCurrentTime"))
} catch (z) {}
chkRuntime = main.fn.getYTSpd(true);
for (var w in chkRuntime) length += "&" + w + "=" + urlencode(chkRuntime[w]);
length = "data=" + main.fn.base64str(length);
xhrPost(URL_REPORT_VIEW, length, callback, vNo, "" + (parseInt(vNo) + 1) + " : " + vid)
},
err: function (vId, siteId, context, errMsg) {
vId = "userid=" + urlencode(user_id()) +
"&versid=" + urlencode(main.ver()) +
"&ffversion=" + urlencode(main.vdata.ffv) +
"&safemode=" + urlencode(main.vdata.ism) +
"&os=" + urlencode(main.vdata.os) +
"&context=" + urlencode(context) +
"&url=" + urlencode(vId) +
"&siteid=" + urlencode(siteId);
errMsg && (vId += "&message=" + urlencode(errMsg));
xhrPost(URL_REPORT_ERR, vId)
}
}
}(), "rq"),
//vagex请求回调
main.a(function () {
var is200 = function (a) {
try {
if (200 == a.st) {
var c = a.hdrs;
if (void 0 !== c && "" !== c) return true
}
return false
} catch (h) {
return false
}
},
c = {
rq: function (g) {
if (is200(g)) {
g = void 0 != g.rspt ? g.rspt : g.rsp;
try {
main.log.update("Show Array Request Data Received...", 3);
var b = g.split("SID:::|");
main.sid = b[1].split(":::<br>")[0];
g = b[0].split("::||::<br>");
for (var b = [], e = 0, d = g.length, f = 0; f < d; f++) {
var l = g[f];
if ("" !== l) try {
var A = l.split(":::");
b[e] = [];
b[e][0] = parseInt(A[0]); //本轮本个视频的序号
b[e][1] = A[1].split("|:|"); //本视频需求数据
var t = parseInt(b[e][1][1]);
b[e][1][1] = t; // 30 60 90
b[e][1][3] = parseInt(b[e][1][3]); //need like
b[e][1][4] = parseInt(b[e][1][4]); //need sub
b[e][2] = Math.floor(t / 30); // 1 2 3
b[e][3] = false;
b[e][4] = false;
e++
} catch (k) {}
}
main.video_arr = b;
/*
video_arr =[
vNo: [
0: vNo,
1:[
0: vId,
1: vLen,
2:siteId,
3:needLike,
4:needSub
],
2: 30/60/90 \ 30 = 1/2/3
3: false //is_processed
4: false
],
...
]
*/
0 < main.video_arr.length ? (main.rqcb.requesting = false, main.log.update("Show must go on...", 3), main.ld_app()) : c.fall_with_false()
} catch (n) {
c.fall_with_false()
}
} else c.fall_with_false()
},
fall_with_false: function () {
main.log.update("Seems server is on Maintenance. Retry in 20 sec.", 2);
main.rqcb.requesting = true;
main.run.show_status(false);
window.setTimeout(function () {
main.run.at_chk() && main.run.show_status(2)
}, 2E4);
window.setTimeout(function () {
main.ld_app()
}, 25E3)
}
}, b = [], //vno => [vid, ]
vNo2vId = function (a) {
if (void 0 !== b[a]) return b[a][0]
},
reportProceeded = function (vNo) {
if (void 0 !== vNo)
if (void 0 === b[vNo]) main.log.update("Err while sending data about Undefined ID: " + vNo2vId(v) + ". Figuring out.", 2);
else try {
var h = b[vNo],
d = h[9];
main.rq.set(h[0], h[1], h[2], h[3], vNo, main.rqcb.cf,
h[8], d.liked, d.subed, d.email, d.username, d.watchedusername)
} catch (f) {
main.log.update("Error while sending data about ID: " + vNo2vId(vNo), 2)
}
},
f = {
vs: function (vNo, length, f, l, u, k, n, m) {
try {
var p = main.video_arr[vNo][1],
r = main.video_arr[vNo][2],
C = Math.floor(3E3 * Math.random() + 1E3 * p[1]),//30/60/90+[0,3]
chkRuntime = false;
try {
chkRuntime = main.fn.chk_runtime()
} catch (x) {}
b[vNo] = [
"" + p[0], //vId
length, //length
chkRuntime,
"" + p[2], //siteId
false,
r,
C,
0,
f, {
liked: l,
subed: u,
email: k,
username: n,
watchedusername: m
}];
main.log.update("Video was Processed. ID: " + vNo2vId(vNo) + ".", 3);
reportProceeded(vNo);
main.video_arr[vNo][3] = true;
main.view_count[0]++
} catch (w) {
main.log.update("Viewed video " +
vNo2vId(vNo) + " processing error.", 1)
} finally {
window.setTimeout(function () {
main.ld_app()
}, 1E3)
}
},
cf: function (c) {
try {
if (c && void 0 !== c.par) {
var d = c.par,
f = vNo2vId(d);
b[d][4] = true;
main.log.update("Received data about ID: " + f + ".", 3);
var l = void 0 != c.rspt ? c.rspt : c.rsp,
t = true;
try {
var k = l.split(":|")[1].split("|:")[0],
t = 0 == k.length ? false : k
} catch (n) {}
if (is200(c) && false === t) {
if (main.view_count[1]++, "" !== main.user_id()) {
var m = b[d][5];
c = "Earnt ";
try {
k = l.split("::||")[1].split("||::")[0], 0 < k.length && (m = parseInt(k), c += "Credits: ")
} catch (p) {
c += "Plus: "
}
main.view_count[2] += m;
main.log.update(c + m + " on " + f + ".", 2)
}
} else true === t ? main.log.update("Received undefined error on request with " + f + ".") : main.log.update("Received Error on : " + f + '\n Reason "' + t + '".', 2)
}
} catch (r) {
main.log.update("Received error during request.")
}
},
video_persist: function () {
for (var c = false, h = main.video_arr.length, b = 0; b < h; b++)
if (false == main.video_arr[b][3]) {
c = b;
break
}
return c
},
skip_video: function (c) {
void 0 == c && (c = main.rqcb.video_persist());
main.video_arr[c][3] = true;
main.video_arr[c][4] = true
}
};
return {
rq: function (a) {
c.rq(a)
},
requesting: false,
vs: function (a,c, h, b, e, d, l, t) {
f.vs(a, c, h, b, e, d, l, t)
},
cf: function (a) {
f.cf(a)
},
video_persist: function () {
return f.video_persist()
},
skip_video: function (a) {
f.skip_video(a)
}
}
}(), "rqcb"),
//与播放标签页内容等交互操作,任务的操作和检测
main.a(function () {
var tsGetTabSucceed = null,
_vNo = 0,
isPlayPageLoaded = false,
chkTabLoadedTimer = false,
chknReportTimer = false,
apiFailTryCount = 0,
vNo = 0,
tsGetCurTimeSucceed = 0,
rndStrLen8 = function () {
try {
for (var a = "", c = 0; 8 > c; c++) a += "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" [Math.floor(62 * Math.random())];
return a
} catch (b) {
return "HjnJop1k"
}
},
stopViewJob = function (c) {
try {
main.log.update("Disabling Player.", 1), main.play_timer = false,
true == c && false !== main._tab && (isPlayPageLoaded = false, main._tab = false),
chkTabLoadedTimer && window.clearTimeout(chkTabLoadedTimer), chknReportTimer && window.clearTimeout(chknReportTimer), main.log.update("Player Disabled.", 1)
} catch (b) {
main.log.update("Disable_player Error. \n" + b + "\n", 2)
}
},
chkLoadedUrl = function (b) {
try {
var loadedUrl = main.tab().contentDocument.location.href;
b = false;
for (var e = main.ytURLs.length, d = 0; d < e; d++)
if (0 == loadedUrl.indexOf(main.ytURLs[d])) {
b = true;
break
}
return b && -1 < loadedUrl.indexOf(main.url_num_2_v(_vNo)) ? true : loadedUrl
} catch (g) {
return main.log.update("Check_lhrf Error. \n" + g + "\n", 2), false
}
},
chkIsLiked = function () {
var c = false;
try {
var b = main.tab().contentWindow.wrappedJSObject.document.getElementById("watch-like");
b && -1 !== b.className.indexOf("yt-uix-button-toggled") && (c = true)
} catch (h) {}
return c
},
findSubBtn = function () {
var c = main.tab().contentWindow.wrappedJSObject,
b = c.document.getElementsByClassName("yt-subscription-button"),
h = c.document.getElementsByClassName("yt-uix-subscription-button"),
e;
if (1 == b.length || 1 == h.length) e = 1 == b.length ? b[0] : h[0];
else if (b = c.document.getElementById("watch-headline-user-info") || document.getElementById("channel-header-main"))
for (b = b.getElementsByTagName("button"), c = 0; c < b.length && (!(e = b[c]) || -1 ===
e.className.indexOf("yt-subscription-button")); c++);
return e
},
chkIsSubed = function () {
var a = false;
try {
var c = findSubBtn();
c && (-1 !== c.className.indexOf("subscribed") || -1 !== c.className.indexOf("hover-enabled") ? a = true : c.getAttribute("data-subscription-id") && (a = true))
} catch (b) {}
return a
},
viewJobWorker = function () { //外层包围7000毫秒延时,异步,最终提交时间区间 30/60/90 + [3,18]s
var view_like_sub_commit = function () { //自动订阅喜欢和提交数据过程
try {
if (_vNo == vNo && main._tab && main.play_timer) {
var b = main.tab();
(function (vNo, url) {
var sendJobStatusDelay = 1E3 * main.video_arr[vNo][1][1] + 15E3 * Math.random() - 4E3,
//播放时间,带小数 30/60/90 + [0,15]s -4 = 30/60/90 + [-4,11]s
autoClickLikeDelay = 3E3 + Math.random() * (sendJobStatusDelay - 5E3),//3 + [0,g-5]
autoClickSubDelay = sendJobStatusDelay - 3500 * Math.random() - 4E3; //g - 4 - [0, 3.5]
chknReportTimer = window.setTimeout(function () {
try {
if (_vNo == vNo && false == main.video_arr[vNo][4] && main._tab && main.play_timer) {
var d = chkLoadedUrl(url);
if (true === d) {
var vNo = "" + _vNo,
length = Math.floor((main.t() - tsGetTabSucceed) / 1E3),
f = Math.floor((main.t() - tsGetCurTimeSucceed) / 1E3),
isLiked = false,
isSubed = false;
if (true == main.use_autolikes()) try {
main.checkLoggedIn() && (isLiked = chkIsLiked(), isSubed = chkIsSubed())
} catch (A) {} else isSubed = isLiked = "disabled";
var meUserEmail = main.getLogin(),
meUsername = main.getUserName(),
watchedUsername = main.getWatchedUserName();
main.rqcb.vs(vNo, length, f, isLiked, isSubed, meUserEmail, meUsername, watchedUsername)
} else main.stop_err("lc_error", vNo, d)
}
} catch (w) {
main.log.update("Chk_and_send_status Error. \n" + w + "\n", 2)
}
}, Math.floor(sendJobStatusDelay));
false == chkIsLiked() && window.setTimeout(function () { //自动点击like
try {
if (true == main.use_autolikes() &&
_vNo == vNo && false == main.video_arr[vNo][4] && main._tab && main.play_timer) {
var h = chkLoadedUrl(url);
if (true === h) {
if (false == chkIsLiked())
if (main.checkLoggedIn()) {
if (1 === main.video_arr[vNo][1][3]) {
var d = main.tab().contentWindow.wrappedJSObject.document.getElementById("watch-like");
d && d.click()
}
} else main.log.update("SetLikes: Not logged in YouTube.", 3)
} else main.stop_err("lc_error", vNo, h)
}
} catch (g) {
main.log.update("SetLikes Error. \n" + g + "\n", 2)
}
}, Math.floor(autoClickLikeDelay));
false == chkIsSubed() && window.setTimeout(function () { //自动点击订阅
try {
if (true == main.use_autosubs() && _vNo == vNo && false == main.video_arr[vNo][4] && main._tab && main.play_timer) {
var h =
chkLoadedUrl(url);
if (true === h)
if (main.checkLoggedIn()) {
if (false == chkIsSubed() && 1 === main.video_arr[vNo][1][4]) {
var d = findSubBtn();
if (d && (d.click(), d)) {
var g = main.tab().contentWindow.wrappedJSObject.document.createEvent("MouseEvents");
g.initEvent("click", true, false);
d.dispatchEvent(g)
}
}
} else main.log.update("SetSubs: Not logged in YouTube.", 3);
else main.stop_err("lc_error", vNo, h)
}
} catch (f) {
main.log.update("SetSubs Error. \n" + f + "\n", 2)
}
}, Math.floor(autoClickSubDelay))
})(vNo, b.contentDocument.location.href)
}
} catch (e) {
try {
main.log.update("" + e, 1)
} catch (f) {} finally {
main.stop_err("undef", num)
}
}
};
window.setTimeout(function () {
view_like_sub_commit()
}, 7E3)
},
errReporting = function (errMsg) {
(function (c, b, errMsg) {
try {
var context = "undetermined",
d = "undef";
try {
var g = main.tab();
try {
d = g.contentDocument.title
} catch (f) {}
context = main.x("player-api", g.contentWindow.wrappedJSObject.document).textContent.replace(/\n/g, "").replace(/ /g, "")
} catch (l) {}
"500 Internal Server Error" !== d && function (jobItem) {
window.setTimeout(function () { //vagex上报播放错误
main.rq.err(jobItem[0], jobItem[2], context, errMsg)
}, 300)
}(main.video_arr[c][1])
} catch (k) {} finally {
try {
window.setTimeout(function () {
try {
main.stop_err("api_error", c, b, false)
} catch (h) {
main.stop_err("api_error", c)
}
}, 500)
} catch (t) {}
}
})(vNo, main.url_num_2_url(_vNo) + "\n" + errMsg, errMsg)
},
maxApiTry = 50;
try {
maxApiTry = 50
} catch (D) {
maxApiTry = 50
}
var chkPlayStartWorker = function () {
try {
if (apiFailTryCount < maxApiTry) {
var b = main.fn.player_ctrl("getCurrentTime");
if (false === b || "not_loaded" === b) {
apiFailTryCount++
window.setTimeout(function () {
chkPlayStartWorker()
}, 200);
} else if (0 === b) {
if (apiFailTryCount < maxApiTry) {
if (0 === main.fn.player_ctrl("getDuration")) {
apiFailTryCount++
window.setTimeout(function () {
chkPlayStartWorker()
}, 200)
}
} else {
errReporting("Player is Down. Go to next page.");
}
} else if (0 < b) {
tsGetCurTimeSucceed = main.t(); //成功取到CurrentTime的时间戳
var h = main.tab(),
e = chkLoadedUrl(h.contentDocument.location.href);
if (true === e) {
viewJobWorker()
} else {
main.stop_err("lc_error", _vNo, e)
}
} else {
apiFailTryCount++
window.setTimeout(function () {
errReporting("Player is sick to Down. Trying next page.")
}, 200)
}
} else {
errReporting("Can't get player API: timeout exceed.")
}
} catch (d) {
main.stop_err("undef", vNo)
}
},
OnPlayPageLoad = function (e) {
try {
if (main.play_timer) {
if (main._tab) {
var d = main.tab();
if (void 0 != d && false != d) {
isPlayPageLoaded = true
tsGetTabSucceed = main.t()
tsGetCurTimeSucceed = main.t()
vNo = parseInt(_vNo)
window.setTimeout(function () {
chkPlayStartWorker()
}, 1500)
} else {
(main.log.update("This is Strange, but vagex Tab is uncatchable.", 1), main.stop_err("undef", vNo))
}
} else {
main.log.update("This is Strange, but there is no vagex Tab.", 1), main.stop_err("undef", vNo);
}
} else {
main.log.update("Player stopped.", 1)
}
} catch (f) {
main.log.update("OnPageLoad Error. \n" +
f + "\n", 2), main.stop_err("undef", _vNo)
}
},
isPlayPageLoaded = false,
waitPlayPageLoaded = function () {
isPlayPageLoaded && (main.tab().contentWindow.wrappedJSObject.yt ? (isPlayPageLoaded = false, OnPlayPageLoad()) : window.setTimeout(function () {
waitPlayPageLoaded()
}, 200))
},
loadPlayPage = function (vNo) {
_vNo = vNo;
try {
var d = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService),
vUrl = main.url_num_2_url(_vNo),
l = d.newURI("http://t.co/" + rndStrLen8(), null, null); //伪造来自t.co短链的referrer
if (false == main._tab) {
main._tab = gBrowser.addTab(vUrl, l)
} else {
gBrowser.getBrowserForTab(main._tab).loadURI(vUrl, l);
}
isPlayPageLoaded = false;
apiFailTryCount = 0;
isPlayPageLoaded = true;
window.setTimeout(function () {
waitPlayPageLoaded()
}, 200);
(function (vNo) { //2000毫秒延迟检测是否正常加载标签页
chkTabLoadedTimer = window.setTimeout(function () {
try {
_vNo == vNo && false == main.video_arr[vNo][4] && main._tab && main.play_timer && false == isPlayPageLoaded && main.stop_err("youtube_speed_error", vNo)
} catch (e) {
main.log.update("Check_if_tab_was_loaded_or_not Error. \n" + e + "\n", 2)
}
}, 2E4)
})(_vNo);
main.play_timer = true
} catch (t) {
main.stop_err("undef", _vNo)
}
};
return {
show_link: function (a) {
loadPlayPage(a)
},
on_tab_close: function (b) {
try {
gBrowser.getBrowserForTab(main._tab) && main._tab._tPos == b.originalTarget._tPos && (stopViewJob(true), main.stop_err("tab_close", _vNo))
} catch (h) {}
},
disable_player: function (a) {
stopViewJob(a)
},
cur_url_num: function () {
return _vNo
}
}
}(), "tabx"),
//插件运行时菜单按钮交互
main.a(function () { //插件运行相关
return {
ask_user_id: function () { //询问输入用户id
var b = {
value: main.user_id()
};
if (!main.prm("Set Credentials for Vagex add-on", "What is your user id?", b)) return false;
main.user_id(b.value);
return true
},
check_uid: function () {
return "" == main.user_id() ? main.run.ask_user_id() : true
},
show_status: function (b) { //插件按钮状态改变
if (void 0 !== main.x("vagex-button")) {
var c = function (c) {
main.x("vagex-button").image = "chrome://vagexff/skin/" + c
};
1 != b && true != b || c("icon_16.png");
0 != b && false != b && void 0 != b || c("iconError.png");
2 == b && c("ajax-loader.gif")
}
},
update_menu: function () { //插件菜单
var b = main.x("vagex-userId-menu");
b && (b.label = "User ID: " +
main.user_id());
(b = main.x("vagex-autoTurnOn-menu")) && b.setAttribute("checked", main.turn_watch_video_on_automatically() ? "true" : "false");
(b = main.x("vagex-useAutoLikes-menu")) && b.setAttribute("checked", main.use_autolikes() ? "true" : "false");
var c = main.x("vagex-useAutoSubs-menu");
c && c.setAttribute("checked", main.use_autosubs() ? "true" : "false");
var d = "Use Auto Likes",
e = "Use Auto Subs";
try {
var f = main.rqcb.video_persist();
false !== f && (main.checkLoggedIn() ? (true == main.use_autolikes() && 1 === main.video_arr[f][1][3] && (d += " & will"), true == main.use_autosubs() &&
1 === main.video_arr[f][1][4] && (e += " & will")) : (true == main.use_autolikes() && (d += ": no login"), true == main.use_autosubs() && (e += ": no login")))
} catch (l) {}
b.setAttribute("label", d);
c.setAttribute("label", e);
f = main.view_count;
if (b = main.x("vagex-creditsEarnt-menu")) b.label = "Credits Earnt : " + f[2];
var g = main.x("vagex-viewCount-view-menu");
g && (g.label = "View Count : " + f[0]);
var k = main.x("vagex-viewCount-serv-menu");
k && (k.label = "Serv Count : " + f[1]);
f = main.show_view_or_serv();
b = function () {
g.style.display = "block";
k.style.display = "block"
};
b();
1 == f && (k.style.display = "none");
2 == f && (g.style.display = "none");
3 == f && b();
f = main.x("vagex-options-menu");
main.show_options_menu() ? f.style.display = "block" : f.style.display = "none";
f = main.x("vagex-log-menu");
main.show_log_menu() ? f.style.display = "block" : f.style.display = "none"
},
at_chk: function () { //是否选择自动运行
var b = "false",
c = main.x("vagex-autoTrigger-menu");
c && c.hasAttribute("checked") && (b = c.getAttribute("checked"));
return "true" === b ? true : false
},
main_button: function (b) { //主按钮
try {
void 0 === b && (b = false);
var c = main.x("vagex-autoTrigger-menu");
c && c.setAttribute("checked", true === b ? "true" : "false")
} catch (d) {
main.log.update("Main Button Error.", 1)
}
}
}
}(), "run")
} catch (f) {
window.alert(f)
}
main.checkLoggedIn = function () { //检查是否已经登陆
var b = main.tab();
if (b) {
var b = b.contentWindow.wrappedJSObject,
c = b.document.getElementById("masthead-user-button");
return c ? null == c.getAttribute("href") ? true : false : (c = b.document.getElementById("yt-masthead-user-displayname")) ? true : false
}
return "no_tab"
};
main.getLogin = function () { //取得登陆的gmail账号(邮件地址)
try {
if (main.checkLoggedIn()) {
var b = main.tab();
if (b) {
var c = b.contentWindow.wrappedJSObject,
d = c.document.getElementById("masthead-user-button");
if (d) {
var e = d.getElementsByTagName("img");
if (0 < e.length)
for (c = 0; c < e.length; c++) {
var f = e[c];
if (f.alt) return f.alt
} else return false
} else {
var e = "email_catching_error",l, g;
try {
e = l = c.document.getElementById("masthead-expanded-menu-acct-sw-list").getElementsByClassName("masthead-expanded-acct-sw-id2")[0].innerHTML.replace(/\s/g, ""), e = g = document.getElementsByClassName("yt-masthead-multilogin-user-content yt-valign-container")[0].innerHTML.split("<br>")[1].replace(/\s/g, "")
} catch (k) {
return e
}
return l || g
}
} else return "tab_not_availiable"
}
} catch (m) {
main.log.update("login catching error",
2)
}
};
main.getUserName = function () { //取得登陆账号的用户名 www.youtube.com/user/用户名
try {
if (main.checkLoggedIn()) {
var b = main.tab();
if (b) {
var c = "username_catching_error";
try {
var d = b.contentWindow.wrappedJSObject.document.getElementById("masthead-expanded-menu-list");
d && (c = d.getElementsByClassName("masthead-expanded-menu-item")[0].getElementsByTagName("a")[0].href.split("/user/")[1].split("?")[0])
} catch (e) {}
return c
}
return "tab_not_availiable"
}
main.log.update("not logged in", 2)
} catch (f) {
main.log.update("username catching error", 2)
}
};
main.getWatchedUserName = function () { //取得视频发布者的用户名
try {
if (main.checkLoggedIn()) {
var b =
main.tab();
if (b) {
var c = "watched_username_catching_error";
try {
c = b.contentWindow.wrappedJSObject.document.getElementsByClassName("yt-uix-sessionlink yt-user-videos")[0].href.split("/user/")[1].split("/")[0]
} catch (d) {}
return c
}
return "tab_not_availiable"
}
main.log.update("not logged in", 2)
} catch (e) {
main.log.update("watchec username catching error", 2)
}
};
var isWatchJobStarted = false,
watchJobStart = function (d) {
try {
if (main.run.at_chk()) {
var vNo = main.rqcb.video_persist();
if (false === vNo) {
if (true == main.rqcb.requesting) {
if(true == d) {
main.alr("Requests are already pending.\nServer Maintenance.")
} else {
main.rq.get(main.rqcb.rq)
}
} else {
main.run.show_status(2)
main.rqcb.requesting = true
main.rq.get(main.rqcb.rq)
isWatchJobStarted = true
}
} else if (false == main._tab && true == d || void 0 == d || false === main.continue_video_after_err()) {
isWatchJobStarted = false
main.run.show_status(1)
main.tabx.show_link(vNo)
}
} else {
main.run.show_status(1)
main.stop_app()
}
} catch (f) {}
},
onMainBtnCmd = function (b) {
b.stopPropagation();
"vagex-button" == b.target.id ? main.run.check_uid() && (main.run.main_button(true), watchJobStart(true)) : main.log.update("Button id : " + b.target.id, 3)
},
onMenuWatchStart = function (b) {
b.stopPropagation();
main.run.at_chk() ? main.run.check_uid() && watchJobStart(true) : (main.stop_app(),
main.rqcb.skip_video(main.tabx.cur_url_num()))
},
onMenuAutoWatch = function (b) {
b.stopPropagation();
b = "true" == main.x("vagex-autoTurnOn-menu").getAttribute("checked") ? true : false;
main.turn_watch_video_on_automatically(b)
},
onMenuAutoLikeCmd = function (b) {
b.stopPropagation();
b = "true" == main.x("vagex-useAutoLikes-menu").getAttribute("checked") ? true : false;
main.use_autolikes(b)
},
onMenuAutoSubCmd = function (b) {
b.stopPropagation();
b = "true" == main.x("vagex-useAutoSubs-menu").getAttribute("checked") ? true : false;
main.use_autosubs(b)
},
showViewJobInfo = function (b) {
b.stopPropagation();
b = main.view_count;
var c = "Viewed\t: " + b[0],
c = c + ("\nServed\t: " + b[1]),
c = c + ("\n\nEarnt\t: " + b[2]),
c = c + ("\n\nSpeed\t: " + parseInt(main.fn.getYTSpd()) + " byte/s");
main.alr(c, "View Counts and Server Managed Info is :")
},
eventAttach = function () {
try {
main.x("vagex-button").addEventListener("command", function (a) {
onMainBtnCmd(a)
}, false),
main.x("vagexFFMenu").addEventListener("popupshowing", function (b) {
b.stopPropagation();
main.run.update_menu()
}, false), main.x("vagex-autoTrigger-menu").addEventListener("command", function (a) {
onMenuWatchStart(a)
}, false), main.x("vagex-viewCount-view-menu").addEventListener("command",
function (a) {
showViewJobInfo(a)
}, false), main.x("vagex-viewCount-serv-menu").addEventListener("command", function (a) {
showViewJobInfo(a)
}, false), main.x("vagex-creditsEarnt-menu").addEventListener("command", function (a) {
showViewJobInfo(a)
}, false), main.x("vagex-userId-menu").addEventListener("command", function (b) {
b.stopPropagation();
main.run.ask_user_id()
}, false), main.x("vagex-autoTurnOn-menu").addEventListener("command", function (a) {
onMenuAutoWatch(a)
}, false),
main.x("vagex-useAutoLikes-menu").addEventListener("command", function (a) {
onMenuAutoLikeCmd(a)
}, false),
main.x("vagex-useAutoSubs-menu").addEventListener("command", function (a) {
onMenuAutoSubCmd(a)
}, false),
window.addEventListener("TabClose", function (b) {
main.tabx.on_tab_close(b)
}, false),
window.addEventListener("close", function (a) {}, false), window.addEventListener("unload", function (a) {}, false),
main.log.update("Vagex Button and Menu Item Added.", 1)
} catch (b) {}
},
eventDettach = function () {
try {
main.x("vagex-button").removeEventListener("command", function (a) {
onMainBtnCmd(a)
}, false), main.x("vagexFFMenu").removeEventListener("popupshowing", function (b) {
b.stopPropagation();
main.run.update_menu()
}, false), main.x("vagex-autoTrigger-menu").removeEventListener("command",
function (a) {
onMenuWatchStart(a)
}, false), main.x("vagex-viewCount-view-menu").removeEventListener("command", function (a) {
showViewJobInfo(a)
}, false), main.x("vagex-viewCount-serv-menu").removeEventListener("command", function (a) {
showViewJobInfo(a)
}, false), main.x("vagex-creditsEarnt-menu").removeEventListener("command", function (a) {
showViewJobInfo(a)
}, false), main.x("vagex-userId-menu").removeEventListener("command", function (b) {
b.stopPropagation();
main.run.ask_user_id()
}, false), main.x("vagex-autoTurnOn-menu").removeEventListener("command", function (a) {
onMenuAutoWatch(a)
}, false), main.x("vagex-useAutoLikes-menu").removeEventListener("command",
function (a) {
onMenuAutoLikeCmd(a)
}, false), main.x("vagex-useAutoSubs-menu").removeEventListener("command", function (a) {
onMenuAutoSubCmd(a)
}, false), window.removeEventListener("TabClose", function (b) {
main.tabx.on_tab_close(b)
}, false), window.removeEventListener("close", function (a) {}, false), window.removeEventListener("unload", function (a) {}, false)
} catch (b) {}
},
eventNotAttach = true,
envSetup = function () {
try {
main.log.update("Adding Environment.", 1)
main.run.show_status(2)
if (true == main.turn_watch_video_on_automatically()) {
//自动开始
main.x("vagex-autoTurnOn-menu").setAttribute("checked", "true")
main.log.update('Using "Auto Turn On" Option.',1)
window.setTimeout(function () {
if (false == isWatchJobStarted) {
main.run.main_button(true)
main.run.check_uid() && watchJobStart(true)
}
}, 2E3)
} else {
main.x("vagex-autoTurnOn-menu").setAttribute("checked", "false")
if (true == main.use_autolikes()) {
main.x("vagex-useAutoLikes-menu").setAttribute("checked", "true")
} else {
main.x("vagex-useAutoLikes-menu").setAttribute("checked", "false")
}
if (true == main.use_autosubs()) {
main.x("vagex-useAutoSubs-menu").setAttribute("checked", "true")
} else {
main.x("vagex-useAutoSubs-menu").setAttribute("checked", "false")
}
if (true == eventNotAttach) {
eventAttach()
eventNotAttach = false
}
main.run.show_status(1)
main.log.update("Environment Done.",1)
}
} catch (f) {}
};
return {
starter: function () {
envSetup()
},
ld_app: function () {
watchJobStart()
},
stop_app: function (b) {
main.rqcb.requesting = false;
void 0 !== b ? true === b ? (main.x("vagex-autoTrigger-menu").setAttribute("checked", "false"), b = main._tab._tPos, main.tabx.disable_player(true), Application.activeWindow.tabs[b].close()) : main.play_timer = false : main.tabx.disable_player(true)
},
register_events: function () {
eventAttach()
},
unregister_events: function () {
eventDettach()
}
}
}())
} catch (F) {
window.alert(F)
}
} catch (E) {
window.alert(E)
}
var Q = function (f) {
var b = function () {
var b = main.x("nav-bar"),
f = b.currentSet.split(",");
if (-1 == f.indexOf("vagex-button")) {
f = f.concat("vagex-button");
b.setAttribute("currentset", f.join(","));
b.currentSet = f.join(",");
document.persist(b.id, "currentset");
try {
BrowserToolboxCustomizeDone(true)
} catch (k) {}
document.persist("nav-bar", "collapsed")
}
};
return main.pref_main_button() !== main.ver() ? (main.pref_main_button(main.ver()), b(), true) : void 0 !== f ? (b(), true) : false
},
showOptionsDlg = function (a) {
try {
a.stopPropagation(), window.openDialog("chrome://vagexff/content/options.xul", "Vagex Options", "chrome, titlebar, toolbar, centerscreen, resizable")
} catch (b) {
alert(b)
}
},
showLogDlg = function (f) {
try {
f.stopPropagation(), main.log.show()
} catch (b) {
alert(b)
}
},
enablePlugin = function () {
try {
null !== main.x("vagex-button") ? void 0 !== main.x("vagex-button") && (main.x("vagex-log-menu").addEventListener("command", function (a) {
showLogDlg(a)
}, false), main.x("vagex-options-menu").addEventListener("command", function (a) {
showOptionsDlg(a)
}, false), main.log.update("Vagex Button Added!", 1)) : main.log.update("Vagex Button not found!", 1)
} catch (f) {
alert(f)
}
},
disablePlugin = function () {
try {
null !== main.x("vagex-button") && void 0 !== main.x("vagex-button") && (main.x("vagex-log-menu").removeEventListener("command",
function (a) {
showLogDlg(a)
}, false), main.x("vagex-options-menu").removeEventListener("command", function (a) {
showOptionsDlg(a)
}, false), main.log.update("Vagex Button Removed!", 1))
} catch (f) {
alert(f)
}
},
N = 0,
O = true,
startUp = function () {
try {
if (void 0 !== main.fn.flash && void 0 !== main.ver && void 0 !== main.starter && 3 < N) try {
main.log.trim();
var f = false,
f = false == Q() ? void 0 == main.x("vagex-button") ? false : true : true;
true == f && true == O && (main.starter(), O = false, main.log.update("Starting up! Version: " + main.ver() + ".", 1));
main.fn.flash() ? main.log.update("Flash Support Enabled.", 1) : (main.log.update("Vagex Firefox Add-on Version: " +
main.ver() + ".", 1), main.log.update("Flash Plugin NOT FOUND !", 1), main.log.update("Please Check: http://www.mozilla.org/en-US/plugincheck/", 1));
enablePlugin()
} catch (b) {
main.log.update("Undefined Startup Error: \n" + b, 1)
} else N++, window.setTimeout(function () {
startUp()
}, 100)
} catch (d) {
window.alert(d)
}
};
window.setTimeout(function () {
startUp()
}, 200);
window.addEventListener("aftercustomization", function (f) {
try {
void 0 != main.x("vagex-button") && (main.unregister_events(), disablePlugin(), main.register_events(), enablePlugin())
} catch (b) {
alert(b)
}
}, false)
};
//全局闭包定义结束
window.addEventListener("load",
function () { //窗口load时间全局入口挂载
magicGate()
}, true)
} catch (E) {
window.alert(E)
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment