-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path秒传链接提取(es6).js
1102 lines (1015 loc) · 42.8 KB
/
秒传链接提取(es6).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 moe.cangku.mengzonefire
// @version 1.5.4
// @description 用于提取和生成百度网盘秒传链接
// @author mengzonefire
// @match *://pan.baidu.com/disk/home*
// @match *://yun.baidu.com/disk/home*
// @resource sweetalert2Css https://cdn.jsdelivr.net/npm/sweetalert2@8/dist/sweetalert2.min.css
// @require https://cdn.jsdelivr.net/npm/sweetalert2@8/dist/sweetalert2.min.js
// @require https://cdn.jsdelivr.net/npm/js-base64
// @require https://cdn.staticfile.org/spark-md5/3.0.0/spark-md5.min.js
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_setClipboard
// @grant GM_xmlhttpRequest
// @grant GM_info
// @grant GM_getResourceText
// @grant GM_addStyle
// @run-at document-start
// @connect *
// ==/UserScript==
! function () {
'use strict';
const meta_url = 'http://pcs.baidu.com/rest/2.0/pcs/file?app_id=778750&method=meta&path=';
const info_url = 'https://pan.baidu.com/rest/2.0/xpan/nas?method=uinfo';
const api_url = 'http://pan.baidu.com/rest/2.0/xpan/multimedia?method=listall&order=name&limit=10000';
const pcs_url = 'https://pcs.baidu.com/rest/2.0/pcs/file';
const appid_list = ['266719', '265486', '250528', '778750', '498065', '309847'];
//使用'250528', '265486', '266719', 下载50M以上的文件会报403, 黑号情况下部分文件也会报403
const bad_md5 = ['fcadf26fc508b8039bee8f0901d9c58e', '2d9a55b7d5fe70e74ce8c3b2be8f8e43', 'b912d5b77babf959865100bf1d0c2a19'];
const css_url = {
'Minimal': 'https://cdn.jsdelivr.net/npm/sweetalert2@8/dist/sweetalert2.min.css',
'Dark': 'https://cdn.jsdelivr.net/npm/@sweetalert2/theme-dark@4/dark.css',
'WordPress Admin': 'https://cdn.jsdelivr.net/npm/@sweetalert2/theme-wordpress-admin@4/wordpress-admin.css',
'Material UI': 'https://cdn.jsdelivr.net/npm/@sweetalert2/theme-material-ui@4/material-ui.css',
'Bulma': 'https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@4/bulma.css',
'Bootstrap 4': 'https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bootstrap-4@4/bootstrap-4.css'
};
var select_list,
failed = 0,
vip_type = 0,
interval = 0,
check_mode = false,
interval_mode = false,
file_info_list = [],
gen_success_list = [],
dir, file_num, gen_num, gen_prog, codeInfo, recursive, bdcode, xmlhttpRequest;
const myStyle = `style="width: 100%;height: 34px;display: block;line-height: 34px;text-align: center;"`;
const myBtnStyle = `style="height: 26px;line-height: 26px;vertical-align: middle;"`;
const html_btn = `<a class="g-button g-button-blue" id="bdlink_btn" title="秒传链接" style="display: inline-block;"">
<span class="g-button-right"><em class="icon icon-disk" title="秒传链接提取"></em><span class="text" style="width: auto;">秒传链接</span></span></a>`;
const html_btn_gen = `<a class="g-button gen-bdlink-button"><span class="g-button-right"><em class="icon icon-share" title="生成秒传"></em><span class="text">生成秒传</span></span></a>`;
const html_check_md5 = `<p ${myStyle}>测试秒传, 可防止秒传失效<a class="g-button g-button-blue" id="check_md5_btn" ${myBtnStyle}><span class="g-button-right" ${myBtnStyle}><span class="text" style="width: auto;">测试</span></span></a></p>`;
const html_document = `<p ${myStyle}>分享过程中遇到问题可参考<a class="g-button g-button-blue" ${myBtnStyle} href="https://shimo.im/docs/TZ1JJuEjOM0wnFDH" rel="noopener noreferrer" target="_blank"><span class="g-button-right" ${myBtnStyle}><span class="text" style="width: auto;">防爆教程</span></span></a></p>`;
const html_donate = `<p id="bdcode_donate" ${myStyle}>若喜欢该脚本, 可前往 <a href="https://afdian.net/@mengzonefire" rel="noopener noreferrer" target="_blank">赞助页</a> 支持作者
<a class="g-button" id="kill_donate" ${myBtnStyle}><span class="g-button-right" ${myBtnStyle}><span class="text" style="width: auto;">不再显示</span></span></a></p>`;
const html_feedback = `<p id="bdcode_feedback" ${myStyle}>若有任何疑问, 可前往 <a href="https://greasyfork.org/zh-CN/scripts/397324" rel="noopener noreferrer" target="_blank">脚本页</a> 反馈
<a class="g-button" id="kill_feedback" ${myBtnStyle}><span class="g-button-right" ${myBtnStyle}><span class="text" style="width: auto;">不再显示</span></span></a></p>`;
const csd_hint_html = '<p>弹出跨域访问窗口时,请选择"总是允许"或"总是允许全部域名"</p><img style="max-width: 100%; height: auto" src="https://pic.rmb.bdstatic.com/bjh/763ff5014cca49237cb3ede92b5b7ac5.png">';
var checkbox_par = {
input: 'checkbox',
inputValue: GM_getValue('with_path'),
inputPlaceholder: '导出文件夹目录结构',
};
var show_prog = function (r) {
gen_prog.textContent = `${parseInt((r.loaded/r.total)*100)}%`;
};
if (Base64.extendString) {
Base64.extendString();
}
function add_file_list(file_list) {
var dir_list = [];
file_list.forEach(function (item) {
if (item.isdir) {
dir_list.push(item.path);
} else {
file_info_list.push({
'path': item.path,
'size': item.size,
});
}
});
if (dir_list.length) {
Swal.fire({
type: 'info',
title: '选择中包含文件夹, 是否递归生成?',
text: '若选是, 将同时生成各级子文件夹下的文件',
allowOutsideClick: false,
focusCancel: true,
showCancelButton: true,
reverseButtons: true,
showCloseButton: true,
confirmButtonText: '是',
cancelButtonText: '否',
}).then((result) => {
if (result.value) {
recursive = true;
} else if (
result.dismiss === Swal.DismissReason.cancel
) {
recursive = false;
} else {
return;
}
add_dir_list(dir_list);
});
} else {
Gen_bdlink();
}
}
function add_dir_list(dir_list, dir_id = 0) {
if (dir_id >= dir_list.length) {
Gen_bdlink();
return;
}
var path = dir_list[dir_id];
var list_dir_par = {
url: api_url + `&path=${encodeURIComponent(path)}&recursion=${recursive ? 1 : 0}`,
type: 'GET',
responseType: 'json',
onload: function (r) {
if (parseInt(r.status / 100) === 2) {
if (!r.response.errno) {
r.response.list.forEach(function (item) {
item.isdir || file_info_list.push({
'path': item.path,
'size': item.size,
});
});
} else {
file_info_list.push({
'path': path,
'errno': 810
});
}
} else {
file_info_list.push({
'path': path,
'errno': r.status
});
}
add_dir_list(dir_list, dir_id + 1);
},
onerror: function (r) {
file_info_list.push({
'path': path,
'errno': 514
});
add_dir_list(dir_list, dir_id + 1);
}
};
GM_xmlhttpRequest(list_dir_par);
}
function initButtonEvent() {
$(document).on('click', '.gen-bdlink-button', function () {
if (!GM_getValue('gen_no_first')) {
Swal.fire({
title: '首次使用请注意',
showCloseButton: true,
allowOutsideClick: false,
html: csd_hint_html,
}).then((result) => {
if (result.value) {
GM_setValue('gen_no_first', true);
select_list = getSelectedFileList();
add_file_list(select_list);
}
});
return;
}
if (GM_getValue('unfinish')) {
Swal.fire({
title: '检测到未完成的秒传任务',
text: '是否继续进行?',
showCancelButton: true,
allowOutsideClick: false,
confirmButtonText: '确定',
cancelButtonText: '取消',
}).then((result) => {
if (result.value) {
var unfinish_info = GM_getValue('unfinish');
file_info_list = unfinish_info.file_info_list;
Gen_bdlink(unfinish_info.file_id);
} else {
GM_deleteValue('unfinish');
select_list = getSelectedFileList();
add_file_list(select_list);
}
});
} else {
select_list = getSelectedFileList();
add_file_list(select_list);
}
});
}
function getSelectedFileList() {
return unsafeWindow.require('system-core:context/context.js').instanceForSystem.list.getSelected();
};
function initButtonHome() {
let loop = setInterval(() => {
var html_tag = $('div.tcuLAu');
if (!html_tag.length) return false;
if (!$('#h5Input0').length) return false;
html_tag.append(html_btn);
let loop2 = setInterval(() => {
var btn_tag = $('#bdlink_btn');
if (!btn_tag.length) return false;
btn_tag.click(function () {
GetInfo();
});
clearInterval(loop2);
}, 50);
clearInterval(loop);
}, 50);
}
function initButtonGen() {
var listTools = getSystemContext().Broker.getButtonBroker('listTools');
if (listTools && listTools.$box) {
$(listTools.$box).children('div').after(html_btn_gen);
initButtonEvent();
} else {
setTimeout(initButtonGen, 500);
}
};
function getSystemContext() {
return unsafeWindow.require('system-core:context/context.js').instanceForSystem;
};
function Gen_bdlink(file_id = 0) {
if (file_info_list.length > 10 && vip_type === 2 && !interval_mode) {
Set_interval(file_id);
return;
}
Swal.fire({
title: '秒传生成中',
showCloseButton: true,
allowOutsideClick: false,
html: '<p>正在生成第 <gen_num></gen_num> 个</p><p><gen_prog></gen_prog></p>',
onBeforeOpen: () => {
Swal.showLoading()
var content = Swal.getContent();
if (content) {
gen_num = content.querySelector('gen_num');
gen_prog = content.querySelector('gen_prog');
myGenerater(file_id);
}
}
}).then((result) => {
if (result.dismiss && xmlhttpRequest) {
xmlhttpRequest.abort();
GM_deleteValue('unfinish');
interval_mode = false;
file_info_list = [];
}
});
}
function Set_interval(file_id) {
var test_par = /\d+/;
interval = GM_getValue('interval') || 15;
Swal.fire({
title: '批量生成注意',
text: '检测到超会账号且生成的文件较多, 会因为生成过快导致接口被限制(#403), 请输入生成间隔(1-30秒,推荐15)防止上述情况',
input: 'text',
inputValue: interval,
showCancelButton: false,
allowOutsideClick: false,
confirmButtonText: '确定',
inputValidator: (value) => {
if (!value) {
return '不能为空';
}
if (!test_par.test(value)) {
return '输入格式不正确, 请输入数字';
}
if (Number(value) > 30 || Number(value) < 1) {
return '输入应在1-30之间';
}
}
}).then((result) => {
interval = Number(result.value);
GM_setValue('interval', interval);
interval_mode = true;
Gen_bdlink(file_id);
});
}
var show_prog = function (r) {
gen_prog.textContent = `${parseInt((r.loaded / r.total) * 100)}%`;
};
function test_bdlink() {
if (!GM_getValue('show_test_warning')) {
Swal.fire({
title: '注意',
text: '测试秒传会转存并覆盖文件,若在生成期间修改过同名文件,为避免修改的文件丢失,请不要使用此功能!',
input: 'checkbox',
inputPlaceholder: '不再显示',
showCancelButton: true,
allowOutsideClick: false,
confirmButtonText: '确定',
cancelButtonText: '返回'
}).then((result) => {
GM_setValue('show_test_warning', result.value)
if (!result.dismiss) {
codeInfo = gen_success_list;
check_mode = true;
Process();
} else {
gen_success_list = [];
myGenerater(file_info_list.length);
}
});
} else {
codeInfo = gen_success_list;
check_mode = true;
Process();
}
}
function myGenerater(file_id, appid_id = 0, failed = false) {
GM_setValue('unfinish', {
'file_info_list': file_info_list,
'file_id': file_id
});
if (file_id >= file_info_list.length) {
bdcode = '';
var failed_info = '';
var gen_failed = 0;
file_info_list.forEach(function (item) {
if (item.hasOwnProperty('errno')) {
gen_failed++;
failed_info += `<p>文件:${item.path}</p><p>失败原因:${checkErrno(item.errno, item.size)}(#${item.errno})</p>`
} else {
gen_success_list.push(item);
bdcode += `${item.md5}#${item.md5s}#${item.size}#${item.path}\n`;
}
});
bdcode = bdcode.trim();
if (failed_info) {
failed_info = '<p>失败文件列表:</p>' + failed_info;
}
Swal.fire({
title: `生成完毕 共${file_info_list.length}个, 失败${gen_failed}个!`,
confirmButtonText: '复制秒传代码',
cancelButtonText: '取消',
showCloseButton: true,
showCancelButton: !bdcode,
showConfirmButton: bdcode,
allowOutsideClick: false,
html: bdcode ? (html_check_md5 + html_document + (failed_info && ('<p><br></p>' + failed_info))) : html_document + '<p><br></p>' + failed_info,
...(bdcode && checkbox_par),
onBeforeOpen: () => {
let loop = setInterval(() => {
var html_tag = $('#check_md5_btn');
if (!html_tag.length) return false;
$('#check_md5_btn').click(function () {
test_bdlink();
});
clearInterval(loop);
}, 50);
Add_content(document.createElement('div'));
}
}).then((result) => {
if (!result.dismiss) {
if (!result.value) {
bdcode = bdcode.replace(/(\/.+\/)|(\/)/g, '');
}
checkbox_par.inputValue = result.value;
GM_setValue('with_path', result.value);
GM_setClipboard(bdcode);
}
file_info_list = [];
gen_success_list = [];
GM_deleteValue('unfinish');
interval_mode = false;
});
return;
}
var file_info = file_info_list[file_id];
if (file_info.hasOwnProperty('errno')) {
myGenerater(file_id + 1);
return;
}
if (file_info.size > 21474836480) {
file_info.errno = 3939;
myGenerater(file_id + 1);
return;
}
var path = file_info.path;
gen_num.textContent = (file_id + 1).toString() + ' / ' + file_info_list.length.toString();
gen_prog.textContent = '0%';
var dl_size = file_info.size < 262144 ? file_info.size - 1 : 262143;
if (!failed) {
appid_id = file_info.size < 50000000 ? 0 : 3;
}
var get_dl_par = {
url: pcs_url + `?app_id=${appid_list[appid_id]}&method=download&path=${encodeURIComponent(path)}`,
type: 'GET',
headers: {
'Range': `bytes=0-${dl_size}`
},
responseType: 'arraybuffer',
onprogress: show_prog,
ontimeout: function (r) {
myGenerater(file_id);
console.log('timeout !!!');
},
onerror: function (r) {
file_info.errno = 514;
myGenerater(file_id + 1);
},
onload: function (r) {
if (parseInt(r.status / 100) === 2) {
var responseHeaders = r.responseHeaders;
var file_md5 = responseHeaders.match(/content-md5: ([\da-f]{32})/i);
if (file_md5) {
file_md5 = file_md5[1].toLowerCase();
} else {
try_get_md5(file_id, r.response);
return;
}
//bad_md5内的三个md5是和谐文件返回的, 第一个是txt格式的"温馨提示.txt", 第二个是视频格式的(俗称5s),第三个为新发现的8s视频文件
if (bad_md5.indexOf(file_md5) !== -1 || r.finalUrl.indexOf('issuecdn.baidupcs.com') !== -1) {
file_info.errno = 1919;
} else {
var spark = new SparkMD5.ArrayBuffer();
spark.append(r.response);
var slice_md5 = spark.end();
file_info.md5 = file_md5;
file_info.md5s = slice_md5;
}
gen_prog.textContent = '100%';
setTimeout(function () {
myGenerater(file_id + 1);
}, interval_mode ? interval * 1000 : 1000);
} else {
console.log(`return #403, appid: ${appid_list[appid_id]}`);
if (r.status == 403 && appid_id < (appid_list.length - 1)) {
myGenerater(file_id, appid_id + 1, true);
} else {
file_info.errno = r.status;
myGenerater(file_id + 1);
}
}
}
};
xmlhttpRequest = GM_xmlhttpRequest(get_dl_par);
}
function try_get_md5(file_id, file_date) {
var file_info = file_info_list[file_id];
var get_dl_par = {
url: meta_url + encodeURIComponent(file_info.path),
type: 'GET',
onload: function (r) {
var file_md5 = r.responseText.match(/"block_list":\["([\da-f]{32})"\]/i) || r.responseText.match(/md5":"([\da-f]{32})"/i)
if (file_md5) {
file_info.md5 = file_md5[1].toLowerCase();
var spark = new SparkMD5.ArrayBuffer();
spark.append(file_date);
file_info.md5s = spark.end();
} else {
file_info.errno = 996;
}
myGenerater(file_id + 1);
}
}
GM_xmlhttpRequest(get_dl_par);
}
/**
* 一个简单的类似于 NodeJS Buffer 的实现.
* 用于解析游侠度娘提取码。
* @param {SimpleBuffer}
*/
function SimpleBuffer(str) {
this.fromString(str);
}
SimpleBuffer.toStdHex = function toStdHex(n) {
return ('0' + n.toString(16)).slice(-2);
};
SimpleBuffer.prototype.fromString = function fromString(str) {
var len = str.length;
this.buf = new Uint8Array(len);
for (var i = 0; i < len; i++) {
this.buf[i] = str.charCodeAt(i);
}
};
SimpleBuffer.prototype.readUnicode = function readUnicode(index, size) {
if (size & 1) {
size++;
}
var bufText = Array.prototype.slice.call(this.buf, index, index + size).map(SimpleBuffer.toStdHex);
var buf = [''];
for (var i = 0; i < size; i += 2) {
buf.push(bufText[i + 1] + bufText[i]);
}
return JSON.parse('"' + buf.join('\\u') + '"');
};
SimpleBuffer.prototype.readNumber = function readNumber(index, size) {
var ret = 0;
for (var i = index + size; i > index;) {
ret = this.buf[--i] + (ret * 256);
}
return ret;
};
SimpleBuffer.prototype.readUInt = function readUInt(index) {
return this.readNumber(index, 4);
};
SimpleBuffer.prototype.readULong = function readULong(index) {
return this.readNumber(index, 8);
};
SimpleBuffer.prototype.readHex = function readHex(index, size) {
return Array.prototype.slice.call(this.buf, index, index + size).map(SimpleBuffer.toStdHex).join('');
};
function DuParser() {}
DuParser.parse = function generalDuCodeParse(szUrl) {
var r;
if (szUrl.indexOf('bdpan') === 0) {
r = DuParser.parseDu_v1(szUrl);
r.ver = 'PanDL';
} else if (szUrl.indexOf('BDLINK') === 0) {
r = DuParser.parseDu_v2(szUrl);
r.ver = '游侠 v1';
} else if (szUrl.indexOf('BaiduPCS-Go') === 0) {
r = DuParser.parseDu_v3(szUrl);
r.ver = 'PCS-Go';
} else {
r = DuParser.parseDu_v4(szUrl);
r.ver = '梦姬标准';
}
return r;
};
DuParser.parseDu_v1 = function parseDu_v1(szUrl) {
return szUrl.replace(/\s*bdpan:\/\//g, ' ').trim().split(' ').map(function (z) {
return z.trim().fromBase64().match(/([\s\S]+)\|([\d]{1,20})\|([\dA-Fa-f]{32})\|([\dA-Fa-f]{32})/);
}).filter(function (z) {
return z;
}).map(function (info) {
return {
md5: info[3].toLowerCase(),
md5s: info[4].toLowerCase(),
size: info[2],
path: info[1]
};
});
};
DuParser.parseDu_v2 = function parseDu_v2(szUrl) {
var raw = atob(szUrl.slice(6).replace(/\s/g, ''));
if (raw.slice(0, 5) !== 'BDFS\x00') {
return null;
}
var buf = new SimpleBuffer(raw);
var ptr = 9;
var arrFiles = [];
var fileInfo, nameSize;
var total = buf.readUInt(5);
var i;
for (i = 0; i < total; i++) {
// 大小 (8 bytes)
// MD5 + MD5S (0x20)
// nameSize (4 bytes)
// Name (unicode)
fileInfo = {};
fileInfo.size = buf.readULong(ptr + 0);
fileInfo.md5 = buf.readHex(ptr + 8, 0x10);
fileInfo.md5s = buf.readHex(ptr + 0x18, 0x10);
nameSize = buf.readUInt(ptr + 0x28) << 1;
fileInfo.nameSize = nameSize;
ptr += 0x2C;
fileInfo.path = buf.readUnicode(ptr, nameSize);
arrFiles.push(fileInfo);
ptr += nameSize;
}
return arrFiles;
};
DuParser.parseDu_v3 = function parseDu_v3(szUrl) {
return szUrl.split('\n').map(function (z) {
// unsigned long long: 0~18446744073709551615
return z.trim().match(/-length=([\d]{1,20}) -md5=([\dA-Fa-f]{32}) -slicemd5=([\dA-Fa-f]{32})[\s\S]+"([\s\S]+)"/)
}).filter(function (z) {
return z;
}).map(function (info) {
return {
md5: info[2],
md5s: info[3],
size: info[1],
path: info[4]
};
});
};
DuParser.parseDu_v4 = function parseDu_v4(szUrl) {
return szUrl.split('\n').map(function (z) {
// unsigned long long: 0~18446744073709551615
return z.trim().match(/([\dA-Fa-f]{32})#([\dA-Fa-f]{32})#([\d]{1,20})#([\s\S]+)/);
}).filter(function (z) {
return z;
}).map(function (info) {
return {
md5: info[1].toLowerCase(),
md5s: info[2].toLowerCase(),
size: info[3],
path: info[4]
};
});
};
function saveFile(i, try_flag) {
if (i >= codeInfo.length) {
Swal.fire({
title: `${check_mode ? '测试' : '转存'}完毕 共${codeInfo.length}个 失败${failed}个!`,
confirmButtonText: check_mode ? '复制秒传代码' : '确定',
showCloseButton: true,
...(check_mode && checkbox_par),
onBeforeOpen: () => {
var content = Swal.getContent();
codeInfo.forEach(function (item) {
if (item.hasOwnProperty('errno')) {
var file_name = item.path;
if (item.errno === 2 && item.size > 21474836480) {
item.errno = 3939;
}
var errText = checkErrno(item.errno, item.size);
var str1 = `文件:${file_name}`;
var str2 = `失败原因:${errText}(#${item.errno})`;
var ele1 = document.createElement('p');
var ele2 = document.createElement('p');
var text1 = document.createTextNode(str1);
var text2 = document.createTextNode(str2);
ele1.appendChild(text1);
ele2.appendChild(text2);
content.appendChild(ele1);
content.appendChild(ele2);
}
});
Add_content(document.createElement('div'));
var _dir = (dir || '').replace(/\/$/, '');
if (_dir) {
if (_dir.charAt(0) !== '/') {
_dir = '/' + _dir;
}
const cBtn = Swal.getConfirmButton();
const btn = cBtn.cloneNode();
btn.textContent = '打开目录';
btn.style.backgroundColor = '#ecae3c';
btn.onclick = () => {
location.href = `${location.origin}/disk/home?#/all?vmode=list&path=${encodeURIComponent(_dir)}`;
Swal.close();
}
cBtn.before(btn);
}
}
}).then((result) => {
if (check_mode) {
if (!result.dismiss) {
if (!result.value) {
bdcode = bdcode.replace(/\/.+\//g, '');
}
checkbox_par.inputValue = result.value;
GM_setValue('with_path', result.value);
GM_setClipboard(bdcode);
}
file_info_list = [];
gen_success_list = [];
GM_deleteValue('unfinish');
interval_mode = false;
check_mode = false;
}
require('system-core:system/baseService/message/message.js').trigger('system-refresh');
});
failed = 0;
return;
}
var first_404 = false;
var file = codeInfo[i];
file_num.textContent = (i + 1).toString() + ' / ' + codeInfo.length.toString();
$.ajax({
url: `/api/rapidupload${check_mode ? '?rtype=3' : ''}`,
type: 'POST',
data: {
path: dir + file.path,
'content-md5': try_flag ? file.md5.toUpperCase() : file.md5,
'slice-md5': try_flag ? file.md5s.toUpperCase() : file.md5s,
'content-length': file.size
}
}).success(function (r) {
if (r && r.errno) {
if (try_flag && r.errno === 404) {
codeInfo[i].errno = 404;
failed++;
} else if (r.errno !== 404) {
if (file.path.match(/["\\\:*?<>|]/)) {
codeInfo[i].errno = 2333;
} else {
codeInfo[i].errno = r.errno;
}
failed++;
} else {
first_404 = true;
}
}
}).fail(function (r) {
codeInfo[i].errno = 114;
failed++;
}).always(function () {
if (!try_flag && first_404) {
// try UpperCase md5
saveFile(i, true)
} else {
saveFile(i + 1, false);
}
});
}
function checkErrno(errno, file_size = 0) {
switch (errno) {
case -7:
return '保存路径存在非法字符';
case -8:
return '文件已存在';
case 400:
return '请求错误(请尝试使用最新版Chrome浏览器)';
case 403:
return '文件获取失败(生成过于频繁导致接口被限,请稍后再试)';
case 404:
return '文件不存在(秒传无效)';
case 2:
return '转存失败(尝试重新登录网盘账号)';
case 3939:
return `秒传不支持大于20G的文件,文件大小:${(file_size / (1024 ** 3)).toFixed(2)}G`;
//文件大于20G时访问秒传接口实际会返回#2
case 2333:
return '链接内的文件路径错误(不能含有以下字符"\\:*?<>|)';
//文件路径错误时接口实际也是返回#2
case -10:
return '网盘容量已满';
case 114:
return '接口调用失败(请重试)';
case 514:
return '接口调用失败(请重试/弹出跨域访问窗口时,请选择"总是允许"或"总是允许全部域名")';
case 1919:
return '文件已被和谐';
case 810:
return '文件列表获取失败(请重试)';
case 996:
return 'md5获取失败(请等待一段时间再重试)';
default:
return '未知错误';
}
}
function GetInfo(str = '') {
Swal.fire({
title: '请输入提取码',
input: 'textarea',
inputValue: str,
showCancelButton: true,
inputPlaceholder: '[支持 PanDL/梦姬标准/游侠/PCS-Go][支持批量]\n[输入setting进入设置页]',
confirmButtonText: '确定',
cancelButtonText: '取消',
inputValidator: (value) => {
if (!value) {
return '链接不能为空';
}
if (value === 'setting') {
return;
}
codeInfo = DuParser.parse(value);
if (!codeInfo.length) {
return '未识别到正确的链接';
}
}
}).then((result) => {
if (!result.dismiss) {
if (result.value === 'setting') {
setting();
} else {
Process();
}
}
});
}
function Process() {
if (check_mode) {
dir = '';
save_alert();
} else {
dir = GM_getValue('last_dir');
if (!dir) {
dir = '';
}
Swal.fire({
title: '请输入保存路径',
input: 'text',
inputPlaceholder: '格式示例:/GTA5/, 默认保存在根目录',
inputValue: dir,
showCancelButton: true,
confirmButtonText: '确定',
cancelButtonText: '取消',
inputValidator: (value) => {
if (value.match(/["\\\:*?<>|]/)) {
return '路径中不能含有以下字符"\\:*?<>|, 格式示例:/GTA5/';
}
}
}).then((result) => {
if (!result.dismiss) {
dir = result.value;
GM_setValue('last_dir', dir);
if (dir.charAt(dir.length - 1) !== '/') {
dir = dir + '/';
}
save_alert();
}
});
}
}
function save_alert() {
Swal.fire({
title: `文件${check_mode ? '测试' : '提取'}中`,
html: `正在${check_mode ? '测试' : '转存'}第 <file_num></file_num> 个`,
allowOutsideClick: false,
onBeforeOpen: () => {
Swal.showLoading()
var content = Swal.getContent();
if (content) {
file_num = content.querySelector('file_num');
saveFile(0, false);
}
}
});
}
function GetInfo_url() {
let bdlink = location.href.match(/[\?#]bdlink=([\da-zA-Z/\+]+)&?/);
if (bdlink) {
bdlink = bdlink[1].fromBase64();
}
return bdlink;
}
function Add_content(content) {
var hasAdd = false;
if (!GM_getValue('kill_feedback')) {
hasAdd = true;
content.innerHTML += `<p><br></p>`;
content.innerHTML += html_feedback;
let loop = setInterval(() => {
var html_tag = $('#kill_feedback');
if (!html_tag.length) return false;
$('#kill_feedback').click(function () {
GM_setValue('kill_feedback', true);
$('#bdcode_feedback').remove();
});
clearInterval(loop);
}, 50);
}
if (!GM_getValue('kill_donate')) {
if (!hasAdd) {
content.innerHTML += `<p><br></p>`;
}
content.innerHTML += html_donate;
let loop = setInterval(() => {
var html_tag = $('#kill_donate');
if (!html_tag.length) return false;
$('#kill_donate').click(function () {
GM_setValue('kill_donate', true);
$('#bdcode_donate').remove();
});
clearInterval(loop);
}, 50);
}
Swal.getContent().appendChild(content);
}
function checkVipType() {
var info_par = {
url: info_url,
type: 'GET',
responseType: 'json',
onload: function (r) {
if (r.response.hasOwnProperty('vip_type')) {
vip_type = r.response.vip_type;
}
}
};
GM_xmlhttpRequest(info_par);
}
const injectStyle = () => {
let style = GM_getResourceText('sweetalert2Css');
// 暴力猴直接粘贴脚本代码时可能不会将resource中的数据下载缓存,fallback到下载css代码
let themes = GM_getValue('Themes') || 'Minimal';
console.log(themes);
let css_code = GM_getValue(themes);
if (css_code) {
GM_addStyle(css_code);
return;
}
if (style && themes === 'Minimal') {
GM_setValue(themes, style);
GM_addStyle(style);
return;
}
GM_xmlhttpRequest({
url: css_url[themes],
type: 'GET',
responseType: 'text',
onload: function (r) {
style = r.response;
GM_setValue(themes, style);
GM_addStyle(style);
},
onerror: function (r) {
alert('秒传链接提取:\n外部资源加载失败, 脚本无法运行, 请检查网络或尝试更换DNS');
}
})
};
const showUpdateInfo = () => {
if (!GM_getValue('1.5.4_no_first')) {
Swal.fire({
title: `秒传链接提取 1.5.4 更新内容(21.2.11):`,
html: update_info,
heightAuto: false,
scrollbarPadding: false,
showCloseButton: true,
allowOutsideClick: false,
confirmButtonText: '确定'
}).then((result) => {
GM_setValue('1.5.4_no_first', true);
});
}
};
function myInit() {
injectStyle();
const bdlink = GetInfo_url();
window.addEventListener('DOMContentLoaded', () => {
bdlink ? GetInfo(bdlink) : showUpdateInfo();
initButtonHome();
initButtonGen();
checkVipType();
});
}
function setting() {
Swal.fire({
title: '秒传链接提取 设置页',
showCloseButton: true,
showCancelButton: true,
confirmButtonText: '确定',
cancelButtonText: '取消',
allowOutsideClick: false,
input: 'select',
inputValue: GM_getValue('Themes') || 'Minimal',
inputOptions: {
'Minimal': 'Minimal 白色主题(默认)',
'Bulma': 'Bulma 白色简约',
'Bootstrap 4': 'Bootstrap4 白色简约',
'Material UI': 'MaterialUI 白色主题',
'Dark': 'Dark 黑色主题',
'WordPress Admin': 'WordPressAdmin 灰色主题'
}
}).then((result) => {
if (!result.dismiss) {
GM_setValue('Themes', result.value);
Swal.fire({
title: '设置成功 刷新页面生效',
showCloseButton: true,
allowOutsideClick: false,
html: csd_hint_html
});
}
});
}
const update_info =
`<div class="panel-body" style="height: 250px; overflow-y:scroll">