forked from yutaoxie/baiduyun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baiduyun.user.js
1947 lines (1805 loc) · 86.9 KB
/
baiduyun.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 网盘直链下载助手
// @namespace https://github.com/syhyz1990/baiduyun
// @version 4.1.6
// @icon https://www.baiduyun.wiki/48x48.png
// @description 【网盘直链下载助手】是一款免客户端获取百度网盘文件真实下载地址的油猴插件,支持Windows,Mac,Linux,Android等多平台,可使用IDM,XDown等多线程加速工具加速下载,支持RPC协议远程下载。
// @license AGPL
// @supportURL https://github.com/syhyz1990/baiduyun
// @updateURL https://www.baiduyun.wiki/baiduyun.user.js
// @downloadURL https://www.baiduyun.wiki/baiduyun.user.js
// @match *://pan.baidu.com/disk/home*
// @match *://yun.baidu.com/disk/home*
// @match *://pan.baidu.com/s/*
// @match *://yun.baidu.com/s/*
// @match *://pan.baidu.com/share/*
// @match *://yun.baidu.com/share/*
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js
// @require https://cdn.jsdelivr.net/npm/sweetalert2@9
// @connect baidu.com
// @connect baidupcs.com
// @connect baiduyun.wiki
// @connect *
// @run-at document-idle
// @grant unsafeWindow
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_download
// @grant GM_setClipboard
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_openInTab
// @grant GM_info
// @grant GM_registerMenuCommand
// ==/UserScript==
;(() => {
'use strict';
const version = '4.1.6';
const realVersion = GM_info.script.version;
const classMap = {
'bar-search': 'OFaPaO',
'list-tools': 'tcuLAu',
'header': 'vyQHNyb'
};
const hostname = location.hostname;
const errorMsg = {
'dir': '提示:不支持整个文件夹下载,可进入文件夹内获取文件链接下载!',
'unlogin': '提示:登录网盘后才能使用此功能哦!',
'fail': '提示:获取下载链接失败!请刷新网页后重试!',
'unselected': '提示:请先选择要下载的文件!',
'morethan': '提示:多个文件请点击【显示链接】!',
'toobig': '提示:只支持300M以下的文件夹,若链接无法下载,请进入文件夹后勾选文件获取!',
'timeout': '提示:页面过期,请刷新重试!',
'wrongcode': '提示:获取验证码失败!',
'deleted': '提示:文件不存在或已被百度和谐,无法下载!',
};
let defaultCode = 250528;
let secretCode = getValue('secretCodeV') ? getValue('secretCodeV') : defaultCode;
let ids = [];
let userAgent = '';
let number = ['', '①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨'];
let Toast = Swal.mixin({
toast: true,
position: 'top',
showConfirmButton: false,
timer: 3000,
timerProgressBar: false,
onOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
let ariaRPC = {
domain: getValue('rpcDomain') ? getValue('rpcDomain') : 'http://localhost',
port: getValue('rpcPort') ? getValue('rpcPort') : 6800,
token: getValue('rpcToken') ? getValue('rpcToken') : '',
dir: getValue('rpcDir') ? getValue('rpcDir') : 'D:/',
};
function clog(c1, c2, c3) {
c1 = c1 ? c1 : '';
c2 = c2 ? c2 : '';
c3 = c3 ? c3 : '';
console.group('[网盘直链下载助手]');
console.log(c1, c2, c3);
console.groupEnd();
}
function getBDUSS() {
let baiduyunPlugin_BDUSS = getStorage('baiduyunPlugin_BDUSS') ? getStorage('baiduyunPlugin_BDUSS') : '{"baiduyunPlugin_BDUSS":""}';
let BDUSS = JSON.parse(baiduyunPlugin_BDUSS).BDUSS;
if (!BDUSS) {
Swal.fire({
icon: 'error',
title: '提示',
html: 'Aria链接获取需要配合<a href="https://www.baiduyun.wiki/zh-cn/assistant.html" target="_blank">【网盘万能助手】使用</a>',
footer: '【网盘万能助手】是增强扩展插件,安装后请刷新',
confirmButtonText: '安装'
}).then((result) => {
if (result.value) {
GM_openInTab('https://www.baiduyun.wiki/zh-cn/assistant.html', {active: true});
}
});
}
return BDUSS;
}
function aria2c(link, filename, ua) {
let BDUSS = getBDUSS();
ua = ua || userAgent;
if (BDUSS) {
return encodeURIComponent(`aria2c "${link}" --out "${filename}" --header "User-Agent: ${ua}" --header "Cookie: BDUSS=${BDUSS}"`);
} else {
return '请先安装网盘万能助手,安装后请重启浏览器!!!';
}
}
function replaceLink(link) {
return link ? link.replace(/&/g, '&') : '';
}
function detectPage() {
let regx = /[\/].+[\/]/g;
let page = location.pathname.match(regx);
return page[0].replace(/\//g, '');
}
function getCookie(e) {
let o, t;
let n = document, c = decodeURI;
return n.cookie.length > 0 && (o = n.cookie.indexOf(e + "="), -1 != o) ? (o = o + e.length + 1, t = n.cookie.indexOf(";", o), -1 == t && (t = n.cookie.length), c(n.cookie.substring(o, t))) : "";
}
function setCookie(key, value, t) {
let oDate = new Date(); //创建日期对象
oDate.setTime(oDate.getTime() + t * 60 * 1000); //设置过期时间
document.cookie = key + '=' + value + ';expires=' + oDate.toGMTString(); //设置cookie的名称,数值,过期时间
}
function getValue(name) {
return GM_getValue(name);
}
function setValue(name, value) {
GM_setValue(name, value);
}
function getStorage(key) {
return localStorage.getItem(key);
}
function setStorage(key, value) {
return localStorage.setItem(key, value);
}
function getLogID() {
let name = "BAIDUID";
let u = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/~!@#¥%……&";
let d = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
let f = String.fromCharCode;
function l(e) {
if (e.length < 2) {
let n = e.charCodeAt(0);
return 128 > n ? e : 2048 > n ? f(192 | n >>> 6) + f(128 | 63 & n) : f(224 | n >>> 12 & 15) + f(128 | n >>> 6 & 63) + f(128 | 63 & n);
}
let n = 65536 + 1024 * (e.charCodeAt(0) - 55296) + (e.charCodeAt(1) - 56320);
return f(240 | n >>> 18 & 7) + f(128 | n >>> 12 & 63) + f(128 | n >>> 6 & 63) + f(128 | 63 & n);
}
function g(e) {
return (e + "" + Math.random()).replace(d, l);
}
function m(e) {
let n = [0, 2, 1][e.length % 3];
let t = e.charCodeAt(0) << 16 | (e.length > 1 ? e.charCodeAt(1) : 0) << 8 | (e.length > 2 ? e.charCodeAt(2) : 0);
let o = [u.charAt(t >>> 18), u.charAt(t >>> 12 & 63), n >= 2 ? "=" : u.charAt(t >>> 6 & 63), n >= 1 ? "=" : u.charAt(63 & t)];
return o.join("");
}
function h(e) {
return e.replace(/[\s\S]{1,3}/g, m);
}
function p() {
return h(g((new Date()).getTime()));
}
function w(e, n) {
return n ? p(String(e)).replace(/[+\/]/g, (e) => {
return "+" == e ? "-" : "_";
}).replace(/=/g, "") : p(String(e));
}
return w(getCookie(name));
}
function Dialog() {
let linkList = [];
let showParams;
let dialog, shadow;
function createDialog() {
let screenWidth = document.body.clientWidth;
let dialogLeft = screenWidth > 800 ? (screenWidth - 800) / 2 : 0;
let $dialog_div = $('<div class="dialog" style="width: 800px; top: 0px; bottom: auto; left: ' + dialogLeft + 'px; right: auto; display: hidden; visibility: visible; z-index: 52;"></div>');
let $dialog_header = $('<div class="dialog-header"><h3><span class="dialog-title" style="display:inline-block;width:740px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis"></span></h3></div>');
let $dialog_control = $('<div class="dialog-control"><span class="dialog-icon dialog-close">×</span></div>');
let $dialog_body = $('<div class="dialog-body"></div>');
let $dialog_tip = $('<div class="dialog-tip"><p></p></div>');
$dialog_div.append($dialog_header.append($dialog_control)).append($dialog_body);
let $dialog_button = $('<div class="dialog-button" style="display:none"></div>');
let $dialog_button_div = $('<div style="display:table;margin:auto"></div>');
let $dialog_copy_button = $('<button id="dialog-copy-button">复制全部默认链接</button>');
let $dialog_edit_button = $('<button id="dialog-edit-button" style="display:none">编辑</button>');
let $dialog_exit_button = $('<button id="dialog-exit-button" style="display:none">退出</button>');
$dialog_button_div.append($dialog_copy_button).append($dialog_edit_button).append($dialog_exit_button);
$dialog_button.append($dialog_button_div);
$dialog_div.append($dialog_button);
$dialog_copy_button.click(() => {
let content = '';
if (showParams.type === 'batch') {
$.each(linkList, (index, element) => {
if (index === linkList.length - 1)
content += element.downloadlink[0];
else
content += element.downloadlink[0] + '\r\n';
});
}
if (showParams.type === 'batchAria') {
$.each(linkList, (index, element) => {
if (index === linkList.length - 1)
content += decodeURIComponent(aria2c(element.dlink, element.filename, userAgent));
else
content += decodeURIComponent(aria2c(element.dlink, element.filename, userAgent) + '\r\n');
});
}
if (showParams.type === 'rpc') {
$.each(linkList, (index, element) => {
if (index === linkList.length - 1)
content += element.downloadlink;
else
content += element.downloadlink + '\r\n';
});
}
if (showParams.type === 'shareLink') {
$.each(linkList, (index, element) => {
if (element.dlink == 'error')
return;
if (index == linkList.length - 1)
content += element.dlink;
else
content += element.dlink + '\r\n';
});
}
if (showParams.type == 'shareAriaLink') {
$.each(linkList, (index, element) => {
if (element.dlink == 'error')
return;
if (index == linkList.length - 1)
content += decodeURIComponent(aria2c(element.dlink, element.server_filename));
else
content += decodeURIComponent(aria2c(element.dlink, element.server_filename) + '\r\n');
});
}
GM_setClipboard(content, 'text');
if (content != '') {
Toast.fire({
icon: 'success',
text: '已将链接复制到剪贴板!'
});
} else {
Toast.fire({
icon: 'error',
text: '复制失败,请手动复制!'
});
}
});
$dialog_edit_button.click(() => {
let $dialog_textarea = $('div.dialog-body textarea[name=dialog-textarea]', dialog);
let $dialog_item = $('div.dialog-body div', dialog);
$dialog_item.hide();
$dialog_copy_button.hide();
$dialog_edit_button.hide();
$dialog_textarea.show();
$dialog_radio_div.show();
$dialog_exit_button.show();
});
$dialog_exit_button.click(() => {
let $dialog_textarea = $('div.dialog-body textarea[name=dialog-textarea]', dialog);
let $dialog_item = $('div.dialog-body div', dialog);
$dialog_textarea.hide();
$dialog_radio_div.hide();
$dialog_item.show();
$dialog_exit_button.hide();
$dialog_copy_button.show();
$dialog_edit_button.show();
});
$dialog_div.append($dialog_tip);
$('body').append($dialog_div);
$dialog_control.click(dialogControl);
return $dialog_div;
}
function createShadow() {
let $shadow = $('<div class="dialog-shadow" style="position: fixed; left: 0px; top: 0px; z-index: 50; background: rgb(0, 0, 0) none repeat scroll 0% 0%; opacity: 0.5; width: 100%; height: 100%; display: none;"></div>');
$('body').append($shadow);
return $shadow;
}
this.open = (params) => {
showParams = params;
linkList = [];
if (params.type == 'link') {
linkList = params.list.urls;
$('div.dialog-header h3 span.dialog-title', dialog).text(params.title + ":" + params.list.filename);
$.each(params.list.urls, (index, element) => {
element.url = replaceLink(element.url);
let $div = $('<div><div style="width:30px;float:left">' + element.rank + ':</div><div style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis"><a href="' + element.url + '">' + element.url + '</a></div></div>');
$('div.dialog-body', dialog).append($div);
});
}
//批量下载 - 我的网盘
if (params.type === 'batch' || params.type === 'batchAria' || params.type === 'batchAriaRPC' || params.type === 'pcs') {
linkList = params.list;
$('div.dialog-header h3 span.dialog-title', dialog).text(params.title);
$.each(params.list, (index, element) => {
let $div = $('<div class="row"><div class="ui-title" title="' + element.filename + '">' + element.filename + '</div><span>:</span></div>');
if (params.type === 'batch') { //API
$.each(element.downloadlink, (i, e) => {
if (i === 0) {
$div.append($('<a class="ui-link api-link" href="' + e + '" data-link=' + e + '>默认链接</a>'));
} else {
if (getValue('SETTING_B'))
$div.append($('<a class="ui-link api-link" href="' + e + '" data-link=' + e + '>备用链接' + number[i] + '</a>'));
}
});
}
if (params.type === 'pcs') { //PCS
$div.append($('<a class="ui-link pcs-link" data-filename=' + element.filename + ' data-link=' + element.dlink + ' href="javascript:;">' + element.dlink + '</a>'));
}
if (params.type === 'batchAria') { //Aria下载
let link = decodeURIComponent(aria2c(element.dlink, element.filename, userAgent));
$div.append($('<a class="ui-link aria-link" href="javascript:;">' + link + '</a>'));
}
if (params.type === 'batchAriaRPC') {
$div.append($('<button class="aria-rpc" data-link="' + element.dlink + '" data-filename="' + element.filename + '">点击发送到Aria下载器</button>'));
}
$('div.dialog-body', dialog).append($div);
});
}
if (params.type === 'shareLink') {
linkList = params.list;
$('div.dialog-header h3 span.dialog-title', dialog).text(params.title);
$.each(params.list, (index, element) => {
element.dlink = replaceLink(element.dlink);
if (element.isdir == 1) return;
let $div = $('<div class="row"><div class="ui-title" title="' + element.server_filename + '">' + element.server_filename + '</div><span>:</span><a href="' + element.dlink + '" class="share-download">' + element.dlink + '</a></div>');
$('div.dialog-body', dialog).append($div);
});
}
if (params.type === 'rpcLink') {
linkList = params.list;
$('div.dialog-header h3 span.dialog-title', dialog).text(params.title);
$.each(params.list, (index, element) => {
element.dlink = replaceLink(element.dlink);
if (element.isdir == 1) return;
let $div = $('<div class="row"><div class="ui-title" title="' + element.server_filename + '">' + element.server_filename + '</div><span>:</span><button class="aria-rpc" data-link="' + element.dlink + '" data-filename="' + element.server_filename + '">点击发送到Aria</button></div>');
$('div.dialog-body', dialog).append($div);
});
}
if (params.type === 'shareAriaLink') {
linkList = params.list;
$('div.dialog-header h3 span.dialog-title', dialog).text(params.title);
$.each(params.list, (index, element) => {
if (element.isdir == 1) return;
let link = decodeURIComponent(aria2c(element.dlink, element.server_filename));
let $div = $('<div class="row"><div class="ui-title" title="' + element.server_filename + '">' + element.server_filename + '</div><span>:</span><a href="javasctipt:void(0)" class="aria-link">' + link + '</a></div>');
$('div.dialog-body', dialog).append($div);
});
}
if (params.tip) {
$('div.dialog-tip p', dialog).html(params.tip);
}
if (params.showcopy) {
$('div.dialog-button', dialog).show();
$('div.dialog-button button#dialog-copy-button', dialog).show();
}
shadow.show();
dialog.show();
};
this.close = () => {
dialogControl();
};
function dialogControl() {
$('div.dialog-body', dialog).children().remove();
$('div.dialog-header h3 span.dialog-title', dialog).text('');
$('div.dialog-tip p', dialog).text('');
$('div.dialog-button', dialog).hide();
$('div.dialog-radio input[type=radio][name=showmode][value=multi]', dialog).prop('checked', true);
$('div.dialog-radio', dialog).hide();
$('div.dialog-button button#dialog-copy-button', dialog).hide();
$('div.dialog-button button#dialog-edit-button', dialog).hide();
$('div.dialog-button button#dialog-exit-button', dialog).hide();
dialog.hide();
shadow.hide();
}
dialog = createDialog();
shadow = createShadow();
}
function VCodeDialog(refreshVCode, confirmClick) {
let dialog, shadow;
function createDialog() {
let screenWidth = document.body.clientWidth;
let dialogLeft = screenWidth > 520 ? (screenWidth - 520) / 2 : 0;
let $dialog_div = $('<div class="dialog" id="dialog-vcode" style="width:520px;top:0px;bottom:auto;left:' + dialogLeft + 'px;right:auto;display:none;visibility:visible;z-index:52"></div>');
let $dialog_header = $('<div class="dialog-header"><h3><span class="dialog-header-title"><em class="select-text">提示</em></span></h3></div>');
let $dialog_control = $('<div class="dialog-control"><span class="dialog-icon dialog-close icon icon-close"><span class="sicon">x</span></span></div>');
let $dialog_body = $('<div class="dialog-body"></div>');
let $dialog_body_div = $('<div style="text-align:center;padding:22px"></div>');
let $dialog_body_download_verify = $('<div class="download-verify" style="margin-top:10px;padding:0 28px;text-align:left;font-size:12px;"></div>');
let $dialog_verify_body = $('<div class="verify-body">请输入验证码:</div>');
let $dialog_input = $('<input id="dialog-input" type="text" style="padding:3px;width:85px;height:23px;border:1px solid #c6c6c6;background-color:white;vertical-align:middle;" class="input-code" maxlength="4">');
let $dialog_img = $('<img id="dialog-img" class="img-code" style="margin-left:10px;vertical-align:middle;" alt="点击换一张" src="" width="100" height="30">');
let $dialog_refresh = $('<a href="javascript:;" style="text-decoration:underline;" class="underline">换一张</a>');
let $dialog_err = $('<div id="dialog-err" style="padding-left:84px;height:18px;color:#d80000" class="verify-error"></div>');
let $dialog_footer = $('<div class="dialog-footer g-clearfix"></div>');
let $dialog_confirm_button = $('<a class="g-button g-button-blue" data-button-id="" data-button-index href="javascript:;" style="padding-left:36px"><span class="g-button-right" style="padding-right:36px;"><span class="text" style="width:auto;">确定</span></span></a>');
let $dialog_cancel_button = $('<a class="g-button" data-button-id="" data-button-index href="javascript:;" style="padding-left: 36px;"><span class="g-button-right" style="padding-right: 36px;"><span class="text" style="width: auto;">取消</span></span></a>');
$dialog_header.append($dialog_control);
$dialog_verify_body.append($dialog_input).append($dialog_img).append($dialog_refresh);
$dialog_body_download_verify.append($dialog_verify_body).append($dialog_err);
$dialog_body_div.append($dialog_body_download_verify);
$dialog_body.append($dialog_body_div);
$dialog_footer.append($dialog_confirm_button).append($dialog_cancel_button);
$dialog_div.append($dialog_header).append($dialog_body).append($dialog_footer);
$('body').append($dialog_div);
$dialog_control.click(dialogControl);
$dialog_img.click(refreshVCode);
$dialog_refresh.click(refreshVCode);
$dialog_input.keypress((event) => {
if (event.which == 13)
confirmClick();
});
$dialog_confirm_button.click(confirmClick);
$dialog_cancel_button.click(dialogControl);
$dialog_input.click(() => {
$('#dialog-err').text('');
});
return $dialog_div;
}
this.open = (vcode) => {
if (vcode)
$('#dialog-img').attr('src', vcode.img);
dialog.show();
shadow.show();
};
this.close = () => {
dialogControl();
};
dialog = createDialog();
shadow = $('div.dialog-shadow');
function dialogControl() {
$('#dialog-img', dialog).attr('src', '');
$('#dialog-err').text('');
dialog.hide();
shadow.hide();
}
}
//网盘页面的下载助手
function PanHelper() {
let yunData, sign, timestamp, bdstoken, logid, fid_list;
let fileList = [], selectFileList = [], batchLinkList = [], batchLinkListAll = [], linkList = [];
let dialog, searchKey;
let panAPIUrl = location.protocol + "//" + location.host + "/api/";
let restAPIUrl = location.protocol + "//pcs.baidu.com/rest/2.0/pcs/";
let clientAPIUrl = location.protocol + "//pan.baidu.com/rest/2.0/";
this.init = () => {
yunData = unsafeWindow.yunData;
clog('初始化信息:', yunData);
if (yunData === undefined) {
clog('页面未正常加载,或者百度已经更新!');
return false;
}
initVar();
registerEventListener();
addButton();
createIframe();
dialog = new Dialog({addCopy: true});
clog('下载助手加载成功!当前版本:', version);
};
//获取选中文件
function getSelectedFile() {
return require("disk-system:widget/pageModule/list/listInit.js").getCheckedItems();
}
//初始化变量
function initVar() {
sign = getSign();
timestamp = yunData.timestamp;
bdstoken = yunData.MYBDSTOKEN;
logid = getLogID();
}
function registerEventListener() {
registerDownload();
}
//下载事件
function registerDownload() {
$(document).on('click', '.api-link', (e) => {
e.preventDefault();
if (e.target.dataset.link) {
execDownload(e.target.dataset.link);
}
});
$(document).on('click', '.aria-rpc', (e) => {
let link = e.target.dataset.link;
let filename = e.target.dataset.filename;
let url = ariaRPC.domain + ":" + ariaRPC.port + '/jsonrpc';
let json_rpc = {
id: new Date().getTime(),
jsonrpc: '2.0',
method: 'aria2.addUri',
params: [
"token:" + ariaRPC.token,
[link],
{
dir: ariaRPC.dir,
out: filename,
header: ['User-Agent:' + userAgent, 'Cookie: BDUSS=' + getBDUSS()]
}
]
};
GM_xmlhttpRequest({
method: "POST",
headers: {"User-Agent": userAgent},
url: url,
responseType: 'json',
timeout: 3000,
data: JSON.stringify(json_rpc),
onload: (response) => {
if (response.response.result) {
Toast.fire({
icon: 'success',
title: '任务已发送至RPC下载器'
});
} else {
Toast.fire({
icon: 'error',
title: response.response.message
});
}
},
ontimeout: () => {
Toast.fire({
icon: 'error',
title: '连接到RPC服务器超时,请检查RPC配置'
});
}
});
});
}
//我的网盘 - 添加助手按钮
function addButton() {
$('div.' + classMap['bar-search']).css('width', '18%');
let $dropdownbutton = $('<span class="g-dropdown-button"></span>');
let $dropdownbutton_a = $('<a class="g-button" href="javascript:;"><span class="g-button-right"><em class="icon icon-download"></em><span class="text" style="width: 60px;">下载助手</span></span></a>');
let $dropdownbutton_span = $('<span class="menu" style="width:114px"></span>');
let $directbutton = $('<span class="g-button-menu" style="display:block"></span>');
let $directbutton_span = $('<span class="g-dropdown-button g-dropdown-button-second" menulevel="2"></span>');
let $directbutton_a = $('<a class="g-button" href="javascript:;"><span class="g-button-right"><span class="text" style="width:auto">直链下载</span></span></a>');
let $directbutton_menu = $('<span class="menu" style="width:120px;left:79px"></span>');
let $directbutton_batchhttplink_button = $('<a id="batchhttplink-direct" class="g-button-menu" href="javascript:;">显示链接</a>');
$directbutton_menu.append($directbutton_batchhttplink_button);
$directbutton.append($directbutton_span.append($directbutton_a).append($directbutton_menu));
$directbutton.hover(() => {
$directbutton_span.toggleClass('button-open');
});
$directbutton_batchhttplink_button.click(batchClick);
let $pcsbutton = $('<span class="g-button-menu" style="display:block"></span>');
let $pcsbutton_span = $('<span class="g-dropdown-button g-dropdown-button-second" menulevel="2"></span>');
let $pcsbutton_a = $('<a class="g-button" href="javascript:;"><span class="g-button-right"><span class="text" style="width:auto">API下载</span></span></a>');
let $pcsbutton_menu = $('<span class="menu" style="width:120px;left:79px"></span>');
let $pcsbutton_batchhttplink_button = $('<a id="batchhttplink-pcs" class="g-button-menu" href="javascript:;">显示链接</a>');
$pcsbutton_menu.append($pcsbutton_batchhttplink_button);
$pcsbutton.append($pcsbutton_span.append($pcsbutton_a).append($pcsbutton_menu));
$pcsbutton.hover(() => {
$pcsbutton_span.toggleClass('button-open');
});
$pcsbutton_batchhttplink_button.click(batchClick);
let $ariadirectbutton = $('<span class="g-button-menu" style="display:block"></span>');
let $ariadirectbutton_span = $('<span class="g-dropdown-button g-dropdown-button-second" menulevel="2"></span>');
let $ariadirectbutton_a = $('<a class="g-button" href="javascript:;"><span class="g-button-right"><span class="text" style="width:auto">Aria下载</span></span></a>');
let $ariadirectbutton_menu = $('<span class="menu" style="width:120px;left:79px"></span>');
let $ariadirectbutton_batchhttplink_button = $('<a id="batchhttplink-aria" class="g-button-menu" href="javascript:;">显示链接</a>');
$ariadirectbutton_menu.append($ariadirectbutton_batchhttplink_button);
$ariadirectbutton.append($ariadirectbutton_span.append($ariadirectbutton_a).append($ariadirectbutton_menu));
$ariadirectbutton.hover(() => {
$ariadirectbutton_span.toggleClass('button-open');
});
$ariadirectbutton_batchhttplink_button.click(batchClick);
let $ariarpcbutton = $('<span class="g-button-menu" style="display:block"></span>');
let $ariarpcbutton_span = $('<span class="g-dropdown-button g-dropdown-button-second" menulevel="2"></span>');
let $ariarpcbutton_a = $('<a class="g-button" href="javascript:;"><span class="g-button-right"><span class="text" style="width:auto">RPC下载</span></span></a>');
let $ariarpcbutton_menu = $('<span class="menu" style="width:120px;left:79px"></span>');
let $ariarpcbutton_batchhttplink_button = $('<a id="batchhttplink-rpc" class="g-button-menu" href="javascript:;">显示链接</a>');
let $ariarpcbutton_setting_button = $('<a class="g-button-menu" href="javascript:;">RPC配置</a>');
$ariarpcbutton_menu.append($ariarpcbutton_batchhttplink_button).append($ariarpcbutton_setting_button);
$ariarpcbutton.append($ariarpcbutton_span.append($ariarpcbutton_a).append($ariarpcbutton_menu));
$ariarpcbutton.hover(() => {
$ariarpcbutton_span.toggleClass('button-open');
});
$ariarpcbutton_batchhttplink_button.click(batchClick);
$ariarpcbutton_setting_button.click(rpcSetting);
let $apibutton = $('<span class="g-button-menu" style="display:block"></span>');
let $apibutton_span = $('<span class="g-dropdown-button g-dropdown-button-second" menulevel="2"></span>');
let $apibutton_a = $('<a class="g-button" href="javascript:;"><span class="g-button-right"><span class="text" style="width:auto">API下载</span></span></a>');
let $apibutton_menu = $('<span class="menu" style="width:120px;left:77px"></span>');
let $apibutton_download_button = $('<a id="download-api" class="g-button-menu" href="javascript:;">直接下载</a>');
let $apibutton_batchhttplink_button = $('<a id="batchhttplink-api" class="g-button-menu" href="javascript:;">显示链接</a>');
let $setting_button = $('<a id="appid-setting" class="g-button-menu" href="javascript:;">神秘代码</a>');
let $default_setting = $('<a id="default-setting" class="g-button-menu" href="javascript:;" style="color: #999;">恢复默认</a>');
$apibutton_menu.append($apibutton_download_button).append($apibutton_batchhttplink_button)/*.append($setting_button).append($default_setting)*/;
$apibutton.append($apibutton_span.append($apibutton_a).append($apibutton_menu));
$apibutton.hover(() => {
$apibutton_span.toggleClass('button-open');
});
$apibutton_download_button.click(downloadClick);
$apibutton_batchhttplink_button.click(batchClick);
$setting_button.click(setSecretCode);
$default_setting.click(defaultSetting);
$dropdownbutton_span.append($pcsbutton).append($ariadirectbutton).append($ariarpcbutton);
$dropdownbutton.append($dropdownbutton_a).append($dropdownbutton_span);
$dropdownbutton.hover(() => {
$dropdownbutton.toggleClass('button-open');
});
$('.' + classMap['list-tools']).append($dropdownbutton);
$('.' + classMap['list-tools']).css('height', '40px');
}
function rpcSetting() {
let dom = '';
dom += '<div class="flex-center-between"><label for="rpcDomain" style="margin-right: 5px;flex: 0 0 100px;">主机:</label><input type="text" id="rpcDomain" value="' + ariaRPC.domain + '" class="swal2-input" placeholder="http://localhost"></div>';
dom += '<div class="flex-center-between"><label for="rpcPort" style="margin-right: 5px;flex: 0 0 100px;">端口:</label><input type="text" id="rpcPort" value="' + ariaRPC.port + '" class="swal2-input" placeholder="6800"></div>';
dom += '<div class="flex-center-between"><label for="rpcToken" style="margin-right: 5px;flex: 0 0 100px;">密钥:</label><input type="text" id="rpcToken" value="' + ariaRPC.token + '" class="swal2-input" placeholder="没有留空"></div>';
dom += '<div class="flex-center-between"><label for="rpcDir" style="margin-right: 5px;flex: 0 0 100px;">下载路径:</label><input type="text" id="rpcDir" value="' + ariaRPC.dir + '" class="swal2-input" placeholder="默认为D:\"></div>';
dom = '<div>' + dom + '</div>';
let $dom = $(dom);
Swal.fire({
title: 'RPC配置',
allowOutsideClick: false,
html: $dom[0],
showCancelButton: true,
confirmButtonText: '保存',
cancelButtonText: '取消'
}
).then((result) => {
if (result.value) {
setValue('rpcDomain', $('#rpcDomain').val() ? $('#rpcDomain').val() : ariaRPC.domain);
setValue('rpcPort', $('#rpcPort').val() ? $('#rpcPort').val() : ariaRPC.port);
setValue('rpcToken', $('#rpcToken').val());
setValue('rpcDir', $('#rpcDir').val() ? $('#rpcDir').val() : ariaRPC.dir);
history.go(0);
}
});
}
//设置神秘代码
function setSecretCode() {
Swal.fire({
title: '请输入神秘代码',
input: 'text',
inputValue: secretCode,
showCancelButton: true,
confirmButtonText: '确定',
cancelButtonText: '取消',
inputValidator: (value) => {
if (value.length != 6) {
return '请输入正确的神秘代码';
}
}
}).then((result) => {
setValue('secretCodeV', result.value);
Toast.fire({
icon: 'success',
text: '神秘代码执行成功,3s后将自动刷新!'
}).then(() => {
history.go(0);
});
});
}
function defaultSetting() {
setValue('secretCodeV', defaultCode);
Toast.fire({
text: '恢复默认成功,3s后将自动刷新',
icon: 'success'
}).then(() => {
history.go(0);
});
}
function isSuperVIP() {
return yunData.ISSVIP === 1;
}
// 我的网盘 - 下载
function downloadClick(event) {
selectFileList = getSelectedFile();
clog('选中文件列表:', selectFileList);
let id = event.target.id;
let downloadLink;
if (id == 'download-direct') {
let downloadType;
if (selectFileList.length === 0) {
Toast.fire({
icon: 'error',
text: errorMsg.unselected
});
return;
}
if (selectFileList.length == 1) {
selectFileList[0].isdir === 1 ? downloadType = 'batch' : downloadType = 'dlink';
}
if (selectFileList.length > 1) {
downloadType = 'batch';
}
fid_list = getFidList(selectFileList);
let result = getDownloadLinkWithPanAPI(downloadType);
if (result.errno === 0) {
if (downloadType == 'dlink')
downloadLink = result.dlink[0].dlink;
else if (downloadType == 'batch') {
downloadLink = result.dlink;
if (selectFileList.length === 1)
downloadLink = downloadLink + '&zipname=' + encodeURIComponent(selectFileList[0].server_filename) + '.zip';
} else {
Toast.fire({
icon: 'error',
text: errorMsg.fail
});
return;
}
} else if (result.errno == -1) {
Toast.fire({
icon: 'error',
text: errorMsg.deleted
});
return;
} else if (result.errno == 112) {
Toast.fire({
icon: 'error',
text: errorMsg.timeout
});
return;
} else {
Toast.fire({
icon: 'error',
text: errorMsg.fail
});
return;
}
} else {
if (selectFileList.length === 0) {
Toast.fire({
icon: 'error',
text: errorMsg.unselected
});
return;
} else if (selectFileList.length > 1) {
Toast.fire({
icon: 'error',
text: errorMsg.morethan
});
return;
} else {
if (selectFileList[0].isdir == 1) {
Toast.fire({
icon: 'error',
text: errorMsg.dir
});
return;
}
}
if (id == 'download-api') {
downloadLink = getDownloadLinkWithRESTAPIBaidu(selectFileList[0].path);
}
}
execDownload(downloadLink);
}
//我的网盘 - 显示链接
function linkClick(event) {
selectFileList = getSelectedFile();
clog('选中文件列表:', selectFileList);
let id = event.target.id;
let linkList, tip;
if (id.indexOf('direct') != -1) {
let downloadType;
let downloadLink;
if (selectFileList.length === 0) {
Toast.fire({
icon: 'error',
text: errorMsg.unselected
});
return;
} else if (selectFileList.length == 1) {
if (selectFileList[0].isdir === 1)
downloadType = 'batch';
else if (selectFileList[0].isdir === 0)
downloadType = 'dlink';
} else if (selectFileList.length > 1) {
downloadType = 'batch';
}
fid_list = getFidList(selectFileList);
let result = getDownloadLinkWithPanAPI(downloadType);
if (result.errno === 0) {
if (downloadType == 'dlink')
downloadLink = result.dlink[0].dlink;
else if (downloadType == 'batch') {
clog('选中文件列表:', selectFileList);
downloadLink = result.dlink;
if (selectFileList.length === 1)
downloadLink = downloadLink + '&zipname=' + encodeURIComponent(selectFileList[0].server_filename) + '.zip';
} else {
Toast.fire({
icon: 'error',
text: errorMsg.fail
});
return;
}
} else if (result.errno == -1) {
Toast.fire({
icon: 'error',
text: errorMsg.deleted
});
return;
} else if (result.errno == 112) {
Toast.fire({
icon: 'error',
text: errorMsg.timeout
});
return;
} else {
Toast.fire({
icon: 'error',
text: errorMsg.fail
});
return;
}
let httplink = downloadLink.replace(/^([A-Za-z]+):/, 'http:');
let httpslink = downloadLink.replace(/^([A-Za-z]+):/, 'https:');
let filename = '';
$.each(selectFileList, (index, element) => {
if (selectFileList.length == 1)
filename = element.server_filename;
else {
if (index == 0)
filename = element.server_filename;
else
filename = filename + ',' + element.server_filename;
}
});
linkList = {
filename: filename,
urls: [
{url: httplink, rank: 1},
{url: httpslink, rank: 2}
]
};
tip = '显示百度网盘网页获取的链接,可以使用右键迅雷或IDM下载,多文件打包(限300k)下载的链接可以直接复制使用';
dialog.open({title: '下载链接', type: 'link', list: linkList, tip: tip});
} else {
if (selectFileList.length === 0) {
Toast.fire({
icon: 'error',
text: errorMsg.unselected
});
return;
} else if (selectFileList.length > 1) {
Toast.fire({
icon: 'error',
text: errorMsg.morethan
});
return;
} else {
if (selectFileList[0].isdir == 1) {
Toast.fire({
icon: 'error',
text: errorMsg.dir
});
return;
}
}
if (id.indexOf('api') != -1) {
let downloadLink = getDownloadLinkWithRESTAPIBaidu(selectFileList[0].path);
let httplink = downloadLink.replace(/^([A-Za-z]+):/, 'http:');
let httpslink = downloadLink.replace(/^([A-Za-z]+):/, 'https:');
linkList = {
filename: selectFileList[0].server_filename,
urls: [
{url: httplink, rank: 1},
{url: httpslink, rank: 2}
]
};
tip = '显示获取的链接(使用百度云ID),可以右键使用迅雷或IDM下载,直接复制链接无效';
dialog.open({title: '下载链接', type: 'link', list: linkList, tip: tip});
}
}
}
// 我的网盘 - 批量下载
function batchClick(event) {
selectFileList = getSelectedFile();
if (selectFileList.length === 0) {
Toast.fire({
icon: 'error',
text: errorMsg.unselected
});
return;
}
clog('选中文件列表:', selectFileList);
let id = event.target.id;
let linkType, tip;
linkType = id.indexOf('https') == -1 ? (id.indexOf('http') == -1 ? location.protocol + ':' : 'http:') : 'https:';
batchLinkList = [];
batchLinkListAll = [];
if (id.indexOf('direct') > 0) { //直链下载
batchLinkList = getPCSBatchLink(linkType);
let tip = '点击链接直接下载,若下载失败,请尝试其他方法或参考 <a href="https://www.baiduyun.wiki/zh-cn/question.html">常见问题</a>';
if (batchLinkList.length === 0) {
Toast.fire({
icon: 'error',
text: errorMsg.unselected
});
return;
}
dialog.open({title: '直链下载', type: 'batch', list: batchLinkList, tip: tip, showcopy: false});
}
if (id.indexOf('pcs') > 0) { //PCS下载
getPCSBatchLink((batchLinkList) => {
let tip = '点击链接直接下载,若下载失败,请尝试其他方法或参考 <a href="https://www.baiduyun.wiki/zh-cn/question.html">常见问题</a>';
if (batchLinkList.length === 0) {
Toast.fire({
icon: 'error',
text: errorMsg.unselected
});
return;
}
dialog.open({title: 'PCS下载', type: 'pcs', list: batchLinkList, tip: tip, showcopy: false});
});
}
if (id.indexOf('aria') > 0) { //ariaAPI下载
getPCSBatchLink((batchLinkList) => {
tip = '请先安装 <a href="https://www.baiduyun.wiki/zh-cn/assistant.html">网盘万能助手</a> 请将链接复制到支持Aria的下载器中, 推荐使用 <a href="http://pan.baiduyun.wiki/down">XDown</a>';
if (batchLinkList.length === 0) {
Toast.fire({
icon: 'error',
text: errorMsg.unselected
});