2 // @name ThunderLixianExporter
3 // @namespace http://dynamic.cloud.vip.xunlei.com/
5 // @description export thunder lixian url to aria2/wget
6 // @include http://dynamic.cloud.vip.xunlei.com/user_task*
7 // @include http://lixian.vip.xunlei.com/lx3_task.html*
8 // @include http://jiayuan.xunlei.com/lxhome/lx3_task.html*
9 // @include http://cloud.vip.xunlei.com/*
10 // @run-at document-end
11 // @copyright 2012+, Binux <root@binux.me>
12 // @updateURL http://s.binux.me/TLE/master/ThunderLixianExporter.meta.js
15 function tle_wrapper() {
16 // vim: set et sw=2 ts=2 sts=2 ff=unix fenc=utf8:
17 // Author: Binux<root@binux.me>
19 // Created on Fri 20 Jul 2012 11:43:22 AM CST
24 '复制链接': function(todown) {
25 //console.log(todown);
26 var str = '<ul style="max-height: 300px; overflow-y: scroll; overflow-x: hidden;">';
27 $.each(todown.tasklist, function(n, task) {
28 $.each(task.filelist, function(l, file) {
29 if (!file.downurl) return;
30 str += '<li><a href="'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'" target="_blank">'+file.title+'</a></li>';
34 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': '复制选中的链接 > <a href="'+"data:text/html;charset=utf-8,"+encodeURIComponent(str)+'" target="_blank">在新窗口中打开</a>', 'content': str}).show().pop({
35 onHide: function() { $(document.body).click(); },
38 'Aria2': function(todown) {
39 //console.log(todown);
41 $.each(todown.tasklist, function(n, task) {
42 $.each(task.filelist, function(l, file) {
43 if (!file.downurl) return;
44 var filepath = TLE.safe_title(file.title);
45 if (task.tasktype == 0 && task.filelist.length > 1)
46 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
47 str += "aria2c -c -s10 -x10 --out "+TLE.escape_command(filepath)+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
50 TLE.text_pop("aria2 download command", str);
52 'wget': function(todown) {
53 //console.log(todown);
55 $.each(todown.tasklist, function(n, task) {
56 $.each(task.filelist, function(l, file) {
57 if (!file.downurl) return;
58 str += "wget -c -O "+TLE.escape_command(TLE.safe_title(file.title))+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
61 TLE.text_pop("wget download command", str);
63 "YAAW": function(todown) {
64 if (TLE.getConfig("TLE_aria2_jsonrpc")) {
65 show_tip("添加中...到YAAW界面查看是否添加成功");
66 var aria2 = new ARIA2(TLE.getConfig("TLE_aria2_jsonrpc"));
67 $.each(todown.tasklist, function(n, task) {
68 $.each(task.filelist, function(l, file) {
69 if (!file.downurl) return;
70 var filepath = TLE.safe_title(file.title);
71 if (task.tasktype == 0 && task.filelist.length > 1)
72 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
73 aria2.addUri(file.downurl, {out: filepath, header: 'Cookie: gdriveid='+todown.gdriveid});
78 show_tip("尚未设置Aria2 JSONRPC地址");
82 'Aria2导出': function(todown) {
83 //console.log(todown);
85 $.each(todown.tasklist, function(n, task) {
86 $.each(task.filelist, function(l, file) {
87 if (!file.downurl) return;
88 var filepath = TLE.safe_title(file.title);
89 if (task.tasktype == 0 && task.filelist.length > 1)
90 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
91 str += file.downurl+'\r\n out='+filepath+'\r\n header=Cookie: gdriveid='+todown.gdriveid+'\r\n continue=true\r\n max-connection-per-server=5\r\n split=10\r\n parameterized-uri=true\r\n\r\n';
94 TLE.file_pop("Aria2导出文件下载", str, "aria2.down");
96 'IDM导出': function(todown) {
97 //console.log(todown);
99 $.each(todown.tasklist, function(n, task) {
100 $.each(task.filelist, function(l, file) {
101 if (!file.downurl) return;
102 str += '<\r\n'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'\r\ncookie: gdriveid='+todown.gdriveid+'\r\n>\r\n'
105 TLE.file_pop("IDM导出文件下载", str, "idm.ef2");
107 'Orbit导出': function(todown) {
108 //console.log(todown);
110 $.each(todown.tasklist, function(n, task) {
111 $.each(task.filelist, function(l, file) {
112 if (!file.downurl) return;
113 str += TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'|'+TLE.safe_title(file.title.replace("|", "_"))+'||gdriveid='+todown.gdriveid+'\r\n'
116 TLE.file_pop("Orbit导出文件下载", str, "orbit.olt");
118 'eagleget': function(todown) {
119 var ret = {tasks: []};
120 $.each(todown.tasklist, function(n, task) {
121 $.each(task.filelist, function(l, file) {
122 if (!file.downurl) return;
124 cookie: 'gdriveid='+todown.gdriveid,
125 fname: TLE.safe_title(file.title),
126 url: TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))
130 TLE.file_pop("Eagleget导出文件下载(test)", JSON.stringify(ret), "eagleget.eg");
135 function get_taskinfo(p) {
136 var taskid = p.attr("taskid");
138 p.find("input").each(function(n, e) {
139 var key = e.getAttribute("id").replace(taskid, "");
140 info[key] = e.getAttribute("value");
145 function build_normal_taskinfo(info) {
147 'taskname': info.taskname || info.cloud_taskname,
149 'cid': info.dcid || info.cloud_cid,
150 'size': parseInt(info.ysfilesize),
151 'tasktype': info.d_tasktype,
152 'status': info.d_status,
156 'title': info.taskname || info.cloud_taskname,
158 'downurl': info.dl_url || info.cloud_dl_url,
159 'cid': info.dcid || info.cloud_cid,
161 'size': parseInt(info.ysfilesize),
163 taskinfo['filelist'] = filelist;
167 function build_bt_taskinfo(info, rdata) {
169 'taskname': info.taskname,
172 'size': parseInt(info.ysfilesize),
173 'tasktype': info.d_tasktype,
174 'status': info.d_status,
177 $.each(rdata, function(n, e) {
181 'downurl': e.downurl,
184 'size': parseInt(e.filesize),
187 taskinfo['filelist'] = filelist;
191 TLE.safe_title = function safe_title(title) {
192 return title.replace(/[\\\|\:\*\"\?\<\>]/g,"_");
195 TLE.down = function(_this, _do) {
196 var p = $(_this).parents(".rw_list");
197 var info = get_taskinfo(p);
200 if (info.d_tasktype == "0") { //bt task
202 $.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+info.input+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
205 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
206 todown.tasklist = {};
207 todown.tasklist[info.input] = build_bt_taskinfo(info, data['Result'][info.input]);
212 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
213 todown.tasklist = {};
214 todown.tasklist[info.input] = build_normal_taskinfo(info);
219 TLE.batch_down = function(_this, _do) {
220 var ck = document.getElementsByName("ck");
221 var bt_task_list = [];
222 var normal_task_list = [];
223 $.each(ck, function(n, e) {
224 if (e.checked == false) return;
226 var taskid = e.value;
227 var d_status = $("#d_status"+taskid).val();
228 var d_tasktype = $("#d_tasktype"+taskid).val();
229 var d_flag = $("#dflag"+taskid).val();
230 if (d_flag != 4 && d_status == 2) {
231 if (d_tasktype == 0) {
232 bt_task_list.push(taskid);
234 normal_task_list.push(taskid);
239 if (bt_task_list.length) {
241 $.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+bt_task_list.join(",")+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
244 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
245 todown.tasklist = {};
246 $.each(data['Result'], function(n, e) {
247 var info = get_taskinfo($("#tr_c"+n));
248 todown.tasklist[n] = build_bt_taskinfo(info, e);
250 $.each(normal_task_list, function(n, e) {
251 var info = get_taskinfo($("#tr_c"+e));
252 todown.tasklist[e] = build_normal_taskinfo(info);
258 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
259 todown.tasklist = {};
260 $.each(normal_task_list, function(n, e) {
261 var info = get_taskinfo($("#tr_c"+e));
262 todown.tasklist[e] = build_normal_taskinfo(info);
268 TLE.bt_down = function(_this, _do) {
269 var ck = document.getElementsByName("bt_list_ck");
271 $.each(ck, function(n, e) {
272 if (e.checked == false) return;
273 var fid = e.getAttribute("_i");
275 'title': $("#bt_taskname"+fid).val(),
276 'url': $("#bturl"+fid).val(),
277 'downurl': $("#btdownurl"+fid).val(),
278 'cid': $("#btcid"+fid).val(),
279 'gcid': $("#btgcid"+fid).val(),
280 'filesize': $("#bt_filesize"+fid).val(),
284 var taskid = $("#view_bt_taskid").val();
285 var info = get_taskinfo($("#tr_c"+taskid));
288 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
289 todown.tasklist = {};
290 todown.tasklist[taskid] = build_bt_taskinfo(info, files);
291 //console.log(todown);
295 //console.log("bt_down");
298 TLE.bt_down_one = function(_this, _do) {
300 var fid = $(_this).parents(".rw_list").attr("i");
302 'title': $("#bt_taskname"+fid).val(),
303 'url': $("#bturl"+fid).val(),
304 'downurl': $("#btdownurl"+fid).val(),
305 'cid': $("#btcid"+fid).val(),
306 'gcid': $("#btgcid"+fid).val(),
307 'filesize': $("#bt_filesize"+fid).val(),
310 var taskid = $("#view_bt_taskid").val();
311 var info = get_taskinfo($("#tr_c"+taskid));
314 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
315 todown.tasklist = {};
316 todown.tasklist[taskid] = build_bt_taskinfo(info, files);
317 //console.log(todown);
321 //console.log("bt_down");
324 TLE.getbtn = function(_this) {
325 $(_this).parents(".TLE_get_btnbox").find(".TLE_p_getbtn").toggle();
326 close_rightmenu_layer();
330 TLE.text_pop = function(title, content) {
331 content = $('<div></div>').text(content).html()
332 content = '<textarea style="width: 100%; height: 260px;">'+content+'</textarea>'
333 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
334 onHide: function() { $(document.body).click(); },
337 TLE.file_pop = function(title, content, filename) {
338 var url = "data:text/html;charset=utf-8,"+encodeURIComponent(content);
339 var content = '<div style="width: 100%; height: 100px;">'
340 +'<div style="padding: 30px 0 0 30%;">'
341 +'<a href="'+url+'" target="_blank" title="右键另存为" class="TLE_down_btn" download="'+filename+'"><span><em class="TLE_icdwlocal">导出文件</em></span></a>'
342 +(isChrome ? '' : '(右键另存为'+filename+')')
345 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
346 onHide: function() { $(document.body).click(); },
349 TLE.window_pop = function(title, content) {
350 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
351 onHide: function() { $(document.body).click(); },
355 TLE.multiple_server_fix = function(url) {
356 return "'"+url.replace("gdl", "'{gdl,dl.{f,g,h,i,twin}}'")+"'";
359 function encode_utf8(s) {
360 return unescape( encodeURIComponent( s ) );
362 function to_hex(num) {
363 var s = num.toString(16);
369 var thunder_filename_mask = [0x61, 0x31, 0xe4, 0x5f, 0x00, 0x00, 0x00, 0x00];
370 function thunder_filename_encode(filename) {
371 var result = ["01", ];
372 $.each(encode_utf8(filename), function(i, n) {
373 result.push(to_hex(n.charCodeAt(0)^thunder_filename_mask[i%8]).toUpperCase())
375 while (result.length % 8 != 1) {
376 result.push(to_hex(thunder_filename_mask[(result.length-1)%8]).toUpperCase());
378 return result.join("");
381 TLE.url_rewrite = function(url, filename) {
382 url = url.replace(/&n=\w+/, "&n="+thunder_filename_encode(filename));
386 var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
387 TLE.escape_command = function(str) {
389 for (var i = 0; i < str.length; i++) {
390 if (alpha.indexOf(str[i]) == -1)
391 result += "\\"+str[i];
399 TLE.getConfig = function(key) {
400 if (window.localStorage) {
401 return window.localStorage.getItem(key) || "";
403 return getCookie(key);
406 TLE.setConfig = function(key, value) {
407 if (window.localStorage) {
408 window.localStorage.setItem(key, value);
410 setGdCookie(key, value, 86400*365);
414 if (TLE.getConfig("TLE_exporter") == "") {
416 for (var key in TLE.exporter) {
419 TLE.setConfig("TLE_exporter", exporters.join("|"));
424 $("head").append('<style>'
425 +'.TLE_get_btnbox {position:relative; float:left; z-index:11}'
426 +'.TLE_getbtn {position: absolute; top:24px; left:0; border:1px #6FB2F3 solid; background:#fff; width:115px;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;-moz-box-shadow:2px 2px 3px #ddd;-webkit-box-shadow:2px 2px 3px #ddd;}'
427 +'.TLE_getbtn a {display:block; height:22px; line-height:22px; padding-left:18px}'
428 +'.TLE_getbtn a:hover {background:#E4EFF9 url(http://cloud.vip.xunlei.com/190/img/ic_dianbo.png) no-repeat 8px 8px; *background-position:8px 6px ; text-decoration:none}'
429 +'.TLE_get_btnbox .TLE_getlink {width:98px; height:22px; float:left; line-height:21px;*line-height:24px;display:block;color:#000000; margin-right:5px; overflow:hidden;background:url(http://cloud.vip.xunlei.com/190/img/bg_btnall.png?197) no-repeat 0 -390px}'
430 +'.TLE_get_btnbox .TLE_link_gettxt {float:left; display: inline ; width:53px; text-align:center; padding-left:24px; color:#000}'
431 +'.TLE_get_btnbox .TLE_link_gettxt:hover {text-decoration:none}'
432 +'.rwbox .rwset .TLE_link_getic {float:left; display:block; width:20px;height:22px;}'
433 +'.TLE_hiden {display: none; }'
434 +'.TLE_down_btn {background: url(http://cloud.vip.xunlei.com/190/img/lx/bg_rpx.png) no-repeat 0 999em; display: block; float: left; margin: 0 1px; overflow: hidden; color: white; height: 28px; padding-left: 8px; background-position: 0 -60px; text-decoration: none; }'
435 +'.TLE_down_btn span {background: url(http://cloud.vip.xunlei.com/190/img/lx/bg_rpx.png) no-repeat 0 999em; display: block; float: left; height: 28px; line-height: 27px; cursor: pointer; padding-right: 8px; background-position:100% -60px; }'
436 +'.TLE_down_btn:active {background-position:0 -28px; }'
437 +'.TLE_down_btn:active span {background-position:right -28px;}'
438 +'.TLE_icdwlocal { padding-left: 20px; display: inline-block; background: url(http://cloud.vip.xunlei.com/190/img/lx/bg_menu.png) no-repeat 0 999em; background-position: 0 -108px; }'
440 +'.rwbtn.ic_redownloca { display: none !important; }'
441 +'.menu { width: 700px !important; }'
443 +'.rwset {width:530px;}'
446 $("body").append('<div id="TLE_text_pop" class="pop_rwbox" style="display: none;margin: 0;"></div>');
447 $("body").append('<textarea id="TLE_text_tpl" style="display: none;"></textarea>');
448 $("#TLE_text_tpl").text('<div class="p_rw_pop">'
449 +'<div class="tt_box onlytitle">'
452 +'<div class="psc_info">'
455 +'<a href="#" class="close" title="关闭">关闭</a>'
457 $("#setting_main_tpl").text($("#setting_main_tpl").text().replace(/(<\/div>\s+<div class="btnin">)/,
458 '<div class="doline mag01"></div>'
459 +'<h3 style="background-position: 0 -180px;">Thunder Lixian Exporter 设定</h3>'
461 +'<li><b>启用以下导出器</b></li>'
463 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
465 for (var name in TLE.exporter) {
466 str += '<span class="rw_col"><input type="checkbox" class="TLE_setting_ck" name="TLE_ck_'+name+'" '+(enabled_exporter.indexOf(name) == -1 ? "" : "checked")+' />'+name+'</span>';
470 +'<li><b>Aria2 JSON-RPC Path</b></li>'
471 +'<li>Path: <input type="text" id="TLE_aria2_jsonrpc" style="width: 350px" value="'+TLE.getConfig("TLE_aria2_jsonrpc")+'"/></li>'
474 $(".n_vip").after('<div class="zh_info"><em onclick="setting.show()" class="sys_set"></em></div>');
475 var _set_notice_submit = set_notice_submit;
476 set_notice_submit = function(f) {
477 _set_notice_submit(f);
478 var enabled_exporter = [];
479 $(".TLE_setting_ck").each(function(n, e) {
480 if (e.checked) enabled_exporter.push(e.name.replace(/^TLE_ck_/, ""));
482 var config_str = (enabled_exporter.length == 0) ? "_" : enabled_exporter.join("|");
483 var jsonrpc_path = $("#TLE_aria2_jsonrpc").val();
484 if (TLE.getConfig("TLE_exporter") != config_str || TLE.getConfig("TLE_aria2_jsonrpc") != jsonrpc_path) {
485 TLE.setConfig("TLE_exporter", config_str);
486 TLE.setConfig("TLE_aria2_jsonrpc", jsonrpc_path);
488 setTimeout(function(){
490 location.reload(true);
495 function exporter_anchors(type) {
496 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
498 $.each(TLE.exporter, function(n, f) {
499 if (enabled_exporter.indexOf(n) == -1) return;
500 str+=('<a href="#" title="'+n+'" onmouseover="this.className=\'sel_on\'" onmouseout="this.className=\'\'" onclick="'+type+'(this, TLE.exporter[\''+n+'\'])">'+n+'</a>');
505 $(".rwbtn.ic_redownloca").each(function(n, e) {
506 $(e).after('<div class="TLE_get_btnbox">'
507 + '<span class="TLE_getlink">'
508 + '<a href="#" class="TLE_link_gettxt TLE-down-text" style="padding-left: 20px; width: 57px;" onclick='+e.getAttribute("onclick")+'>取回本地</a>'
509 + '<a href="#" class="TLE_link_getic TLE-down-btn" onclick="return TLE.getbtn(this);"></a>'
511 + '<div class="TLE_p_getbtn TLE_getbtn" style="display: none;">'
512 + exporter_anchors("TLE.down")
518 $("#li_task_down,#li_task_download").after('<a href="#" id="TLE_batch_down" title="批量导出" class="btn_m noit"><span><em class="icdwlocal">批量导出</em></span></a>')
519 .parents(".main_link").append(
520 '<div id="TLE_batch_getbtn" class="TLE_getbtn" style="top: 30px; display:none;">'
521 + exporter_anchors("TLE.batch_down")
523 var _task_check_click = task_check_click;
524 task_check_click = function() {
526 if ($("#li_task_down,#li_task_download").hasClass("noit")) {
527 $("#TLE_batch_down").addClass("noit").unbind("click");
529 $("#TLE_batch_down").removeClass("noit").unbind("click").click(function() {
530 $("#TLE_batch_getbtn").css("left", $("#TLE_batch_down").position().left);
531 $("#TLE_batch_getbtn").toggle();
535 //console.log("task_check_click called");
537 $('input[name=ck],input#ckbutton').click(task_check_click);
540 $("#view_bt_list_nav_tpl").text($("#view_bt_list_nav_tpl").text().replace('取回本地</em></span></a>',
541 '取回本地</em></span></a>'
542 +'<a href="#" class="btn_m noit" title="批量导出" id="TLE_bt_down"><span><em class="icdwlocal">批量导出</em></span></a>'
543 +'<div id="TLE_bt_getbtn" class="TLE_getbtn" style="top: 30px; display:none;">'
544 + exporter_anchors("TLE.bt_down")
546 $("#view_bt_list_tpl").text($("#view_bt_list_tpl").text().replace('ic_redownloca" title="">取回本地</a>',
547 'ic_redownloca" title="">取回本地</a>'
548 +'<div class="TLE_get_btnbox">'
549 + '<span class="TLE_getlink">'
550 + '<a href="#" class="TLE_link_gettxt TLE-down-text" style="padding-left: 20px; width: 57px;" onclick="thunder_download($[p.i],1);return false;">取回本地</a>'
551 + '<a href="#" class="TLE_link_getic TLE-down-btn" onclick="return TLE.getbtn(this);"></a>'
553 + '<div class="TLE_p_getbtn TLE_getbtn" style="display: none;">'
554 + exporter_anchors("TLE.bt_down_one")
557 var _bt_view_nav = bt_view_nav;
558 bt_view_nav = function() {
560 if ($("#view_bt_list_nav_down").hasClass("noit")) {
561 $("#TLE_bt_down").addClass("noit").unbind("click");
563 $("#TLE_bt_down").removeClass("noit").unbind("click").click(function() {
564 $("#TLE_bt_getbtn").css("left", $("#TLE_bt_down").position().left);
565 $("#TLE_bt_getbtn").toggle();
569 $("#TLE_bt_getbtn").hide();
570 //console.log("bt_view_nav called");
574 $(document.body).bind("click",function(){
575 $("div.TLE_p_getbtn, #TLE_batch_getbtn, #TLE_bt_getbtn").hide();
577 $("div.rw_list").click(function(e){
578 $("div.TLE_p_getbtn, #TLE_batch_getbtn, #TLE_bt_getbtn").hide();
580 $("div.TLE_get_btnbox").click(function(e){e.stopPropagation();});
586 var ARIA2 = (function() {
587 var jsonrpc_version = '2.0';
589 function get_auth(url) {
590 return url.match(/^(?:(?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(?:\/\/)?(?:([^:@]*(?::[^:@]*)?)?@)?/)[1];
593 function request(jsonrpc_path, method, params) {
594 var xhr = new XMLHttpRequest();
595 var auth = get_auth(jsonrpc_path);
596 jsonrpc_path = jsonrpc_path.replace(/^((?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(\/\/)?(?:(?:[^:@]*(?::[^:@]*)?)?@)?(.*)/, '$1$2$3'); // auth string not allowed in url for firefox
599 jsonrpc: jsonrpc_version,
601 id: (new Date()).getTime().toString(),
603 if (params) request_obj['params'] = params;
604 if (auth && auth.indexOf('token:') == 0) params.unshift(auth);
606 xhr.open("POST", jsonrpc_path+"?tm="+(new Date()).getTime().toString(), true);
607 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
608 if (auth && auth.indexOf('token:') != 0) {
609 xhr.setRequestHeader("Authorization", "Basic "+btoa(auth));
611 xhr.send(JSON.stringify(request_obj));
614 return function(jsonrpc_path) {
615 this.jsonrpc_path = jsonrpc_path;
616 this.addUri = function (uri, options) {
617 request(this.jsonrpc_path, 'aria2.addUri', [[uri, ], options]);
624 function tle_lx3_wrapper() {
625 // vim: set et sw=2 ts=2 sts=2 ff=unix fenc=utf8:
626 // Author: Binux<i@binux.me>
628 // Created on 2013-12-27 23:00:34
633 '复制链接': function(todown) {
634 //console.log(todown);
635 var str = '<ul style="max-height: 300px; overflow-y: scroll; overflow-x: hidden;">';
636 $.each(todown.tasklist, function(n, task) {
637 $.each(task.filelist, function(l, file) {
638 if (!file.downurl) return;
639 str += '<li><a href="'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'" target="_blank">'+file.title+'</a></li>';
643 TLE.window_pop('复制选中的链接 > <a href="'+"data:text/html;charset=utf-8,"+encodeURIComponent(str)+'" target="_blank">在新窗口中打开</a>', str);
645 'Aria2': function(todown) {
646 //console.log(todown);
648 $.each(todown.tasklist, function(n, task) {
649 $.each(task.filelist, function(l, file) {
650 if (!file.downurl) return;
651 var filepath = TLE.safe_title(file.title);
652 if (task.tasktype === 0 && task.filelist.length > 1)
653 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
654 str += "aria2c -c -s10 -x10 --out "+TLE.escape_command(filepath)+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
657 TLE.text_pop("aria2 download command", str);
659 'wget': function(todown) {
660 //console.log(todown);
662 $.each(todown.tasklist, function(n, task) {
663 $.each(task.filelist, function(l, file) {
664 if (!file.downurl) return;
665 str += "wget -c -O "+TLE.escape_command(TLE.safe_title(file.title))+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
668 TLE.text_pop("wget download command", str);
670 "YAAW": function(todown) {
671 if (TLE.getConfig("TLE_aria2_jsonrpc")) {
672 TLE.tip("添加中...到YAAW界面查看是否添加成功");
673 var aria2 = new ARIA2(TLE.getConfig("TLE_aria2_jsonrpc"));
674 $.each(todown.tasklist, function(n, task) {
675 $.each(task.filelist, function(l, file) {
676 if (!file.downurl) return;
677 var filepath = TLE.safe_title(file.title);
678 if (task.tasktype === 0 && task.filelist.length > 1)
679 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
680 aria2.addUri(file.downurl, {out: filepath, header: 'Cookie: gdriveid='+todown.gdriveid});
685 TLE.tip("尚未设置Aria2 JSONRPC地址", 5);
688 'Aria2导出': function(todown) {
689 //console.log(todown);
691 $.each(todown.tasklist, function(n, task) {
692 $.each(task.filelist, function(l, file) {
693 if (!file.downurl) return;
694 var filepath = TLE.safe_title(file.title);
695 if (task.tasktype === 0 && task.filelist.length > 1)
696 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
697 str += file.downurl+'\r\n out='+filepath+'\r\n header=Cookie: gdriveid='+todown.gdriveid+'\r\n continue=true\r\n max-connection-per-server=5\r\n split=10\r\n parameterized-uri=true\r\n\r\n';
700 TLE.file_pop("Aria2导出文件下载", str, "aria2.down");
702 'IDM导出': function(todown) {
703 //console.log(todown);
705 $.each(todown.tasklist, function(n, task) {
706 $.each(task.filelist, function(l, file) {
707 if (!file.downurl) return;
708 str += '<\r\n'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'\r\ncookie: gdriveid='+todown.gdriveid+'\r\n>\r\n';
711 TLE.file_pop("IDM导出文件下载", str, "idm.ef2");
713 'Orbit导出': function(todown) {
714 //console.log(todown);
716 $.each(todown.tasklist, function(n, task) {
717 $.each(task.filelist, function(l, file) {
718 if (!file.downurl) return;
719 str += TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'|'+TLE.safe_title(file.title.replace("|", "_"))+'||gdriveid='+todown.gdriveid+'\r\n';
722 TLE.file_pop("Orbit导出文件下载", str, "orbit.olt");
724 'eagleget导出': function(todown) {
725 var ret = {tasks: []};
726 $.each(todown.tasklist, function(n, task) {
727 $.each(task.filelist, function(l, file) {
728 if (!file.downurl) return;
730 cookie: 'gdriveid='+todown.gdriveid,
731 fname: TLE.safe_title(file.title),
732 url: TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))
736 TLE.file_pop("Eagleget导出文件下载(test)", JSON.stringify(ret), "eagleget.eg");
741 function get_taskinfo(taskid) {
743 taskname: $("#tr_c"+taskid+" .title .w_title").attr("title"),
744 title: $("#tr_c"+taskid+" .title .w_title").attr("title"),
745 f_url: $("#f_url"+taskid).val(),
746 downurl: $("#dl_url"+taskid).val(),
747 cid: $("#dcid"+taskid).val(),
748 gcid: $("#gcid"+taskid).val(),
749 size: parseInt($("#ysfilesize"+taskid).val()),
750 tasktype: parseInt($("#d_tasktype"+taskid).val()),
751 status: $("#d_status"+taskid).val(),
754 function get_bt_taskinfo(taskid) {
756 title: $("#bt_taskname"+taskid).val(),
757 f_url: $("#bturl"+taskid).val(),
758 downurl: $("#btdownurl"+taskid).val(),
759 cid: $("#btcid"+taskid).val(),
760 gcid: $("#btgcid"+taskid).val(),
761 size: $("#bt_filesize"+taskid).val(),
762 status: $("#btd_status"+taskid).val(),
766 function build_bt_taskinfo(info, rdata) {
768 'taskname': info.taskname,
771 'size': parseInt(info.ysfilesize),
772 'tasktype': parseInt(info.d_tasktype),
773 'status': info.d_status,
776 $.each(rdata, function(n, e) {
780 'downurl': e.downurl,
783 'size': parseInt(e.filesize),
786 taskinfo['filelist'] = filelist;
790 TLE.safe_title = function safe_title(title) {
791 return title.replace(/[\\\|\:\*\"\?\<\>]/g,"_");
794 TLE.bt_down = function(_this, _do) {
795 var ck = document.getElementsByName("bt_list_ck");
797 $.each(ck, function(n, e) {
798 if (e.checked == false) return;
799 var fid = e.getAttribute("_i");
801 'title': $("#bt_taskname"+fid).val(),
802 'url': $("#bturl"+fid).val(),
803 'downurl': $("#btdownurl"+fid).val(),
804 'cid': $("#btcid"+fid).val(),
805 'gcid': $("#btgcid"+fid).val(),
806 'filesize': $("#bt_filesize"+fid).val(),
810 var taskid = $("#view_bt_taskid").val();
811 var info = get_taskinfo($("#tr_c"+taskid));
814 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
815 todown.tasklist = {};
816 todown.tasklist[taskid] = build_bt_taskinfo(info, files);
817 //console.log(todown);
821 //console.log("bt_down");
824 TLE.text_pop = function(title, content) {
825 content = $('<div></div>').text(content).html()
826 content = '<textarea style="width: 100%; height: 260px;">'+content+'</textarea>'
827 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
828 //onHide: function() { $(document.body).click(); },
831 TLE.file_pop = function(title, content, filename) {
832 var url = "data:text/html;charset=utf-8,"+encodeURIComponent(content);
834 $('<a href="'+url+'" target="_blank" style="display:none;" download="'+filename+'"></a>').appendTo('body').get(0).click();
836 var content = '<div style="width: 100%; height: 100px;">'
837 +'<div style="padding: 30px 0 0 30%;">'
838 +'<a href="'+url+'" target="_blank" title="右键另存为" class="pop_btn" download="'+filename+'"><span><em class="TLE_icdwlocal">导出文件</em></span></a>'
839 +(isChrome ? '' : '(右键另存为'+filename+')')
842 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
843 //onHide: function() { $(document.body).click(); },
847 TLE.window_pop = function(title, content) {
848 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
849 //onHide: function() { $(document.body).click(); },
852 TLE.tip = function(content, time) {
853 TS2.show(content, time);
855 TLE.hide_tip = function() {
859 TLE.multiple_server_fix = function(url) {
860 return "'"+url.replace("gdl", "'{gdl,dl.{f,g,h,i,twin}}'")+"'";
863 function encode_utf8(s) {
864 return unescape( encodeURIComponent( s ) );
866 function to_hex(num) {
867 var s = num.toString(16);
873 var thunder_filename_mask = [0x61, 0x31, 0xe4, 0x5f, 0x00, 0x00, 0x00, 0x00];
874 function thunder_filename_encode(filename) {
875 var result = ["01", ];
876 $.each(encode_utf8(filename), function(i, n) {
877 result.push(to_hex(n.charCodeAt(0)^thunder_filename_mask[i%8]).toUpperCase())
879 while (result.length % 8 != 1) {
880 result.push(to_hex(thunder_filename_mask[(result.length-1)%8]).toUpperCase());
882 return result.join("");
885 TLE.url_rewrite = function(url, filename) {
886 url = url.replace(/&n=\w+/, "&n="+thunder_filename_encode(filename));
890 var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
891 TLE.escape_command = function(str) {
893 for (var i = 0; i < str.length; i++) {
894 if (alpha.indexOf(str[i]) == -1)
895 result += "\\"+str[i];
903 TLE.getConfig = function(key) {
904 if (window.localStorage) {
905 return window.localStorage.getItem(key) || "";
907 return getCookie(key);
910 TLE.setConfig = function(key, value) {
911 if (window.localStorage) {
912 window.localStorage.setItem(key, value);
914 setGdCookie(key, value, 86400*365);
918 if (TLE.getConfig("TLE_exporter") == "") {
920 for (var key in TLE.exporter) {
923 TLE.setConfig("TLE_exporter", exporters.join("|"));
928 $("head").append('<style>'
929 +'#TLE_setting { padding: 10px 20px 20px 20px; }'
930 +'#TLE_setting span { padding-left: 1em; }'
931 +'#TLE_setting li { margin-top: 0.5em; }'
932 +'#TLE_exporter_select { padding: 10px 20px 20px 20px; }'
935 $("body").append('<div id="TLE_text_pop" class="lixian_pop_wp pop_w400" style="display:none;margin:0;"></div>');
936 $("body").append('<textarea id="TLE_text_tpl" style="display: none;"></textarea>');
937 $("#TLE_text_tpl").text('<div class="lixian_pop">'
938 +'<div class="l_p_hd">'
941 +'<div class="l_p_bd">'
944 +'<a class="pop_close" title="关闭浮层" close="1" id="close">关闭浮层</a>'
947 $("#view_down_bar ul").prepend('<li> <a href="#" id="TLE_setting_anchor">TLE设置</a></li>');
948 $("#TLE_setting_anchor").on("click", function() {
949 var content = '<div id="TLE_setting"><ul>'
950 +'<li><b>启用以下导出器</b></li>'
952 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
954 for (var name in TLE.exporter) {
955 str += '<span class="rw_col"><input type="checkbox" class="TLE_setting_ck" name="TLE_ck_'+name+'" '+(enabled_exporter.indexOf(name) == -1 ? "" : "checked")+' />'+name+'</span>';
959 +'<li><b>Aria2 JSON-RPC Path</b></li>'
960 +'<li>Path: <input type="text" id="TLE_aria2_jsonrpc" style="width: 350px" value="'+TLE.getConfig("TLE_aria2_jsonrpc")+'"/></li>'
964 +'<div class="l_p_ft"><div class="btn_area"><a id="TLE_setting_ok" class="pop_btn">确定</a> <a close="1" class="pop_btn pop_btn_cancel">取消</a></div></div>';
965 $("#TLE_text_pop").tpl("TLE_text_tpl", {title: "Thunder Lixian Exporter 设定", content: content}).show().pop();
966 $("#TLE_setting_ok").on("click", function() {
967 var enabled_exporter = [];
968 $(".TLE_setting_ck").each(function(n, e) {
969 if (e.checked) enabled_exporter.push(e.name.replace(/^TLE_ck_/, ""));
971 var config_str = (enabled_exporter.length == 0) ? "_" : enabled_exporter.join("|");
972 var jsonrpc_path = $("#TLE_aria2_jsonrpc").val();
973 if (TLE.getConfig("TLE_exporter") != config_str || TLE.getConfig("TLE_aria2_jsonrpc") != jsonrpc_path) {
974 TLE.setConfig("TLE_exporter", config_str);
975 TLE.setConfig("TLE_aria2_jsonrpc", jsonrpc_path);
977 $("a.pop_close:visible").click();
982 function exporter_anchors() {
983 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
985 $.each(TLE.exporter, function(n, f) {
986 if (enabled_exporter.indexOf(n) == -1) return;
987 str+=('<li><a href="#" title="'+n+'" onclick="TLE.exporter[\''+n+'\'](TLE.todown);return false;">'+n+'</a></li>');
991 function show_exporter_selector() {
992 $("#TLE_text_pop").tpl("TLE_text_tpl", {title: "您正在使用Thunder Lixian Exporter",
993 content: '<ul id="TLE_exporter_select">'
999 window.thunder_download = function(taskid, type) {
1001 TLE.todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
1005 taskname: $("#bt_info_list .title .w").text(),
1013 filelist.push(get_bt_taskinfo(taskid));
1014 taskinfo['filelist'] = filelist;
1015 TLE.todown.tasklist = {};
1016 TLE.todown.tasklist['0'] = taskinfo;
1019 var taskinfo = get_taskinfo(taskid);
1021 filelist.push(get_taskinfo(taskid));
1022 taskinfo['filelist'] = filelist;
1023 TLE.todown.tasklist = {};
1024 TLE.todown.tasklist[taskid] = taskinfo;
1026 show_exporter_selector();
1028 window.bt_task_down = function(cid, taskid) {
1030 batch_down_all_f([taskid, ]);
1032 window.batch_down_all_f = function(taskids) {
1036 $("span[name=ck][checked]").each(function(n, e) {
1037 taskids.push($(e).attr("value"));
1041 var bt_task_list = [], normal_task_list = [];
1042 $.each(taskids, function(n, taskid) {
1043 var d_status = $("#d_status"+taskid).val();
1044 var d_tasktype = parseInt($("#d_tasktype"+taskid).val());
1045 var d_flag = $("#dflag"+taskid).val();
1046 if (d_flag != 4 && d_status == 2) {
1047 if (d_tasktype == 0) {
1048 bt_task_list.push(taskid);
1050 normal_task_list.push(taskid);
1055 if (bt_task_list.length) {
1057 $.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+bt_task_list.join(",")+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
1060 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
1061 todown.tasklist = {};
1062 $.each(data['Result'], function(n, e) {
1063 var taskinfo = get_taskinfo(n);
1065 $.each(e, function(n, e) {
1072 size: parseInt(e.filesize),
1075 taskinfo.filelist = filelist;
1076 todown.tasklist[n] = taskinfo;
1078 $.each(normal_task_list, function(n, e) {
1079 var taskinfo = get_taskinfo(e);
1080 taskinfo['filelist'] = taskinfo;
1081 todown.tasklist[e] = taskinfo;
1083 TLE.todown = todown;
1084 show_exporter_selector();
1088 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
1089 todown.tasklist = {};
1090 $.each(normal_task_list, function(n, e) {
1091 var taskinfo = get_taskinfo(e);
1092 taskinfo['filelist'] = taskinfo;
1093 todown.tasklist[e] = taskinfo;
1095 TLE.todown = todown;
1096 show_exporter_selector();
1099 window.batch_down_bt = function() {
1101 $("span[name=bt_list_ck][checked]").each(function(n, e) {
1102 var taskid = $(e).attr("value");
1103 if ($("#btd_status"+taskid).val() == 2)
1104 taskids.push(taskid);
1108 TLE.todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
1110 taskname: $("#bt_info_list .title .w").text(),
1118 $.each(taskids, function(n, e) {
1119 filelist.push(get_bt_taskinfo(e));
1121 taskinfo['filelist'] = filelist;
1122 TLE.todown.tasklist = {};
1123 TLE.todown.tasklist['0'] = taskinfo;
1124 show_exporter_selector();
1131 var ARIA2 = (function() {
1132 var jsonrpc_version = '2.0';
1134 function get_auth(url) {
1135 return url.match(/^(?:(?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(?:\/\/)?(?:([^:@]*(?::[^:@]*)?)?@)?/)[1];
1138 function request(jsonrpc_path, method, params) {
1139 var xhr = new XMLHttpRequest();
1140 var auth = get_auth(jsonrpc_path);
1141 jsonrpc_path = jsonrpc_path.replace(/^((?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(\/\/)?(?:(?:[^:@]*(?::[^:@]*)?)?@)?(.*)/, '$1$2$3'); // auth string not allowed in url for firefox
1144 jsonrpc: jsonrpc_version,
1146 id: (new Date()).getTime().toString(),
1148 if (params) request_obj['params'] = params;
1149 if (auth && auth.indexOf('token:') == 0) params.unshift(auth);
1151 xhr.open("POST", jsonrpc_path+"?tm="+(new Date()).getTime().toString(), true);
1152 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
1153 if (auth && auth.indexOf('token:') != 0) {
1154 xhr.setRequestHeader("Authorization", "Basic "+btoa(auth));
1156 xhr.send(JSON.stringify(request_obj));
1159 return function(jsonrpc_path) {
1160 this.jsonrpc_path = jsonrpc_path;
1161 this.addUri = function (uri, options) {
1162 request(this.jsonrpc_path, 'aria2.addUri', [[uri, ], options]);
1169 function onload(func) {
1170 if (document.readyState === "complete") {
1173 window.addEventListener('load', func);
1177 var script = document.createElement('script');
1178 script.id = "TLE_script";
1179 if (location.host == "dynamic.cloud.vip.xunlei.com") {
1180 script.appendChild(document.createTextNode('('+ tle_wrapper +')();'));
1182 script.appendChild(document.createTextNode('('+ tle_lx3_wrapper +')();'));
1184 (document.body || document.head || document.documentElement).appendChild(script);