modified: myjupyterlab.sh
[GalaxyCodeBases.git] / js / ThunderLixianExporter / ThunderLixianExporter.user.js
bloba3cef4f14f44d5a3a339e7f1ecbcd19a9a179c32
1 // ==UserScript==
2 // @name ThunderLixianExporter
3 // @namespace http://dynamic.cloud.vip.xunlei.com/
4 // @version 0.78.3
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
13 // ==/UserScript==
15 function tle_wrapper() {
16 // vim: set et sw=2 ts=2 sts=2 ff=unix fenc=utf8:
17 // Author: Binux<root@binux.me>
18 // http://binux.me
19 // Created on Fri 20 Jul 2012 11:43:22 AM CST
21 TLE = {};
23 TLE.exporter = {
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>';
31 });
32 });
33 str += "</ul>";
34 $("#TLE_text_pop").tpl("TLE_text_tpl", {'title': '复制选中的链接 &gt; <a href="'+"data:text/html;charset=utf-8,"+encodeURIComponent(str)+'" target="_blank">在新窗口中打开</a>', 'content': str}).show().pop({
35 onHide: function() { $(document.body).click(); },
36 });
38 'Aria2': function(todown) {
39 //console.log(todown);
40 var str = "";
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";
48 });
49 });
50 TLE.text_pop("aria2 download command", str);
52 'wget': function(todown) {
53 //console.log(todown);
54 var str = "";
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";
59 });
60 });
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});
74 });
75 });
76 hide_tip();
77 } else {
78 show_tip("尚未设置Aria2 JSONRPC地址");
79 hide_tip();
82 'Aria2导出': function(todown) {
83 //console.log(todown);
84 var str = "";
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';
92 });
93 });
94 TLE.file_pop("Aria2导出文件下载", str, "aria2.down");
96 'IDM导出': function(todown) {
97 //console.log(todown);
98 var str = "";
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);
109 var str = "";
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;
123 ret.tasks.push({
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");
134 (function(TLE) {
135 function get_taskinfo(p) {
136 var taskid = p.attr("taskid");
137 var info = {};
138 p.find("input").each(function(n, e) {
139 var key = e.getAttribute("id").replace(taskid, "");
140 info[key] = e.getAttribute("value");
142 return info;
145 function build_normal_taskinfo(info) {
146 var taskinfo = {
147 'taskname': info.taskname || info.cloud_taskname,
148 'f_url': info.f_url,
149 'cid': info.dcid || info.cloud_cid,
150 'size': parseInt(info.ysfilesize),
151 'tasktype': info.d_tasktype,
152 'status': info.d_status,
154 var filelist = [];
155 filelist.push({
156 'title': info.taskname || info.cloud_taskname,
157 'f_url': info.f_url,
158 'downurl': info.dl_url || info.cloud_dl_url,
159 'cid': info.dcid || info.cloud_cid,
160 'gcid': "",
161 'size': parseInt(info.ysfilesize),
163 taskinfo['filelist'] = filelist;
165 return taskinfo;
167 function build_bt_taskinfo(info, rdata) {
168 var taskinfo = {
169 'taskname': info.taskname,
170 'f_url': info.f_url,
171 'cid': info.dcid,
172 'size': parseInt(info.ysfilesize),
173 'tasktype': info.d_tasktype,
174 'status': info.d_status,
176 var filelist = [];
177 $.each(rdata, function(n, e) {
178 filelist.push({
179 'title': e.title,
180 'f_url': e.url,
181 'downurl': e.downurl,
182 'cid': e.cid,
183 'gcid': e.gcid,
184 'size': parseInt(e.filesize),
187 taskinfo['filelist'] = filelist;
188 return taskinfo;
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);
198 console.log(info);
200 if (info.d_tasktype == "0") { //bt task
201 show_tip("载入中...");
202 $.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+info.input+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
203 hide_tip();
204 var todown = {};
205 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
206 todown.tasklist = {};
207 todown.tasklist[info.input] = build_bt_taskinfo(info, data['Result'][info.input]);
208 _do(todown);
210 } else {
211 var todown = {}
212 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
213 todown.tasklist = {};
214 todown.tasklist[info.input] = build_normal_taskinfo(info);
215 _do(todown);
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);
233 } else {
234 normal_task_list.push(taskid);
239 if (bt_task_list.length) {
240 show_tip("载入中...");
241 $.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+bt_task_list.join(",")+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
242 hide_tip();
243 var todown = {};
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);
254 _do(todown);
256 } else {
257 var todown = {};
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);
264 _do(todown);
268 TLE.bt_down = function(_this, _do) {
269 var ck = document.getElementsByName("bt_list_ck");
270 var files = [];
271 $.each(ck, function(n, e) {
272 if (e.checked == false) return;
273 var fid = e.getAttribute("_i");
274 var file = {
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(),
282 files.push(file);
284 var taskid = $("#view_bt_taskid").val();
285 var info = get_taskinfo($("#tr_c"+taskid));
287 var todown = {};
288 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
289 todown.tasklist = {};
290 todown.tasklist[taskid] = build_bt_taskinfo(info, files);
291 //console.log(todown);
293 _do(todown);
295 //console.log("bt_down");
298 TLE.bt_down_one = function(_this, _do) {
299 var files = []
300 var fid = $(_this).parents(".rw_list").attr("i");
301 var file = {
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(),
309 files.push(file);
310 var taskid = $("#view_bt_taskid").val();
311 var info = get_taskinfo($("#tr_c"+taskid));
313 var todown = {};
314 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
315 todown.tasklist = {};
316 todown.tasklist[taskid] = build_bt_taskinfo(info, files);
317 //console.log(todown);
319 _do(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();
327 return false;
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+')')
343 +'</div>'
344 +'</div>'
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);
364 if (s.length == 1)
365 return '0'+s;
366 else
367 return s;
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));
383 return url;
386 var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
387 TLE.escape_command = function(str) {
388 var result = "";
389 for (var i = 0; i < str.length; i++) {
390 if (alpha.indexOf(str[i]) == -1)
391 result += "\\"+str[i];
392 else
393 result += str[i];
395 return result;
398 //setting
399 TLE.getConfig = function(key) {
400 if (window.localStorage) {
401 return window.localStorage.getItem(key) || "";
402 } else {
403 return getCookie(key);
406 TLE.setConfig = function(key, value) {
407 if (window.localStorage) {
408 window.localStorage.setItem(key, value);
409 } else {
410 setGdCookie(key, value, 86400*365);
413 //set default config
414 if (TLE.getConfig("TLE_exporter") == "") {
415 var exporters = [];
416 for (var key in TLE.exporter) {
417 exporters.push(key);
419 TLE.setConfig("TLE_exporter", exporters.join("|"));
422 function init() {
423 //css
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; }'
442 // for thunder css
443 +'.rwset {width:530px;}'
444 +'</style>');
445 //pop
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">'
450 +'<h3>$[title]</h3>'
451 +'</div>'
452 +'<div class="psc_info">'
453 +'$[content]'
454 +'</div>'
455 +'<a href="#" class="close" title="关闭">关闭</a>'
456 +'</div>');
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>'
460 +'<ul>'
461 +'<li><b>启用以下导出器</b></li>'
462 +'<li>'+(function(){
463 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
464 var str = '';
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>';
468 return str;
469 })()+'</li>'
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>'
472 +'</ul>'
473 +'$1'));
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);
487 TS2.show('设置已生效',1);
488 setTimeout(function(){
489 setting.hide();
490 location.reload(true);
491 }, 1*1000);
495 function exporter_anchors(type) {
496 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
497 var str = '';
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>');
502 return str;
504 //down
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>'
510 + '</span>'
511 + '<div class="TLE_p_getbtn TLE_getbtn" style="display: none;">'
512 + exporter_anchors("TLE.down")
513 + '</div>'
514 + '</div>');
517 //batch_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")
522 + '</div>');
523 var _task_check_click = task_check_click;
524 task_check_click = function() {
525 _task_check_click();
526 if ($("#li_task_down,#li_task_download").hasClass("noit")) {
527 $("#TLE_batch_down").addClass("noit").unbind("click");
528 } else {
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();
532 return false;
535 //console.log("task_check_click called");
537 $('input[name=ck],input#ckbutton').click(task_check_click);
539 //bt_down
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")
545 + '</div>'));
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>'
552 + '</span>'
553 + '<div class="TLE_p_getbtn TLE_getbtn" style="display: none;">'
554 + exporter_anchors("TLE.bt_down_one")
555 + '</div>'
556 + '</div>'));
557 var _bt_view_nav = bt_view_nav;
558 bt_view_nav = function() {
559 _bt_view_nav();
560 if ($("#view_bt_list_nav_down").hasClass("noit")) {
561 $("#TLE_bt_down").addClass("noit").unbind("click");
562 } else {
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();
566 return false;
569 $("#TLE_bt_getbtn").hide();
570 //console.log("bt_view_nav called");
573 //close menu binding
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();});
583 init();
584 })(TLE);
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
598 var request_obj = {
599 jsonrpc: jsonrpc_version,
600 method: method,
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]);
619 return this;
621 })();
622 } // end of wrapper
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>
627 // http://binux.me
628 // Created on 2013-12-27 23:00:34
630 TLE = {};
632 TLE.exporter = {
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>';
642 str += "</ul>";
643 TLE.window_pop('复制选中的链接 &gt; <a href="'+"data:text/html;charset=utf-8,"+encodeURIComponent(str)+'" target="_blank">在新窗口中打开</a>', str);
645 'Aria2': function(todown) {
646 //console.log(todown);
647 var str = "";
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);
661 var str = "";
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});
683 TLE.hide_tip();
684 } else {
685 TLE.tip("尚未设置Aria2 JSONRPC地址", 5);
688 'Aria2导出': function(todown) {
689 //console.log(todown);
690 var str = "";
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);
704 var str = "";
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);
715 var str = "";
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;
729 ret.tasks.push({
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");
740 (function(TLE) {
741 function get_taskinfo(taskid) {
742 return {
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) {
755 return {
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) {
767 var taskinfo = {
768 'taskname': info.taskname,
769 'f_url': info.f_url,
770 'cid': info.dcid,
771 'size': parseInt(info.ysfilesize),
772 'tasktype': parseInt(info.d_tasktype),
773 'status': info.d_status,
775 var filelist = [];
776 $.each(rdata, function(n, e) {
777 filelist.push({
778 'title': e.title,
779 'f_url': e.url,
780 'downurl': e.downurl,
781 'cid': e.cid,
782 'gcid': e.gcid,
783 'size': parseInt(e.filesize),
786 taskinfo['filelist'] = filelist;
787 return taskinfo;
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");
796 var files = [];
797 $.each(ck, function(n, e) {
798 if (e.checked == false) return;
799 var fid = e.getAttribute("_i");
800 var file = {
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(),
808 files.push(file);
810 var taskid = $("#view_bt_taskid").val();
811 var info = get_taskinfo($("#tr_c"+taskid));
813 var todown = {};
814 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
815 todown.tasklist = {};
816 todown.tasklist[taskid] = build_bt_taskinfo(info, files);
817 //console.log(todown);
819 _do(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);
833 if (isChrome) {
834 $('<a href="'+url+'" target="_blank" style="display:none;" download="'+filename+'"></a>').appendTo('body').get(0).click();
835 } else {
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+')')
840 +'</div>'
841 +'</div>'
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() {
856 TS2.hide();
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);
868 if (s.length == 1)
869 return '0'+s;
870 else
871 return s;
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));
887 return url;
890 var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
891 TLE.escape_command = function(str) {
892 var result = "";
893 for (var i = 0; i < str.length; i++) {
894 if (alpha.indexOf(str[i]) == -1)
895 result += "\\"+str[i];
896 else
897 result += str[i];
899 return result;
902 //setting
903 TLE.getConfig = function(key) {
904 if (window.localStorage) {
905 return window.localStorage.getItem(key) || "";
906 } else {
907 return getCookie(key);
910 TLE.setConfig = function(key, value) {
911 if (window.localStorage) {
912 window.localStorage.setItem(key, value);
913 } else {
914 setGdCookie(key, value, 86400*365);
917 //set default config
918 if (TLE.getConfig("TLE_exporter") == "") {
919 var exporters = [];
920 for (var key in TLE.exporter) {
921 exporters.push(key);
923 TLE.setConfig("TLE_exporter", exporters.join("|"));
926 function init() {
927 //css
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; }'
933 +'</style>');
934 //pop
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">'
939 +'<h3>$[title]</h3>'
940 +'</div>'
941 +'<div class="l_p_bd">'
942 +'$[content]'
943 +'</div>'
944 +'<a class="pop_close" title="关闭浮层" close="1" id="close">关闭浮层</a>'
945 +'</div>');
946 //setting
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>'
951 +'<li>'+(function(){
952 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
953 var str = '';
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>';
957 return str;
958 })()+'</li>'
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>'
961 +'</ul>'
962 +'</div>'
963 +'</div>'
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();
978 TLE.tip("配置已保存", 5);
981 //download binding
982 function exporter_anchors() {
983 var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
984 var str = '';
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>');
989 return str;
991 function show_exporter_selector() {
992 $("#TLE_text_pop").tpl("TLE_text_tpl", {title: "您正在使用Thunder Lixian Exporter",
993 content: '<ul id="TLE_exporter_select">'
994 +exporter_anchors()
995 +'</ul>'}).pop();
998 TLE.todown = {};
999 window.thunder_download = function(taskid, type) {
1000 TLE.todown = {};
1001 TLE.todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
1002 if (type === 1) {
1003 // bt_down_one
1004 var taskinfo = {
1005 taskname: $("#bt_info_list .title .w").text(),
1006 f_url: null,
1007 cid: null,
1008 size: null,
1009 tasktype: 0,
1010 status: 2,
1012 var filelist = [];
1013 filelist.push(get_bt_taskinfo(taskid));
1014 taskinfo['filelist'] = filelist;
1015 TLE.todown.tasklist = {};
1016 TLE.todown.tasklist['0'] = taskinfo;
1017 } else {
1018 // down
1019 var taskinfo = get_taskinfo(taskid);
1020 var filelist = [];
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) {
1029 // bt_down
1030 batch_down_all_f([taskid, ]);
1032 window.batch_down_all_f = function(taskids) {
1033 // batch_down
1034 if (!taskids) {
1035 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);
1049 } else {
1050 normal_task_list.push(taskid);
1055 if (bt_task_list.length) {
1056 TLE.tip("载入中...");
1057 $.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+bt_task_list.join(",")+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
1058 TLE.hide_tip();
1059 var todown = {};
1060 todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
1061 todown.tasklist = {};
1062 $.each(data['Result'], function(n, e) {
1063 var taskinfo = get_taskinfo(n);
1064 var filelist = [];
1065 $.each(e, function(n, e) {
1066 filelist.push({
1067 title: e.title,
1068 f_url: e.url,
1069 downurl: e.downurl,
1070 cid: e.cid,
1071 gcid: e.gcid,
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();
1086 } else {
1087 var todown = {};
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() {
1100 var taskids = [];
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);
1107 TLE.todown = {};
1108 TLE.todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
1109 var taskinfo = {
1110 taskname: $("#bt_info_list .title .w").text(),
1111 f_url: null,
1112 cid: null,
1113 size: null,
1114 tasktype: 0,
1115 status: 2,
1117 var filelist = [];
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();
1128 init();
1129 })(TLE);
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
1143 var request_obj = {
1144 jsonrpc: jsonrpc_version,
1145 method: method,
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]);
1164 return this;
1166 })();
1167 } // end of wrapper
1169 function onload(func) {
1170 if (document.readyState === "complete") {
1171 func();
1172 } else {
1173 window.addEventListener('load', func);
1176 onload(function(){
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 +')();'));
1181 } else {
1182 script.appendChild(document.createTextNode('('+ tle_lx3_wrapper +')();'));
1184 (document.body || document.head || document.documentElement).appendChild(script);