1 // vim: set et sw=2 ts=2 sts=2 ff=unix fenc=utf8:
2 // Author: Binux<i@binux.me>
4 // Created on 2013-12-27 23:00:34
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.window_pop('复制选中的链接 > <a href="'+"data:text/html;charset=utf-8,"+encodeURIComponent(str)+'" target="_blank">在新窗口中打开</a>', str);
21 'Aria2': function(todown) {
22 //console.log(todown);
24 $.each(todown.tasklist, function(n, task) {
25 $.each(task.filelist, function(l, file) {
26 if (!file.downurl) return;
27 var filepath = TLE.safe_title(file.title);
28 if (task.tasktype === 0 && task.filelist.length > 1)
29 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
30 str += "aria2c -c -s10 -x10 --out "+TLE.escape_command(filepath)+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
33 TLE.text_pop("aria2 download command", str);
35 'wget': function(todown) {
36 //console.log(todown);
38 $.each(todown.tasklist, function(n, task) {
39 $.each(task.filelist, function(l, file) {
40 if (!file.downurl) return;
41 str += "wget -c -O "+TLE.escape_command(TLE.safe_title(file.title))+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
44 TLE.text_pop("wget download command", str);
46 "YAAW": function(todown) {
47 if (TLE.getConfig("TLE_aria2_jsonrpc")) {
48 TLE.tip("添加中...到YAAW界面查看是否添加成功");
49 var aria2 = new ARIA2(TLE.getConfig("TLE_aria2_jsonrpc"));
50 $.each(todown.tasklist, function(n, task) {
51 $.each(task.filelist, function(l, file) {
52 if (!file.downurl) return;
53 var filepath = TLE.safe_title(file.title);
54 if (task.tasktype === 0 && task.filelist.length > 1)
55 filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
56 aria2.addUri(file.downurl, {out: filepath, header: 'Cookie: gdriveid='+todown.gdriveid});
61 TLE.tip("尚未设置Aria2 JSONRPC地址", 5);
64 'Aria2导出': function(todown) {
65 //console.log(todown);
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 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';
76 TLE.file_pop("Aria2导出文件下载", str, "aria2.down");
78 'IDM导出': function(todown) {
79 //console.log(todown);
81 $.each(todown.tasklist, function(n, task) {
82 $.each(task.filelist, function(l, file) {
83 if (!file.downurl) return;
84 str += '<\r\n'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'\r\ncookie: gdriveid='+todown.gdriveid+'\r\n>\r\n';
87 TLE.file_pop("IDM导出文件下载", str, "idm.ef2");
89 'Orbit导出': function(todown) {
90 //console.log(todown);
92 $.each(todown.tasklist, function(n, task) {
93 $.each(task.filelist, function(l, file) {
94 if (!file.downurl) return;
95 str += TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'|'+TLE.safe_title(file.title.replace("|", "_"))+'||gdriveid='+todown.gdriveid+'\r\n';
98 TLE.file_pop("Orbit导出文件下载", str, "orbit.olt");
100 'eagleget导出': function(todown) {
101 var ret = {tasks: []};
102 $.each(todown.tasklist, function(n, task) {
103 $.each(task.filelist, function(l, file) {
104 if (!file.downurl) return;
106 cookie: 'gdriveid='+todown.gdriveid,
107 fname: TLE.safe_title(file.title),
108 url: TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))
112 TLE.file_pop("Eagleget导出文件下载(test)", JSON.stringify(ret), "eagleget.eg");
117 function get_taskinfo(taskid) {
119 taskname: $("#tr_c"+taskid+" .title .w_title").attr("title"),
120 title: $("#tr_c"+taskid+" .title .w_title").attr("title"),
121 f_url: $("#f_url"+taskid).val(),
122 downurl: $("#dl_url"+taskid).val(),
123 cid: $("#dcid"+taskid).val(),
124 gcid: $("#gcid"+taskid).val(),
125 size: parseInt($("#ysfilesize"+taskid).val()),
126 tasktype: parseInt($("#d_tasktype"+taskid).val()),
127 status: $("#d_status"+taskid).val(),
130 function get_bt_taskinfo(taskid) {
132 title: $("#bt_taskname"+taskid).val(),
133 f_url: $("#bturl"+taskid).val(),
134 downurl: $("#btdownurl"+taskid).val(),
135 cid: $("#btcid"+taskid).val(),
136 gcid: $("#btgcid"+taskid).val(),
137 size: $("#bt_filesize"+taskid).val(),
138 status: $("#btd_status"+taskid).val(),
142 function build_bt_taskinfo(info, rdata) {
144 'taskname': info.taskname,
147 'size': parseInt(info.ysfilesize),
148 'tasktype': parseInt(info.d_tasktype),
149 'status': info.d_status,
152 $.each(rdata, function(n, e) {
156 'downurl': e.downurl,
159 'size': parseInt(e.filesize),
162 taskinfo['filelist'] = filelist;
166 TLE.safe_title = function safe_title(title) {
167 return title.replace(/[\\\|\:\*\"\?\<\>]/g,"_");
170 TLE.bt_down = function(_this, _do) {
171 var ck = document.getElementsByName("bt_list_ck");
173 $.each(ck, function(n, e) {
174 if (e.checked == false) return;
175 var fid = e.getAttribute("_i");
177 'title': $("#bt_taskname"+fid).val(),
178 'url': $("#bturl"+fid).val(),
179 'downurl': $("#btdownurl"+fid).val(),
180 'cid': $("#btcid"+fid).val(),
181 'gcid': $("#btgcid"+fid).val(),
182 'filesize': $("#bt_filesize"+fid).val(),
186 var taskid = $("#view_bt_taskid").val();
187 var info = get_taskinfo($("#tr_c"+taskid));
190 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
191 todown.tasklist = {};
192 todown.tasklist[taskid] = build_bt_taskinfo(info, files);
193 //console.log(todown);
197 //console.log("bt_down");
200 TLE.text_pop = function(title, content) {
201 content = $('<div></div>').text(content).html()
202 content = '<textarea style="width: 100%; height: 260px;">'+content+'</textarea>'
203 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
204 //onHide: function() { $(document.body).click(); },
207 TLE.file_pop = function(title, content, filename) {
208 var url = "data:text/html;charset=utf-8,"+encodeURIComponent(content);
210 $('<a href="'+url+'" target="_blank" style="display:none;" download="'+filename+'"></a>').appendTo('body').get(0).click();
212 var content = '<div style="width: 100%; height: 100px;">'
213 +'<div style="padding: 30px 0 0 30%;">'
214 +'<a href="'+url+'" target="_blank" title="右键另存为" class="pop_btn" download="'+filename+'"><span><em class="TLE_icdwlocal">导出文件</em></span></a>'
215 +(isChrome ? '' : '(右键另存为'+filename+')')
218 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
219 //onHide: function() { $(document.body).click(); },
223 TLE.window_pop = function(title, content) {
224 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
225 //onHide: function() { $(document.body).click(); },
228 TLE.tip = function(content, time) {
229 TS2.show(content, time);
231 TLE.hide_tip = function() {
235 TLE.multiple_server_fix = function(url) {
236 return "'"+url.replace("gdl", "'{gdl,dl.{f,g,h,i,twin}}'")+"'";
239 function encode_utf8(s) {
240 return unescape( encodeURIComponent( s ) );
242 function to_hex(num) {
243 var s = num.toString(16);
249 var thunder_filename_mask = [0x61, 0x31, 0xe4, 0x5f, 0x00, 0x00, 0x00, 0x00];
250 function thunder_filename_encode(filename) {
251 var result = ["01", ];
252 $.each(encode_utf8(filename), function(i, n) {
253 result.push(to_hex(n.charCodeAt(0)^thunder_filename_mask[i%8]).toUpperCase())
255 while (result.length % 8 != 1) {
256 result.push(to_hex(thunder_filename_mask[(result.length-1)%8]).toUpperCase());
258 return result.join("");
261 TLE.url_rewrite = function(url, filename) {
262 url = url.replace(/&n=\w+/, "&n="+thunder_filename_encode(filename));
266 var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
267 TLE.escape_command = function(str) {
269 for (var i = 0; i < str.length; i++) {
270 if (alpha.indexOf(str[i]) == -1)
271 result += "\\"+str[i];
279 TLE.getConfig = function(key) {
280 if (window.localStorage) {
281 return window.localStorage.getItem(key) || "";
283 return getCookie(key);
286 TLE.setConfig = function(key, value) {
287 if (window.localStorage) {
288 window.localStorage.setItem(key, value);
290 setGdCookie(key, value, 86400*365);
294 if (TLE.getConfig("TLE_exporter") == "") {
296 for (var key in TLE.exporter) {
299 TLE.setConfig("TLE_exporter", exporters.join("|"));
304 $("head").append('<style>'
305 +'#TLE_setting { padding: 10px 20px 20px 20px; }'
306 +'#TLE_setting span { padding-left: 1em; }'
307 +'#TLE_setting li { margin-top: 0.5em; }'
308 +'#TLE_exporter_select { padding: 10px 20px 20px 20px; }'
311 $("body").append('<div id="TLE_text_pop" class="lixian_pop_wp pop_w400" style="display:none;margin:0;"></div>');
312 $("body").append('<textarea id="TLE_text_tpl" style="display: none;"></textarea>');
313 $("#TLE_text_tpl").text('<div class="lixian_pop">'
314 +'<div class="l_p_hd">'
317 +'<div class="l_p_bd">'
320 +'<a class="pop_close" title="关闭浮层" close="1" id="close">关闭浮层</a>'
323 $("#view_down_bar ul").prepend('<li> <a href="#" id="TLE_setting_anchor">TLE设置</a></li>');
324 $("#TLE_setting_anchor").on("click", function() {
325 var content = '<div id="TLE_setting"><ul>'
326 +'<li><b>启用以下导出器</b></li>'
328 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
330 for (var name in TLE.exporter) {
331 str += '<span class="rw_col"><input type="checkbox" class="TLE_setting_ck" name="TLE_ck_'+name+'" '+(enabled_exporter.indexOf(name) == -1 ? "" : "checked")+' />'+name+'</span>';
335 +'<li><b>Aria2 JSON-RPC Path</b></li>'
336 +'<li>Path: <input type="text" id="TLE_aria2_jsonrpc" style="width: 350px" value="'+TLE.getConfig("TLE_aria2_jsonrpc")+'"/></li>'
340 +'<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>';
341 $("#TLE_text_pop").tpl("TLE_text_tpl", {title: "Thunder Lixian Exporter 设定", content: content}).show().pop();
342 $("#TLE_setting_ok").on("click", function() {
343 var enabled_exporter = [];
344 $(".TLE_setting_ck").each(function(n, e) {
345 if (e.checked) enabled_exporter.push(e.name.replace(/^TLE_ck_/, ""));
347 var config_str = (enabled_exporter.length == 0) ? "_" : enabled_exporter.join("|");
348 var jsonrpc_path = $("#TLE_aria2_jsonrpc").val();
349 if (TLE.getConfig("TLE_exporter") != config_str || TLE.getConfig("TLE_aria2_jsonrpc") != jsonrpc_path) {
350 TLE.setConfig("TLE_exporter", config_str);
351 TLE.setConfig("TLE_aria2_jsonrpc", jsonrpc_path);
353 $("a.pop_close:visible").click();
358 function exporter_anchors() {
359 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
361 $.each(TLE.exporter, function(n, f) {
362 if (enabled_exporter.indexOf(n) == -1) return;
363 str+=('<li><a href="#" title="'+n+'" onclick="TLE.exporter[\''+n+'\'](TLE.todown);return false;">'+n+'</a></li>');
367 function show_exporter_selector() {
368 $("#TLE_text_pop").tpl("TLE_text_tpl", {title: "您正在使用Thunder Lixian Exporter",
369 content: '<ul id="TLE_exporter_select">'
375 window.thunder_download = function(taskid, type) {
377 TLE.todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
381 taskname: $("#bt_info_list .title .w").text(),
389 filelist.push(get_bt_taskinfo(taskid));
390 taskinfo['filelist'] = filelist;
391 TLE.todown.tasklist = {};
392 TLE.todown.tasklist['0'] = taskinfo;
395 var taskinfo = get_taskinfo(taskid);
397 filelist.push(get_taskinfo(taskid));
398 taskinfo['filelist'] = filelist;
399 TLE.todown.tasklist = {};
400 TLE.todown.tasklist[taskid] = taskinfo;
402 show_exporter_selector();
404 window.bt_task_down = function(cid, taskid) {
406 batch_down_all_f([taskid, ]);
408 window.batch_down_all_f = function(taskids) {
412 $("span[name=ck][checked]").each(function(n, e) {
413 taskids.push($(e).attr("value"));
417 var bt_task_list = [], normal_task_list = [];
418 $.each(taskids, function(n, taskid) {
419 var d_status = $("#d_status"+taskid).val();
420 var d_tasktype = parseInt($("#d_tasktype"+taskid).val());
421 var d_flag = $("#dflag"+taskid).val();
422 if (d_flag != 4 && d_status == 2) {
423 if (d_tasktype == 0) {
424 bt_task_list.push(taskid);
426 normal_task_list.push(taskid);
431 if (bt_task_list.length) {
433 $.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+bt_task_list.join(",")+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
436 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
437 todown.tasklist = {};
438 $.each(data['Result'], function(n, e) {
439 var taskinfo = get_taskinfo(n);
441 $.each(e, function(n, e) {
448 size: parseInt(e.filesize),
451 taskinfo.filelist = filelist;
452 todown.tasklist[n] = taskinfo;
454 $.each(normal_task_list, function(n, e) {
455 var taskinfo = get_taskinfo(e);
456 taskinfo['filelist'] = taskinfo;
457 todown.tasklist[e] = taskinfo;
460 show_exporter_selector();
464 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
465 todown.tasklist = {};
466 $.each(normal_task_list, function(n, e) {
467 var taskinfo = get_taskinfo(e);
468 taskinfo['filelist'] = taskinfo;
469 todown.tasklist[e] = taskinfo;
472 show_exporter_selector();
475 window.batch_down_bt = function() {
477 $("span[name=bt_list_ck][checked]").each(function(n, e) {
478 var taskid = $(e).attr("value");
479 if ($("#btd_status"+taskid).val() == 2)
480 taskids.push(taskid);
484 TLE.todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
486 taskname: $("#bt_info_list .title .w").text(),
494 $.each(taskids, function(n, e) {
495 filelist.push(get_bt_taskinfo(e));
497 taskinfo['filelist'] = filelist;
498 TLE.todown.tasklist = {};
499 TLE.todown.tasklist['0'] = taskinfo;
500 show_exporter_selector();
507 var ARIA2 = (function() {
508 var jsonrpc_version = '2.0';
510 function get_auth(url) {
511 return url.match(/^(?:(?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(?:\/\/)?(?:([^:@]*(?::[^:@]*)?)?@)?/)[1];
514 function request(jsonrpc_path, method, params) {
515 var xhr = new XMLHttpRequest();
516 var auth = get_auth(jsonrpc_path);
517 jsonrpc_path = jsonrpc_path.replace(/^((?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(\/\/)?(?:(?:[^:@]*(?::[^:@]*)?)?@)?(.*)/, '$1$2$3'); // auth string not allowed in url for firefox
520 jsonrpc: jsonrpc_version,
522 id: (new Date()).getTime().toString(),
524 if (params) request_obj['params'] = params;
525 if (auth && auth.indexOf('token:') == 0) params.unshift(auth);
527 xhr.open("POST", jsonrpc_path+"?tm="+(new Date()).getTime().toString(), true);
528 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
529 if (auth && auth.indexOf('token:') != 0) {
530 xhr.setRequestHeader("Authorization", "Basic "+btoa(auth));
532 xhr.send(JSON.stringify(request_obj));
535 return function(jsonrpc_path) {
536 this.jsonrpc_path = jsonrpc_path;
537 this.addUri = function (uri, options) {
538 request(this.jsonrpc_path, 'aria2.addUri', [[uri, ], options]);