-
Notifications
You must be signed in to change notification settings - Fork 156
/
ThunderLixianExporter.user.js
1221 lines (1149 loc) · 46 KB
/
ThunderLixianExporter.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name ThunderLixianExporter
// @namespace http://dynamic.cloud.vip.xunlei.com/
// @version 0.78.4
// @description export thunder lixian url to aria2/wget
// @include http://dynamic.cloud.vip.xunlei.com/user_task*
// @include http://lixian.vip.xunlei.com/lx3_task.html*
// @include http://jiayuan.xunlei.com/lxhome/lx3_task.html*
// @include http://cloud.vip.xunlei.com/*
// @run-at document-end
// @copyright 2012~2017, Binux <root@binux.me>
// @updateURL https://cdn.rawgit.com/binux/ThunderLixianExporter/master/ThunderLixianExporter.meta.js
// ==/UserScript==
function tle_wrapper() {
// vim: set et sw=2 ts=2 sts=2 ff=unix fenc=utf8:
// Author: Binux<root@binux.me>
// http://binux.me
// Created on Fri 20 Jul 2012 11:43:22 AM CST
TLE = {};
TLE.exporter = {
'复制链接': function(todown) {
//console.log(todown);
var str = '<ul style="max-height: 300px; overflow-y: scroll; overflow-x: hidden;">';
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
str += '<li><a href="'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'" target="_blank">'+file.title+'</a></li>';
});
});
str += "</ul>";
$("#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({
onHide: function() { $(document.body).click(); },
});
},
'Aria2': function(todown) {
//console.log(todown);
var str = "";
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
var filepath = TLE.safe_title(file.title);
if (task.tasktype == 0 && task.filelist.length > 1)
filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
str += "aria2c -c -s10 -x10 --out "+TLE.escape_command(filepath)+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
});
});
TLE.text_pop("aria2 download command", str);
},
'wget': function(todown) {
//console.log(todown);
var str = "";
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
str += "wget -c -O "+TLE.escape_command(TLE.safe_title(file.title))+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
});
});
TLE.text_pop("wget download command", str);
},
"YAAW": function(todown) {
if (TLE.getConfig("TLE_aria2_jsonrpc")) {
show_tip("添加中...到YAAW界面查看是否添加成功");
var aria2 = new ARIA2(TLE.getConfig("TLE_aria2_jsonrpc"));
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
var filepath = TLE.safe_title(file.title);
if (task.tasktype == 0 && task.filelist.length > 1)
filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
aria2.addUri(file.downurl, {out: filepath, header: 'Cookie: gdriveid='+todown.gdriveid});
});
});
hide_tip();
} else {
show_tip("尚未设置Aria2 JSONRPC地址");
hide_tip();
};
},
'Aria2导出': function(todown) {
//console.log(todown);
var str = "";
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
var filepath = TLE.safe_title(file.title);
if (task.tasktype == 0 && task.filelist.length > 1)
filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
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';
});
});
TLE.file_pop("Aria2导出文件下载", str, "aria2.down");
},
'IDM导出': function(todown) {
//console.log(todown);
var str = "";
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
str += '<\r\n'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'\r\ncookie: gdriveid='+todown.gdriveid+'\r\n>\r\n'
});
});
TLE.file_pop("IDM导出文件下载", str, "idm.ef2");
},
'Orbit导出': function(todown) {
//console.log(todown);
var str = "";
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
str += TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'|'+TLE.safe_title(file.title.replace("|", "_"))+'||gdriveid='+todown.gdriveid+'\r\n'
});
});
TLE.file_pop("Orbit导出文件下载", str, "orbit.olt");
},
'eagleget': function(todown) {
var ret = {tasks: []};
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
ret.tasks.push({
cookie: 'gdriveid='+todown.gdriveid,
fname: TLE.safe_title(file.title),
url: TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))
});
});
});
TLE.file_pop("Eagleget导出文件下载(test)", JSON.stringify(ret), "eagleget.eg");
},
};
(function(TLE) {
function get_taskinfo(p) {
var taskid = p.attr("taskid");
var info = {};
p.find("input").each(function(n, e) {
var key = e.getAttribute("id").replace(taskid, "");
info[key] = e.getAttribute("value");
});
return info;
};
function build_normal_taskinfo(info) {
var taskinfo = {
'taskname': info.taskname || info.cloud_taskname,
'f_url': info.f_url,
'cid': info.dcid || info.cloud_cid,
'size': parseInt(info.ysfilesize),
'tasktype': info.d_tasktype,
'status': info.d_status,
};
var filelist = [];
filelist.push({
'title': info.taskname || info.cloud_taskname,
'f_url': info.f_url,
'downurl': info.dl_url || info.cloud_dl_url,
'cid': info.dcid || info.cloud_cid,
'gcid': "",
'size': parseInt(info.ysfilesize),
});
taskinfo['filelist'] = filelist;
return taskinfo;
};
function build_bt_taskinfo(info, rdata) {
var taskinfo = {
'taskname': info.taskname,
'f_url': info.f_url,
'cid': info.dcid,
'size': parseInt(info.ysfilesize),
'tasktype': info.d_tasktype,
'status': info.d_status,
};
var filelist = [];
$.each(rdata, function(n, e) {
filelist.push({
'title': e.title,
'f_url': e.url,
'downurl': e.downurl,
'cid': e.cid,
'gcid': e.gcid,
'size': parseInt(e.filesize),
});
});
taskinfo['filelist'] = filelist;
return taskinfo;
};
TLE.safe_title = function safe_title(title) {
return title.replace(/[\\\|\:\*\"\?\<\>]/g,"_");
};
TLE.down = function(_this, _do) {
var p = $(_this).parents(".rw_list");
var info = get_taskinfo(p);
console.log(info);
if (info.d_tasktype == "0") { //bt task
show_tip("载入中...");
$.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+info.input+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
hide_tip();
var todown = {};
todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
todown.tasklist = {};
todown.tasklist[info.input] = build_bt_taskinfo(info, data['Result'][info.input]);
_do(todown);
});
} else {
var todown = {}
todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
todown.tasklist = {};
todown.tasklist[info.input] = build_normal_taskinfo(info);
_do(todown);
};
};
TLE.batch_down = function(_this, _do) {
var ck = document.getElementsByName("ck");
var bt_task_list = [];
var normal_task_list = [];
$.each(ck, function(n, e) {
if (e.checked == false) return;
var taskid = e.value;
var d_status = $("#d_status"+taskid).val();
var d_tasktype = $("#d_tasktype"+taskid).val();
var d_flag = $("#dflag"+taskid).val();
if (d_flag != 4 && d_status == 2) {
if (d_tasktype == 0) {
bt_task_list.push(taskid);
} else {
normal_task_list.push(taskid);
};
};
});
if (bt_task_list.length) {
show_tip("载入中...");
$.getJSON(INTERFACE_URL+"/fill_bt_list?tid="+bt_task_list.join(",")+"&g_net="+G_section+"&uid="+G_USERID+"&callback=?", function(data) {
hide_tip();
var todown = {};
todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
todown.tasklist = {};
$.each(data['Result'], function(n, e) {
var info = get_taskinfo($("#tr_c"+n));
todown.tasklist[n] = build_bt_taskinfo(info, e);
});
$.each(normal_task_list, function(n, e) {
var info = get_taskinfo($("#tr_c"+e));
todown.tasklist[e] = build_normal_taskinfo(info);
});
_do(todown);
});
} else {
var todown = {};
todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
todown.tasklist = {};
$.each(normal_task_list, function(n, e) {
var info = get_taskinfo($("#tr_c"+e));
todown.tasklist[e] = build_normal_taskinfo(info);
});
_do(todown);
};
};
TLE.bt_down = function(_this, _do) {
var ck = document.getElementsByName("bt_list_ck");
var files = [];
$.each(ck, function(n, e) {
if (e.checked == false) return;
var fid = e.getAttribute("_i");
var file = {
'title': $("#bt_taskname"+fid).val(),
'url': $("#bturl"+fid).val(),
'downurl': $("#btdownurl"+fid).val(),
'cid': $("#btcid"+fid).val(),
'gcid': $("#btgcid"+fid).val(),
'filesize': $("#bt_filesize"+fid).val(),
};
files.push(file);
});
var taskid = $("#view_bt_taskid").val();
var info = get_taskinfo($("#tr_c"+taskid));
var todown = {};
todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
todown.tasklist = {};
todown.tasklist[taskid] = build_bt_taskinfo(info, files);
//console.log(todown);
_do(todown);
//console.log("bt_down");
};
TLE.bt_down_one = function(_this, _do) {
var files = []
var fid = $(_this).parents(".rw_list").attr("i");
var file = {
'title': $("#bt_taskname"+fid).val(),
'url': $("#bturl"+fid).val(),
'downurl': $("#btdownurl"+fid).val(),
'cid': $("#btcid"+fid).val(),
'gcid': $("#btgcid"+fid).val(),
'filesize': $("#bt_filesize"+fid).val(),
};
files.push(file);
var taskid = $("#view_bt_taskid").val();
var info = get_taskinfo($("#tr_c"+taskid));
var todown = {};
todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
todown.tasklist = {};
todown.tasklist[taskid] = build_bt_taskinfo(info, files);
//console.log(todown);
_do(todown);
//console.log("bt_down");
};
TLE.getbtn = function(_this) {
$(_this).parents(".TLE_get_btnbox").find(".TLE_p_getbtn").toggle();
close_rightmenu_layer();
return false;
};
TLE.text_pop = function(title, content) {
content = $('<div></div>').text(content).html()
content = '<textarea style="width: 100%; height: 260px;">'+content+'</textarea>'
$("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
onHide: function() { $(document.body).click(); },
});
};
TLE.file_pop = function(title, content, filename) {
var url = "data:text/html;charset=utf-8,"+encodeURIComponent(content);
var content = '<div style="width: 100%; height: 100px;">'
+'<div style="padding: 30px 0 0 30%;">'
+'<a href="'+url+'" target="_blank" title="右键另存为" class="TLE_down_btn" download="'+filename+'"><span><em class="TLE_icdwlocal">导出文件</em></span></a>'
+(isChrome ? '' : '(右键另存为'+filename+')')
+'</div>'
+'</div>'
$("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
onHide: function() { $(document.body).click(); },
});
};
TLE.window_pop = function(title, content) {
$("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
onHide: function() { $(document.body).click(); },
});
};
TLE.multiple_server_fix = function(url) {
return "'"+url.replace("gdl", "'{gdl,dl.{f,g,h,i,twin}}'")+"'";
}
function encode_utf8(s) {
return unescape( encodeURIComponent( s ) );
};
function to_hex(num) {
var s = num.toString(16);
if (s.length == 1)
return '0'+s;
else
return s;
};
var thunder_filename_mask = [0x61, 0x31, 0xe4, 0x5f, 0x00, 0x00, 0x00, 0x00];
function thunder_filename_encode(filename) {
var result = ["01", ];
$.each(encode_utf8(filename), function(i, n) {
result.push(to_hex(n.charCodeAt(0)^thunder_filename_mask[i%8]).toUpperCase())
});
while (result.length % 8 != 1) {
result.push(to_hex(thunder_filename_mask[(result.length-1)%8]).toUpperCase());
}
return result.join("");
};
TLE.url_rewrite = function(url, filename) {
url = url.replace(/&n=\w+/, "&n="+thunder_filename_encode(filename));
return url;
};
var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
TLE.escape_command = function(str) {
var result = "";
for (var i = 0; i < str.length; i++) {
if (alpha.indexOf(str[i]) == -1)
result += "\\"+str[i];
else
result += str[i];
}
return result;
};
//setting
TLE.getConfig = function(key) {
if (window.localStorage) {
return window.localStorage.getItem(key) || "";
} else {
return getCookie(key);
}
};
TLE.setConfig = function(key, value) {
if (window.localStorage) {
window.localStorage.setItem(key, value);
} else {
setGdCookie(key, value, 86400*365);
}
};
//set default config
if (TLE.getConfig("TLE_exporter") == "") {
var exporters = [];
for (var key in TLE.exporter) {
exporters.push(key);
};
TLE.setConfig("TLE_exporter", exporters.join("|"));
};
function init() {
//css
$("head").append('<style>'
+'.TLE_get_btnbox {position:relative; float:left; z-index:11}'
+'.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;}'
+'.TLE_getbtn a {display:block; height:22px; line-height:22px; padding-left:18px}'
+'.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}'
+'.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}'
+'.TLE_get_btnbox .TLE_link_gettxt {float:left; display: inline ; width:53px; text-align:center; padding-left:24px; color:#000}'
+'.TLE_get_btnbox .TLE_link_gettxt:hover {text-decoration:none}'
+'.rwbox .rwset .TLE_link_getic {float:left; display:block; width:20px;height:22px;}'
+'.TLE_hiden {display: none; }'
+'.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; }'
+'.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; }'
+'.TLE_down_btn:active {background-position:0 -28px; }'
+'.TLE_down_btn:active span {background-position:right -28px;}'
+'.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; }'
+'.rwbtn.ic_redownloca { display: none !important; }'
+'.menu { width: 700px !important; }'
// for thunder css
+'.rwset {width:530px;}'
+'</style>');
//pop
$("body").append('<div id="TLE_text_pop" class="pop_rwbox" style="display: none;margin: 0;"></div>');
$("body").append('<textarea id="TLE_text_tpl" style="display: none;"></textarea>');
$("#TLE_text_tpl").text('<div class="p_rw_pop">'
+'<div class="tt_box onlytitle">'
+'<h3>$[title]</h3>'
+'</div>'
+'<div class="psc_info">'
+'$[content]'
+'</div>'
+'<a href="#" class="close" title="关闭">关闭</a>'
+'</div>');
$("#setting_main_tpl").text($("#setting_main_tpl").text().replace(/(<\/div>\s+<div class="btnin">)/,
'<div class="doline mag01"></div>'
+'<h3 style="background-position: 0 -180px;">Thunder Lixian Exporter 设定</h3>'
+'<ul>'
+'<li><b>启用以下导出器</b></li>'
+'<li>'+(function(){
var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
var str = '';
for (var name in TLE.exporter) {
str += '<span class="rw_col"><input type="checkbox" class="TLE_setting_ck" name="TLE_ck_'+name+'" '+(enabled_exporter.indexOf(name) == -1 ? "" : "checked")+' />'+name+'</span>';
}
return str;
})()+'</li>'
+'<li><b>Aria2 JSON-RPC Path</b></li>'
+'<li>Path: <input type="text" id="TLE_aria2_jsonrpc" style="width: 350px" value="'+TLE.getConfig("TLE_aria2_jsonrpc")+'"/></li>'
+'</ul>'
+'$1'));
$(".n_vip").after('<div class="zh_info"><em onclick="setting.show()" class="sys_set"></em></div>');
var _set_notice_submit = set_notice_submit;
set_notice_submit = function(f) {
_set_notice_submit(f);
var enabled_exporter = [];
$(".TLE_setting_ck").each(function(n, e) {
if (e.checked) enabled_exporter.push(e.name.replace(/^TLE_ck_/, ""));
});
var config_str = (enabled_exporter.length == 0) ? "_" : enabled_exporter.join("|");
var jsonrpc_path = $("#TLE_aria2_jsonrpc").val();
if (TLE.getConfig("TLE_exporter") != config_str || TLE.getConfig("TLE_aria2_jsonrpc") != jsonrpc_path) {
TLE.setConfig("TLE_exporter", config_str);
TLE.setConfig("TLE_aria2_jsonrpc", jsonrpc_path);
TS2.show('设置已生效',1);
setTimeout(function(){
setting.hide();
location.reload(true);
}, 1*1000);
}
};
function exporter_anchors(type) {
var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
var str = '';
$.each(TLE.exporter, function(n, f) {
if (enabled_exporter.indexOf(n) == -1) return;
str+=('<a href="#" title="'+n+'" onmouseover="this.className=\'sel_on\'" onmouseout="this.className=\'\'" onclick="'+type+'(this, TLE.exporter[\''+n+'\'])">'+n+'</a>');
});
return str;
}
//down
$(".rwbtn.ic_redownloca").each(function(n, e) {
$(e).after('<div class="TLE_get_btnbox">'
+ '<span class="TLE_getlink">'
+ '<a href="#" class="TLE_link_gettxt TLE-down-text" style="padding-left: 20px; width: 57px;" onclick='+e.getAttribute("onclick")+'>取回本地</a>'
+ '<a href="#" class="TLE_link_getic TLE-down-btn" onclick="return TLE.getbtn(this);"></a>'
+ '</span>'
+ '<div class="TLE_p_getbtn TLE_getbtn" style="display: none;">'
+ exporter_anchors("TLE.down")
+ '</div>'
+ '</div>');
});
//batch_down
$("#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>')
.parents(".main_link").append(
'<div id="TLE_batch_getbtn" class="TLE_getbtn" style="top: 30px; display:none;">'
+ exporter_anchors("TLE.batch_down")
+ '</div>');
var _task_check_click = task_check_click;
task_check_click = function() {
_task_check_click();
if ($("#li_task_down,#li_task_download").hasClass("noit")) {
$("#TLE_batch_down").addClass("noit").unbind("click");
} else {
$("#TLE_batch_down").removeClass("noit").unbind("click").click(function() {
$("#TLE_batch_getbtn").css("left", $("#TLE_batch_down").position().left);
$("#TLE_batch_getbtn").toggle();
return false;
});
};
//console.log("task_check_click called");
};
$('input[name=ck],input#ckbutton').click(task_check_click);
//bt_down
$("#view_bt_list_nav_tpl").text($("#view_bt_list_nav_tpl").text().replace('取回本地</em></span></a>',
'取回本地</em></span></a>'
+'<a href="#" class="btn_m noit" title="批量导出" id="TLE_bt_down"><span><em class="icdwlocal">批量导出</em></span></a>'
+'<div id="TLE_bt_getbtn" class="TLE_getbtn" style="top: 30px; display:none;">'
+ exporter_anchors("TLE.bt_down")
+ '</div>'));
$("#view_bt_list_tpl").text($("#view_bt_list_tpl").text().replace('ic_redownloca" title="">取回本地</a>',
'ic_redownloca" title="">取回本地</a>'
+'<div class="TLE_get_btnbox">'
+ '<span class="TLE_getlink">'
+ '<a href="#" class="TLE_link_gettxt TLE-down-text" style="padding-left: 20px; width: 57px;" onclick="thunder_download($[p.i],1);return false;">取回本地</a>'
+ '<a href="#" class="TLE_link_getic TLE-down-btn" onclick="return TLE.getbtn(this);"></a>'
+ '</span>'
+ '<div class="TLE_p_getbtn TLE_getbtn" style="display: none;">'
+ exporter_anchors("TLE.bt_down_one")
+ '</div>'
+ '</div>'));
var _bt_view_nav = bt_view_nav;
bt_view_nav = function() {
_bt_view_nav();
if ($("#view_bt_list_nav_down").hasClass("noit")) {
$("#TLE_bt_down").addClass("noit").unbind("click");
} else {
$("#TLE_bt_down").removeClass("noit").unbind("click").click(function() {
$("#TLE_bt_getbtn").css("left", $("#TLE_bt_down").position().left);
$("#TLE_bt_getbtn").toggle();
return false;
});
};
$("#TLE_bt_getbtn").hide();
//console.log("bt_view_nav called");
};
//close menu binding
$(document.body).bind("click",function(){
$("div.TLE_p_getbtn, #TLE_batch_getbtn, #TLE_bt_getbtn").hide();
});
$("div.rw_list").click(function(e){
$("div.TLE_p_getbtn, #TLE_batch_getbtn, #TLE_bt_getbtn").hide();
});
$("div.TLE_get_btnbox").click(function(e){e.stopPropagation();});
// support for shift group select
document.addEventListener('click', function(e) {
var that;
if ($(e.target).is('div.rw_list')) {
that = $(e.target);
} else if ($(e.target).is('div.rw_list *')) {
that = $(e.target).parents('div.rw_list');
} else {
return;
}
var id=that.attr('taskid');
if (e.button == 0 && e.shiftKey) {
window.getSelection().removeAllRanges();
e.stopPropagation();
var checked = $('div.rw_list:has(input[value]:checked)').map(function(i, e) { return $(e).index('div.rw_list') }).get();
var myindex = $('.rw_list[taskid="'+id+'"]').index('div.rw_list');
var from = checked.reduce(function(a, e) { return Math.abs(e-myindex) < Math.abs(a-myindex) ? e : a; }, checked[0]);
if (from > myindex) {
var tmp = from;
from = myindex;
myindex = tmp;
}
$('div.rw_list:eq('+from+'), div.rw_list:gt('+from+'):lt('+(myindex-from)+')').each(function(i, e) {
var id = $(e).attr('taskid');
if(!in_array(id,task_nowcheck)){
task_nowcheck.push(id);
}
$("#input"+id).attr("checked","true");
});
task_check_click();
clickFun(e,that);
}
}, true);
};
init();
})(TLE);
var ARIA2 = (function() {
var jsonrpc_version = '2.0';
function get_auth(url) {
return url.match(/^(?:(?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(?:\/\/)?(?:([^:@]*(?::[^:@]*)?)?@)?/)[1];
};
function request(jsonrpc_path, method, params) {
var xhr = new XMLHttpRequest();
var auth = get_auth(jsonrpc_path);
jsonrpc_path = jsonrpc_path.replace(/^((?![^:@]+:[^:@\/]*@)[^:\/?#.]+:)?(\/\/)?(?:(?:[^:@]*(?::[^:@]*)?)?@)?(.*)/, '$1$2$3'); // auth string not allowed in url for firefox
var request_obj = {
jsonrpc: jsonrpc_version,
method: method,
id: (new Date()).getTime().toString(),
};
if (params) request_obj['params'] = params;
if (auth && auth.indexOf('token:') == 0) params.unshift(auth);
xhr.open("POST", jsonrpc_path+"?tm="+(new Date()).getTime().toString(), true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
if (auth && auth.indexOf('token:') != 0) {
xhr.setRequestHeader("Authorization", "Basic "+btoa(auth));
}
xhr.send(JSON.stringify(request_obj));
};
return function(jsonrpc_path) {
this.jsonrpc_path = jsonrpc_path;
this.addUri = function (uri, options) {
request(this.jsonrpc_path, 'aria2.addUri', [[uri, ], options]);
};
return this;
}
})();
} // end of wrapper
function tle_lx3_wrapper() {
// vim: set et sw=2 ts=2 sts=2 ff=unix fenc=utf8:
// Author: Binux<i@binux.me>
// http://binux.me
// Created on 2013-12-27 23:00:34
TLE = {};
TLE.exporter = {
'复制链接': function(todown) {
//console.log(todown);
var str = '<ul style="max-height: 300px; overflow-y: scroll; overflow-x: hidden;">';
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
str += '<li><a href="'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'" target="_blank">'+file.title+'</a></li>';
});
});
str += "</ul>";
TLE.window_pop('复制选中的链接 > <a href="'+"data:text/html;charset=utf-8,"+encodeURIComponent(str)+'" target="_blank">在新窗口中打开</a>', str);
},
'Aria2': function(todown) {
//console.log(todown);
var str = "";
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
var filepath = TLE.safe_title(file.title);
if (task.tasktype === 0 && task.filelist.length > 1)
filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
str += "aria2c -c -s10 -x10 --out "+TLE.escape_command(filepath)+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
});
});
TLE.text_pop("aria2 download command", str);
},
'wget': function(todown) {
//console.log(todown);
var str = "";
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
str += "wget -c -O "+TLE.escape_command(TLE.safe_title(file.title))+" --header 'Cookie: gdriveid="+todown.gdriveid+";' '"+file.downurl+"'\n";
});
});
TLE.text_pop("wget download command", str);
},
"YAAW": function(todown) {
if (TLE.getConfig("TLE_aria2_jsonrpc")) {
TLE.tip("添加中...到YAAW界面查看是否添加成功");
var aria2 = new ARIA2(TLE.getConfig("TLE_aria2_jsonrpc"));
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
var filepath = TLE.safe_title(file.title);
if (task.tasktype === 0 && task.filelist.length > 1)
filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
aria2.addUri(file.downurl, {out: filepath, header: 'Cookie: gdriveid='+todown.gdriveid});
});
});
TLE.hide_tip();
} else {
TLE.tip("尚未设置Aria2 JSONRPC地址", 5);
}
},
'Aria2导出': function(todown) {
//console.log(todown);
var str = "";
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
var filepath = TLE.safe_title(file.title);
if (task.tasktype === 0 && task.filelist.length > 1)
filepath = TLE.safe_title(task.taskname) + "/" + TLE.safe_title(file.title.replace(/\\+\*?/g,"/"));
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';
});
});
TLE.file_pop("Aria2导出文件下载", str, "aria2.down");
},
'IDM导出': function(todown) {
//console.log(todown);
var str = "";
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
str += '<\r\n'+TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'\r\ncookie: gdriveid='+todown.gdriveid+'\r\n>\r\n';
});
});
TLE.file_pop("IDM导出文件下载", str, "idm.ef2");
},
'Orbit导出': function(todown) {
//console.log(todown);
var str = "";
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
str += TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))+'|'+TLE.safe_title(file.title.replace("|", "_"))+'||gdriveid='+todown.gdriveid+'\r\n';
});
});
TLE.file_pop("Orbit导出文件下载", str, "orbit.olt");
},
'eagleget导出': function(todown) {
var ret = {tasks: []};
$.each(todown.tasklist, function(n, task) {
$.each(task.filelist, function(l, file) {
if (!file.downurl) return;
ret.tasks.push({
cookie: 'gdriveid='+todown.gdriveid,
fname: TLE.safe_title(file.title),
url: TLE.url_rewrite(file.downurl, TLE.safe_title(file.title))
});
});
});
TLE.file_pop("Eagleget导出文件下载(test)", JSON.stringify(ret), "eagleget.eg");
},
};
(function(TLE) {
function get_taskinfo(taskid) {
return {
taskname: $("#tr_c"+taskid+" .title .w_title").attr("title"),
title: $("#tr_c"+taskid+" .title .w_title").attr("title"),
f_url: $("#f_url"+taskid).val(),
downurl: $("#dl_url"+taskid).val(),
cid: $("#dcid"+taskid).val(),
gcid: $("#gcid"+taskid).val(),
size: parseInt($("#ysfilesize"+taskid).val()),
tasktype: parseInt($("#d_tasktype"+taskid).val()),
status: $("#d_status"+taskid).val(),
};
}
function get_bt_taskinfo(taskid) {
return {
title: $("#bt_taskname"+taskid).val(),
f_url: $("#bturl"+taskid).val(),
downurl: $("#btdownurl"+taskid).val(),
cid: $("#btcid"+taskid).val(),
gcid: $("#btgcid"+taskid).val(),
size: $("#bt_filesize"+taskid).val(),
status: $("#btd_status"+taskid).val(),
};
}
function build_bt_taskinfo(info, rdata) {
var taskinfo = {
'taskname': info.taskname,
'f_url': info.f_url,
'cid': info.dcid,
'size': parseInt(info.ysfilesize),
'tasktype': parseInt(info.d_tasktype),
'status': info.d_status,
};
var filelist = [];
$.each(rdata, function(n, e) {
filelist.push({
'title': e.title,
'f_url': e.url,
'downurl': e.downurl,
'cid': e.cid,
'gcid': e.gcid,
'size': parseInt(e.filesize),
});
});
taskinfo['filelist'] = filelist;
return taskinfo;
};
TLE.safe_title = function safe_title(title) {
return title.replace(/[\\\|\:\*\"\?\<\>]/g,"_");
};
TLE.bt_down = function(_this, _do) {
var ck = document.getElementsByName("bt_list_ck");
var files = [];
$.each(ck, function(n, e) {
if (e.checked == false) return;
var fid = e.getAttribute("_i");
var file = {
'title': $("#bt_taskname"+fid).val(),
'url': $("#bturl"+fid).val(),
'downurl': $("#btdownurl"+fid).val(),
'cid': $("#btcid"+fid).val(),
'gcid': $("#btgcid"+fid).val(),
'filesize': $("#bt_filesize"+fid).val(),
};
files.push(file);
});
var taskid = $("#view_bt_taskid").val();
var info = get_taskinfo($("#tr_c"+taskid));
var todown = {};
todown.gdriveid = $("#cok").val() || getCookie("gdriveid");
todown.tasklist = {};
todown.tasklist[taskid] = build_bt_taskinfo(info, files);
//console.log(todown);
_do(todown);
//console.log("bt_down");
};
TLE.text_pop = function(title, content) {
content = $('<div></div>').text(content).html()
content = '<textarea style="width: 100%; height: 260px;">'+content+'</textarea>'
$("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
//onHide: function() { $(document.body).click(); },
});
};
TLE.file_pop = function(title, content, filename) {
var url = "data:text/html;charset=utf-8,"+encodeURIComponent(content);
if (isChrome) {
$('<a href="'+url+'" target="_blank" style="display:none;" download="'+filename+'"></a>').appendTo('body').get(0).click();
} else {
var content = '<div style="width: 100%; height: 100px;">'
+'<div style="padding: 30px 0 0 30%;">'
+'<a href="'+url+'" target="_blank" title="右键另存为" class="pop_btn" download="'+filename+'"><span><em class="TLE_icdwlocal">导出文件</em></span></a>'
+(isChrome ? '' : '(右键另存为'+filename+')')
+'</div>'
+'</div>'
$("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
//onHide: function() { $(document.body).click(); },
});
}
};
TLE.window_pop = function(title, content) {
$("#TLE_text_pop").tpl("TLE_text_tpl", {'title': title, 'content': content}).show().pop({
//onHide: function() { $(document.body).click(); },
});
};
TLE.tip = function(content, time) {
TS2.show(content, time);
};
TLE.hide_tip = function() {
TS2.hide();
};
TLE.multiple_server_fix = function(url) {
return "'"+url.replace("gdl", "'{gdl,dl.{f,g,h,i,twin}}'")+"'";
}
function encode_utf8(s) {
return unescape( encodeURIComponent( s ) );
};
function to_hex(num) {
var s = num.toString(16);
if (s.length == 1)
return '0'+s;
else
return s;
};
var thunder_filename_mask = [0x61, 0x31, 0xe4, 0x5f, 0x00, 0x00, 0x00, 0x00];
function thunder_filename_encode(filename) {
var result = ["01", ];
$.each(encode_utf8(filename), function(i, n) {
result.push(to_hex(n.charCodeAt(0)^thunder_filename_mask[i%8]).toUpperCase())
});
while (result.length % 8 != 1) {
result.push(to_hex(thunder_filename_mask[(result.length-1)%8]).toUpperCase());
}
return result.join("");
};
TLE.url_rewrite = function(url, filename) {
url = url.replace(/&n=\w+/, "&n="+thunder_filename_encode(filename));
return url;
};
var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
TLE.escape_command = function(str) {
var result = "";
for (var i = 0; i < str.length; i++) {
if (alpha.indexOf(str[i]) == -1)
result += "\\"+str[i];
else
result += str[i];
}
return result;
};
//setting
TLE.getConfig = function(key) {
if (window.localStorage) {
return window.localStorage.getItem(key) || "";
} else {
return getCookie(key);
}
};
TLE.setConfig = function(key, value) {
if (window.localStorage) {
window.localStorage.setItem(key, value);
} else {
setGdCookie(key, value, 86400*365);
}
};
//set default config
if (TLE.getConfig("TLE_exporter") == "") {
var exporters = [];
for (var key in TLE.exporter) {
exporters.push(key);
};
TLE.setConfig("TLE_exporter", exporters.join("|"));
};
function init() {
//css
$("head").append('<style>'
+'#TLE_setting { padding: 10px 20px 20px 20px; }'
+'#TLE_setting span { padding-left: 1em; }'
+'#TLE_setting li { margin-top: 0.5em; }'
+'#TLE_exporter_select { padding: 10px 20px 20px 20px; }'
+'</style>');
//pop
$("body").append('<div id="TLE_text_pop" class="lixian_pop_wp pop_w400" style="display:none;margin:0;"></div>');
$("body").append('<textarea id="TLE_text_tpl" style="display: none;"></textarea>');
$("#TLE_text_tpl").text('<div class="lixian_pop">'
+'<div class="l_p_hd">'
+'<h3>$[title]</h3>'
+'</div>'
+'<div class="l_p_bd">'
+'$[content]'
+'</div>'
+'<a class="pop_close" title="关闭浮层" close="1" id="close">关闭浮层</a>'
+'</div>');
//setting
$("#view_down_bar ul").prepend('<li> <a href="#" id="TLE_setting_anchor">TLE设置</a></li>');
$("#TLE_setting_anchor").on("click", function() {
var content = '<div id="TLE_setting"><ul>'
+'<li><b>启用以下导出器</b></li>'
+'<li>'+(function(){
var enabled_exporter = TLE.getConfig("TLE_exporter").split("|");
var str = '';
for (var name in TLE.exporter) {
str += '<span class="rw_col"><input type="checkbox" class="TLE_setting_ck" name="TLE_ck_'+name+'" '+(enabled_exporter.indexOf(name) == -1 ? "" : "checked")+' />'+name+'</span>';
}
return str;
})()+'</li>'
+'<li><b>Aria2 JSON-RPC Path</b></li>'
+'<li>Path: <input type="text" id="TLE_aria2_jsonrpc" style="width: 350px" value="'+TLE.getConfig("TLE_aria2_jsonrpc")+'"/></li>'
+'</ul>'
+'</div>'
+'</div>'
+'<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>';