1 // vim: set et sw=2 ts=2 sts=2 ff=unix fenc=utf8:
2 // Author: Binux<root@binux.me>
4 // Created on Fri 20 Jul 2012 11:43:22 AM CST
9 '复制链接': function(todown) {
10 //console.log(todown);
11 var str = '<ul style="max-height: 300px; overflow-y: scroll; overflow-x: hidden;">';
12 $.each(todown.tasklist, function(n, task) {
13 $.each(task.filelist, function(l, file) {
14 if (!file.downurl) return;
15 str += '<li><a href="'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'" target="_blank">'+file.title+'</a></li>';
19 $("#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({
20 onHide: function() { $(document.body).click(); },
23 'Aria2': function(todown) {
24 //console.log(todown);
26 $.each(todown.tasklist, function(n, task) {
27 $.each(task.filelist, function(l, file) {
28 if (!file.downurl) return;
29 var filepath = TLE.safe_title(file.title);
30 if (task.tasktype == 0 && task.filelist.length > 1)
31 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
32 str += "aria2c -c -s10 -x10 --out "+TLE.escape_command(filepath)+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
35 TLE.text_pop("aria2 download command", str);
37 'wget': function(todown) {
38 //console.log(todown);
40 $.each(todown.tasklist, function(n, task) {
41 $.each(task.filelist, function(l, file) {
42 if (!file.downurl) return;
43 str += "wget -c -O "+TLE.escape_command(TLE.safe_title(file.title))+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
46 TLE.text_pop("wget download command", str);
48 "YAAW": function(todown) {
49 if (TLE.getConfig("TLE_aria2_jsonrpc")) {
50 show_tip("添加中...到YAAW界面查看是否添加成功");
51 var aria2 = new ARIA2(TLE.getConfig("TLE_aria2_jsonrpc"));
52 $.each(todown.tasklist, function(n, task) {
53 $.each(task.filelist, function(l, file) {
54 if (!file.downurl) return;
55 var filepath = TLE.safe_title(file.title);
56 if (task.tasktype == 0 && task.filelist.length > 1)
57 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
58 aria2.addUri(file.downurl, {out: filepath, header: 'Cookie: gdriveid='+todown.gdriveid});
63 show_tip("尚未设置Aria2 JSONRPC地址");
67 'Aria2导出': function(todown) {
68 //console.log(todown);
70 $.each(todown.tasklist, function(n, task) {
71 $.each(task.filelist, function(l, file) {
72 if (!file.downurl) return;
73 var filepath = TLE.safe_title(file.title);
74 if (task.tasktype == 0 && task.filelist.length > 1)
75 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
76 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';
79 TLE.file_pop("Aria2导出文件下载", str, "aria2.down");
81 'IDM导出': function(todown) {
82 //console.log(todown);
84 $.each(todown.tasklist, function(n, task) {
85 $.each(task.filelist, function(l, file) {
86 if (!file.downurl) return;
87 str += '<\r\n'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'\r\ncookie: gdriveid='+todown.gdriveid+'\r\n>\r\n'
90 TLE.file_pop("IDM导出文件下载", str, "idm.ef2");
92 'Orbit导出': function(todown) {
93 //console.log(todown);
95 $.each(todown.tasklist, function(n, task) {
96 $.each(task.filelist, function(l, file) {
97 if (!file.downurl) return;
98 str += TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'|'+TLE.safe_title(file.title.replace("|", "_"))+'||gdriveid='+todown.gdriveid+'\r\n'
101 TLE.file_pop("Orbit导出文件下载", str, "orbit.olt");
103 'eagleget': function(todown) {
104 var ret = {tasks: []};
105 $.each(todown.tasklist, function(n, task) {
106 $.each(task.filelist, function(l, file) {
107 if (!file.downurl) return;
109 cookie: 'gdriveid='+todown.gdriveid,
110 fname: TLE.safe_title(file.title),
111 url: TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))
115 TLE.file_pop("Eagleget导出文件下载(test)", JSON.stringify(ret), "eagleget.eg");
120 function get_taskinfo(p) {
121 var taskid = p.attr("taskid");
123 p.find("input").each(function(n, e) {
124 var key = e.getAttribute("id").replace(taskid, "");
125 info[key] = e.getAttribute("value");
130 function build_normal_taskinfo(info) {
132 'taskname': info.taskname || info.cloud_taskname,
134 'cid': info.dcid || info.cloud_cid,
135 'size': parseInt(info.ysfilesize),
136 'tasktype': info.d_tasktype,
137 'status': info.d_status,
141 'title': info.taskname || info.cloud_taskname,
143 'downurl': info.dl_url || info.cloud_dl_url,
144 'cid': info.dcid || info.cloud_cid,
146 'size': parseInt(info.ysfilesize),
148 taskinfo['filelist'] = filelist;
152 function build_bt_taskinfo(info, rdata) {
154 'taskname': info.taskname,
157 'size': parseInt(info.ysfilesize),
158 'tasktype': info.d_tasktype,
159 'status': info.d_status,
162 $.each(rdata, function(n, e) {
166 'downurl': e.downurl,
169 'size': parseInt(e.filesize),
172 taskinfo['filelist'] = filelist;
176 TLE.safe_title = function safe_title(title) {
177 return title.replace(/[\\\|\:\*\"\?\<\>]/g,"_");
180 TLE.down = function(_this, _do) {
181 var p = $(_this).parents(".rw_list");
182 var info = get_taskinfo(p);
185 if (info.d_tasktype == "0") { //bt task
187 $.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+info.input+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
190 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
191 todown.tasklist = {};
192 todown.tasklist[info.input] = build_bt_taskinfo(info, data['Result'][info.input]);
197 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
198 todown.tasklist = {};
199 todown.tasklist[info.input] = build_normal_taskinfo(info);
204 TLE.batch_down = function(_this, _do) {
205 var ck = document.getElementsByName("ck");
206 var bt_task_list = [];
207 var normal_task_list = [];
208 $.each(ck, function(n, e) {
209 if (e.checked == false) return;
211 var taskid = e.value;
212 var d_status = $("#d_status"+taskid).val();
213 var d_tasktype = $("#d_tasktype"+taskid).val();
214 var d_flag = $("#dflag"+taskid).val();
215 if (d_flag != 4 && d_status == 2) {
216 if (d_tasktype == 0) {
217 bt_task_list.push(taskid);
219 normal_task_list.push(taskid);
224 if (bt_task_list.length) {
226 $.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+bt_task_list.join(",")+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
229 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
230 todown.tasklist = {};
231 $.each(data['Result'], function(n, e) {
232 var info = get_taskinfo($("#tr_c"+n));
233 todown.tasklist[n] = build_bt_taskinfo(info, e);
235 $.each(normal_task_list, function(n, e) {
236 var info = get_taskinfo($("#tr_c"+e));
237 todown.tasklist[e] = build_normal_taskinfo(info);
243 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
244 todown.tasklist = {};
245 $.each(normal_task_list, function(n, e) {
246 var info = get_taskinfo($("#tr_c"+e));
247 todown.tasklist[e] = build_normal_taskinfo(info);
253 TLE.bt_down = function(_this, _do) {
254 var ck = document.getElementsByName("bt_list_ck");
256 $.each(ck, function(n, e) {
257 if (e.checked == false) return;
258 var fid = e.getAttribute("_i");
260 'title': $("#bt_taskname"+fid).val(),
261 'url': $("#bturl"+fid).val(),
262 'downurl': $("#btdownurl"+fid).val(),
263 'cid': $("#btcid"+fid).val(),
264 'gcid': $("#btgcid"+fid).val(),
265 'filesize': $("#bt_filesize"+fid).val(),
269 var taskid = $("#view_bt_taskid").val();
270 var info = get_taskinfo($("#tr_c"+taskid));
273 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
274 todown.tasklist = {};
275 todown.tasklist[taskid] = build_bt_taskinfo(info, files);
276 //console.log(todown);
280 //console.log("bt_down");
283 TLE.bt_down_one = function(_this, _do) {
285 var fid = $(_this).parents(".rw_list").attr("i");
287 'title': $("#bt_taskname"+fid).val(),
288 'url': $("#bturl"+fid).val(),
289 'downurl': $("#btdownurl"+fid).val(),
290 'cid': $("#btcid"+fid).val(),
291 'gcid': $("#btgcid"+fid).val(),
292 'filesize': $("#bt_filesize"+fid).val(),
295 var taskid = $("#view_bt_taskid").val();
296 var info = get_taskinfo($("#tr_c"+taskid));
299 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
300 todown.tasklist = {};
301 todown.tasklist[taskid] = build_bt_taskinfo(info, files);
302 //console.log(todown);
306 //console.log("bt_down");
309 TLE.getbtn = function(_this) {
310 $(_this).parents(".TLE_get_btnbox").find(".TLE_p_getbtn").toggle();
311 close_rightmenu_layer();
315 TLE.text_pop = function(title, content) {
316 content = $('<div></div>').text(content).html()
317 content = '<textarea style="width: 100%; height: 260px;">'+content+'</textarea>'
318 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
319 onHide: function() { $(document.body).click(); },
322 TLE.file_pop = function(title, content, filename) {
323 var url = "data:text/html;charset=utf-8,"+encodeURIComponent(content);
324 var content = '<div style="width: 100%; height: 100px;">'
325 +'<div style="padding: 30px 0 0 30%;">'
326 +'<a href="'+url+'" target="_blank" title="右键另存为" class="TLE_down_btn" download="'+filename+'"><span><em class="TLE_icdwlocal">导出文件</em></span></a>'
327 +(isChrome ? '' : '(右键另存为'+filename+')')
330 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
331 onHide: function() { $(document.body).click(); },
334 TLE.window_pop = function(title, content) {
335 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
336 onHide: function() { $(document.body).click(); },
340 TLE.multiple_server_fix = function(url) {
341 return "'"+url.replace("gdl", "'{gdl,dl.{f,g,h,i,twin}}'")+"'";
344 function encode_utf8(s) {
345 return unescape( encodeURIComponent( s ) );
347 function to_hex(num) {
348 var s = num.toString(16);
354 var thunder_filename_mask = [0x61, 0x31, 0xe4, 0x5f, 0x00, 0x00, 0x00, 0x00];
355 function thunder_filename_encode(filename) {
356 var result = ["01", ];
357 $.each(encode_utf8(filename), function(i, n) {
358 result.push(to_hex(n.charCodeAt(0)^thunder_filename_mask[i%8]).toUpperCase())
360 while (result.length % 8 != 1) {
361 result.push(to_hex(thunder_filename_mask[(result.length-1)%8]).toUpperCase());
363 return result.join("");
366 TLE.url_rewrite = function(url, filename) {
367 url = url.replace(/&n=\w+/, "&n="+thunder_filename_encode(filename));
371 var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
372 TLE.escape_command = function(str) {
374 for (var i = 0; i < str.length; i++) {
375 if (alpha.indexOf(str[i]) == -1)
376 result += "\\"+str[i];
384 TLE.getConfig = function(key) {
385 if (window.localStorage) {
386 return window.localStorage.getItem(key) || "";
388 return getCookie(key);
391 TLE.setConfig = function(key, value) {
392 if (window.localStorage) {
393 window.localStorage.setItem(key, value);
395 setGdCookie(key, value, 86400*365);
399 if (TLE.getConfig("TLE_exporter") == "") {
401 for (var key in TLE.exporter) {
404 TLE.setConfig("TLE_exporter", exporters.join("|"));
409 $("head").append('<style>'
410 +'.TLE_get_btnbox {position:relative; float:left; z-index:11}'
411 +'.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;}'
412 +'.TLE_getbtn a {display:block; height:22px; line-height:22px; padding-left:18px}'
413 +'.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}'
414 +'.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}'
415 +'.TLE_get_btnbox .TLE_link_gettxt {float:left; display: inline ; width:53px; text-align:center; padding-left:24px; color:#000}'
416 +'.TLE_get_btnbox .TLE_link_gettxt:hover {text-decoration:none}'
417 +'.rwbox .rwset .TLE_link_getic {float:left; display:block; width:20px;height:22px;}'
418 +'.TLE_hiden {display: none; }'
419 +'.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; }'
420 +'.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; }'
421 +'.TLE_down_btn:active {background-position:0 -28px; }'
422 +'.TLE_down_btn:active span {background-position:right -28px;}'
423 +'.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; }'
425 +'.rwbtn.ic_redownloca { display: none !important; }'
426 +'.menu { width: 700px !important; }'
428 +'.rwset {width:530px;}'
431 $("body").append('<div id="TLE_text_pop" class="pop_rwbox" style="display: none;margin: 0;"></div>');
432 $("body").append('<textarea id="TLE_text_tpl" style="display: none;"></textarea>');
433 $("#TLE_text_tpl").text('<div class="p_rw_pop">'
434 +'<div class="tt_box onlytitle">'
437 +'<div class="psc_info">'
440 +'<a href="#" class="close" title="关闭">关闭</a>'
442 $("#setting_main_tpl").text($("#setting_main_tpl").text().replace(/(<\/div>\s+<div class="btnin">)/,
443 '<div class="doline mag01"></div>'
444 +'<h3 style="background-position: 0 -180px;">Thunder Lixian Exporter 设定</h3>'
446 +'<li><b>启用以下导出器</b></li>'
448 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
450 for (var name in TLE.exporter) {
451 str += '<span class="rw_col"><input type="checkbox" class="TLE_setting_ck" name="TLE_ck_'+name+'" '+(enabled_exporter.indexOf(name) == -1 ? "" : "checked")+' />'+name+'</span>';
455 +'<li><b>Aria2 JSON-RPC Path</b></li>'
456 +'<li>Path: <input type="text" id="TLE_aria2_jsonrpc" style="width: 350px" value="'+TLE.getConfig("TLE_aria2_jsonrpc")+'"/></li>'
459 $(".n_vip").after('<div class="zh_info"><em onclick="setting.show()" class="sys_set"></em></div>');
460 var _set_notice_submit = set_notice_submit;
461 set_notice_submit = function(f) {
462 _set_notice_submit(f);
463 var enabled_exporter = [];
464 $(".TLE_setting_ck").each(function(n, e) {
465 if (e.checked) enabled_exporter.push(e.name.replace(/^TLE_ck_/, ""));
467 var config_str = (enabled_exporter.length == 0) ? "_" : enabled_exporter.join("|");
468 var jsonrpc_path = $("#TLE_aria2_jsonrpc").val();
469 if (TLE.getConfig("TLE_exporter") != config_str || TLE.getConfig("TLE_aria2_jsonrpc") != jsonrpc_path) {
470 TLE.setConfig("TLE_exporter", config_str);
471 TLE.setConfig("TLE_aria2_jsonrpc", jsonrpc_path);
473 setTimeout(function(){
475 location.reload(true);
480 function exporter_anchors(type) {
481 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
483 $.each(TLE.exporter, function(n, f) {
484 if (enabled_exporter.indexOf(n) == -1) return;
485 str+=('<a href="#" title="'+n+'" onmouseover="this.className=\'sel_on\'" onmouseout="this.className=\'\'" onclick="'+type+'(this, TLE.exporter[\''+n+'\'])">'+n+'</a>');
490 $(".rwbtn.ic_redownloca").each(function(n, e) {
491 $(e).after('<div class="TLE_get_btnbox">'
492 + '<span class="TLE_getlink">'
493 + '<a href="#" class="TLE_link_gettxt TLE-down-text" style="padding-left: 20px; width: 57px;" onclick='+e.getAttribute("onclick")+'>取回本地</a>'
494 + '<a href="#" class="TLE_link_getic TLE-down-btn" onclick="return TLE.getbtn(this);"></a>'
496 + '<div class="TLE_p_getbtn TLE_getbtn" style="display: none;">'
497 + exporter_anchors("TLE.down")
503 $("#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>')
504 .parents(".main_link").append(
505 '<div id="TLE_batch_getbtn" class="TLE_getbtn" style="top: 30px; display:none;">'
506 + exporter_anchors("TLE.batch_down")
508 var _task_check_click = task_check_click;
509 task_check_click = function() {
511 if ($("#li_task_down,#li_task_download").hasClass("noit")) {
512 $("#TLE_batch_down").addClass("noit").unbind("click");
514 $("#TLE_batch_down").removeClass("noit").unbind("click").click(function() {
515 $("#TLE_batch_getbtn").css("left", $("#TLE_batch_down").position().left);
516 $("#TLE_batch_getbtn").toggle();
520 //console.log("task_check_click called");
522 $('input[name=ck],input#ckbutton').click(task_check_click);
525 $("#view_bt_list_nav_tpl").text($("#view_bt_list_nav_tpl").text().replace('取回本地</em></span></a>',
526 '取回本地</em></span></a>'
527 +'<a href="#" class="btn_m noit" title="批量导出" id="TLE_bt_down"><span><em class="icdwlocal">批量导出</em></span></a>'
528 +'<div id="TLE_bt_getbtn" class="TLE_getbtn" style="top: 30px; display:none;">'
529 + exporter_anchors("TLE.bt_down")
531 $("#view_bt_list_tpl").text($("#view_bt_list_tpl").text().replace('ic_redownloca" title="">取回本地</a>',
532 'ic_redownloca" title="">取回本地</a>'
533 +'<div class="TLE_get_btnbox">'
534 + '<span class="TLE_getlink">'
535 + '<a href="#" class="TLE_link_gettxt TLE-down-text" style="padding-left: 20px; width: 57px;" onclick="thunder_download($[p.i],1);return false;">取回本地</a>'
536 + '<a href="#" class="TLE_link_getic TLE-down-btn" onclick="return TLE.getbtn(this);"></a>'
538 + '<div class="TLE_p_getbtn TLE_getbtn" style="display: none;">'
539 + exporter_anchors("TLE.bt_down_one")
542 var _bt_view_nav = bt_view_nav;
543 bt_view_nav = function() {
545 if ($("#view_bt_list_nav_down").hasClass("noit")) {
546 $("#TLE_bt_down").addClass("noit").unbind("click");
548 $("#TLE_bt_down").removeClass("noit").unbind("click").click(function() {
549 $("#TLE_bt_getbtn").css("left", $("#TLE_bt_down").position().left);
550 $("#TLE_bt_getbtn").toggle();
554 $("#TLE_bt_getbtn").hide();
555 //console.log("bt_view_nav called");
559 $(document.body).bind("click",function(){
560 $("div.TLE_p_getbtn, #TLE_batch_getbtn, #TLE_bt_getbtn").hide();
562 $("div.rw_list").click(function(e){
563 $("div.TLE_p_getbtn, #TLE_batch_getbtn, #TLE_bt_getbtn").hide();
565 $("div.TLE_get_btnbox").click(function(e){e.stopPropagation();});
571 var ARIA2 = (function() {
572 var jsonrpc_version = '2.0';
574 function get_auth(url) {
575 return url.match(/^(?:(?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(?:\/\/)?(?:([^:@]*(?::[^:@]*)?)?@)?/)[1];
578 function request(jsonrpc_path, method, params) {
579 var xhr = new XMLHttpRequest();
580 var auth = get_auth(jsonrpc_path);
581 jsonrpc_path = jsonrpc_path.replace(/^((?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(\/\/)?(?:(?:[^:@]*(?::[^:@]*)?)?@)?(.*)/, '$1$2$3'); // auth string not allowed in url for firefox
584 jsonrpc: jsonrpc_version,
586 id: (new Date()).getTime().toString(),
588 if (params) request_obj['params'] = params;
589 if (auth && auth.indexOf('token:') == 0) params.unshift(auth);
591 xhr.open("POST", jsonrpc_path+"?tm="+(new Date()).getTime().toString(), true);
592 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
593 if (auth && auth.indexOf('token:') != 0) {
594 xhr.setRequestHeader("Authorization", "Basic "+btoa(auth));
596 xhr.send(JSON.stringify(request_obj));
599 return function(jsonrpc_path) {
600 this.jsonrpc_path = jsonrpc_path;
601 this.addUri = function (uri, options) {
602 request(this.jsonrpc_path, 'aria2.addUri', [[uri, ], options]);