forked from MoeClub/Note
-
Notifications
You must be signed in to change notification settings - Fork 0
/
115.user.js
2641 lines (2259 loc) · 103 KB
/
115.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 115转存助手ui优化版
// @name:zh 115转存助手ui优化版
// @description 2021.12.20更新,115转存助手ui优化版 v3.2.1 (143.2021.1220.1)(based on Fake115Upload 1.4.3 @T3rry)
// @author Never4Ever
// @namespace Fake115Upload@Never4Ever
// @version 143.2021.1220.1
// @match https://115.com/*
// @grant GM_xmlhttpRequest
// @grant GM_log
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_setClipboard
// @grant unsafeWindow
// @grant GM_registerMenuCommand
// @grant GM_addStyle
// @connect proapi.115.com
// @connect webapi.115.com
// @connect 115.com
// @require https://greasyfork.org/scripts/398240-gm-config-zh-cn/code/GM_config_zh-CN.js
// @require https://cdn.bootcss.com/jsSHA/2.3.1/sha1.js
// @require https://unpkg.zhimg.com/underscore@1.12.0/underscore-min.js
// @require https://unpkg.zhimg.com/sweetalert2@11.3.0
// @require https://unpkg.zhimg.com/node-forge@0.10.0/dist/forge.min.js
// @require https://unpkg.zhimg.com/emoutils@2.0.0/dist/umd/emoutils.min.js
// ==/UserScript==
/*********************************************
请从以下获取最新版,或者遇到问题去此反馈,感谢
https://gist.github.com/Nerver4Ever/953447c9ecd330ffc0861d4cbb839369
**********************************************/
(function () {
'use strict';
const TIPS = {
CurrentVersion: "143.2021.1220.1",
LastUpdateDate: "2021.12.20",
VersionTips: "115转存助手ui优化版 V3.2.1",
UpdateUrl: "https://gist.github.com/Nerver4Ever/953447c9ecd330ffc0861d4cbb839369",
Sha1FileInputDetails: "",
};
const WORKSETTINGS = {
WorkingItemsNumber: 4, //同时执行任务数
SleepLittleTime: 500, //短暂休眠,毫秒,暂时在转存中使用
SleepMoreTime: 1000, //长时休眠,毫秒,暂时在提取中使用
SleepMuchMoreTime: 8000, //超长休眠,暂时未使用
ANumber: 27, //随机数,暂时未使用
};
GM_addStyle(`
.my115Info{
color:red
}
.btnInGrid{
height:20px;
width:20px;
margin-left:-22px;
margin-top:36px;
border:0px;
border-color:transparent;
background-color:transparent;
}
.btnInGrid i{
margin:3px -3px
}
li:hover .btnInGrid{
background-color:#2777F8 !important
}
/* Style The Dropdown Button */
.my115Dropbtn {
background-color: #2777F8;
color: white;
font-size: 16px;
border: none;
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.my115Dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.my115Dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 230px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
margin-top: 32px;
}
/* Links inside the dropdown */
.my115Dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
cursor: pointer;
margin:4px;
}
/* Change color of dropdown links on hover */
.my115Dropdown-content a:hover{
background-color: #2777F8;
color:white;
}
/* Show the dropdown menu on hover */
.my115Dropdown:hover .my115Dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.my115Dropdown:hover .my115Dropbtn {
background-color: #3e8e41;
}
`);
function config() {
var windowCss = '#Cfg4ne .nav-tabs {margin: 20 2} #Cfg4ne .config_var textarea{width: 310px; height: 50px;} #Cfg4ne .inline {padding-bottom:0px;} #Cfg4ne .config_header a:hover {color:#1e90ff;} #Cfg4ne .config_var {margin-left: 6%;margin-right: 6%;} #Cfg4ne input[type="checkbox"] {margin: 3px 3px 3px 0px;} #Cfg4ne input[type="text"] {width: 60px;} #Cfg4ne {background-color: lightgray;} #Cfg4ne .reset_holder {float: left; position: relative; bottom: -1em;} #Cfg4ne .saveclose_buttons {margin: .7em;} #Cfg4ne .section_desc {font-size: 10pt;}';
GM_registerMenuCommand('设置', opencfg);
function opencfg() {
GM_config.open();
};
GM_config.init({
id: 'Cfg4ne',
title: GM_config.create('a', {
href: TIPS.UpdateUrl,
target: '_blank',
className: 'setTitle',
textContent: `${TIPS.VersionTips}设置`,
title: `作者:Never4Ever 版本:${TIPS.CurrentVersion}点击访问主页`
}),
isTabs: true,
skin: 'tab',
css: windowCss,
frameStyle: {
height: '420px',
width: '570px',
zIndex: '2147483648',
},
fields: {
createRootFolderDefaultValue: {
section: ['', '转存助手一些功能设置,发包参数暂未开放,敬请期待!'],
label: '“sha1转存时,强制在保存处新建根目录”这项默认选中',
labelPos: 'right',
type: 'checkbox',
default: true,
},
createChildFolderVisible: {
label: '显示“sha1转存时,不创建任何子目录”选项;不显示则强制创建子目录',
labelPos: 'right',
type: 'checkbox',
default: false,
},
advancedRename: {
label: '在目录的悬浮工具条处显示“去除分隔符”选项',
labelPos: 'right',
type: 'checkbox',
default: false,
},
autoUseSeparator: {
label: '自动给文件名添加分隔符进行上传,以防文件名违规',
labelPos: 'right',
type: 'checkbox',
default: true,
},
autoUseSeparatorToRename: {
label: '上传结束,自动给文件名去除分隔符,还原原文件名',
labelPos: 'right',
type: 'checkbox',
default: true,
},
separator: {
label: '分隔符方案(推荐非常用汉字;如果分隔符失效,请自行修改):',
type: 'text',
default: '變'
},
uploadNumber: {
//section: ['时间参数设置', '注意:参数设置过快,会引起115服务器无响应,为稳定运行参数未启用!'],
//label: '转存同时工作任务数:',
labelPos: 'left',
type: 'hidden',
default: '4',
},
uploadSleepTime: {
//label: '转存间隔时间(毫秒):',
labelPos: 'left',
type: 'hidden',
default: '500',
},
downloadNumber: {
//label: '提取同时工作任务数:',
labelPos: 'left',
type: 'hidden',
default: '4',
},
downloadSleepTime: {
//label: '提取间隔时间(毫秒):',
labelPos: 'left',
type: 'hidden',
default: '1300',
},
createFolderSleepTime: {
//label: '目录创建间隔时间(毫秒):',
labelPos: 'left',
type: 'hidden',
default: '300',
},
checkUpdate: {
//section: ['帮助&更新&反馈', '常见错误以及对本脚本进行更新检查与bug反馈'],
label: '前往github主页',
labelPos: 'right',
type: 'button',
click: function () {
window.open(TIPS.UpdateUrl, "_blank");
}
},
},
events: {
save: function () {
GM_config.close();
location.reload();
}
},
});
};
config();
var currentConfig = {
createRootFolderDefaultValue: 'createRootFolderDefaultValue',
createChildFolderVisible: 'createChildFolderVisible',
advancedRename: 'advancedRename',
autoUseSeparator: 'autoUseSeparator',
autoUseSeparatorToRename: 'autoUseSeparatorToRename',
separator: 'separator',
uploadNumber: 'uploadNumber',
uploadSleepTime: 'uploadSleepTime',
downloadNumber: 'downloadNumber',
downloadSleepTime: 'downloadSleepTime',
createFolderSleepTime: 'createFolderSleepTime',
}
var offlineTaskButton = `
<div class="my115Dropdown" id="my115Dropdown">
<div class="my115Dropbtn">
<a href="javascript:;" class="button btn-line btn-upload" menu="offline_task"><i class="icon-operate ifo-linktask"></i><span>链接与sha1转存任务</span><em style="display:none;" class="num-dot"></em></a>
</div>
<div class="my115Dropdown-content" style="display:none;">
<a id="my115ContinuedDownload"> 继续【提取】或者【转存】</a>
</div>
</div>
`;
console.log($("#my115Dropdown").length);
if (!$("#my115Dropdown").length > 0) {
$(".left-tvf").eq(0).append(offlineTaskButton);
$("#my115ContinuedDownload").click(e => {
postSha1Messgae(createMessage(MessageType.BEGIN4CONTINUETASK, ""));
});
}
window.cookie = document.cookie
//todo:waitForKeyElements
waitForKeyElements("div.file-opr", AddShareSHA1Btn);
waitForKeyElements("div.dialog-bottom", AddDownloadSha1Btn);
waitForKeyElements("div.lstc-search", AddShareButtonForSearchItem);
waitForKeyElements(`#js_cantain_box .list-thumb li[rel="item"]`, AddCeateSha1ButtonInGrid)
waitForKeyElements('div#js_top_header_file_path_box', CreateSha1ButtonForSelectedItems);
//隐藏截图中的uid
waitForKeyElements('div[class^="fp-"]', HandleUidDiv);
function HandleUidDiv(node){
node.hide();
console.log("set uiddiv");
}
//#region 20201230新的提取api相关
var pub_key = '-----BEGIN PUBLIC KEY-----\
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDR3rWmeYnRClwLBB0Rq0dlm8Mr\
PmWpL5I23SzCFAoNpJX6Dn74dfb6y02YH15eO6XmeBHdc7ekEFJUIi+swganTokR\
IVRRr/z16/3oh7ya22dcAqg191y+d6YDr4IGg/Q5587UKJMj35yQVXaeFXmLlFPo\
kFiz4uPxhrB7BGqZbQIDAQAB\
-----END PUBLIC KEY-----'
var private_key = '-----BEGIN RSA PRIVATE KEY-----\
MIICXAIBAAKBgQCMgUJLwWb0kYdW6feyLvqgNHmwgeYYlocst8UckQ1+waTOKHFC\
TVyRSb1eCKJZWaGa08mB5lEu/asruNo/HjFcKUvRF6n7nYzo5jO0li4IfGKdxso6\
FJIUtAke8rA2PLOubH7nAjd/BV7TzZP2w0IlanZVS76n8gNDe75l8tonQQIDAQAB\
AoGANwTasA2Awl5GT/t4WhbZX2iNClgjgRdYwWMI1aHbVfqADZZ6m0rt55qng63/\
3NsjVByAuNQ2kB8XKxzMoZCyJNvnd78YuW3Zowqs6HgDUHk6T5CmRad0fvaVYi6t\
viOkxtiPIuh4QrQ7NUhsLRtbH6d9s1KLCRDKhO23pGr9vtECQQDpjKYssF+kq9iy\
A9WvXRjbY9+ca27YfarD9WVzWS2rFg8MsCbvCo9ebXcmju44QhCghQFIVXuebQ7Q\
pydvqF0lAkEAmgLnib1XonYOxjVJM2jqy5zEGe6vzg8aSwKCYec14iiJKmEYcP4z\
DSRms43hnQsp8M2ynjnsYCjyiegg+AZ87QJANuwwmAnSNDOFfjeQpPDLy6wtBeft\
5VOIORUYiovKRZWmbGFwhn6BQL+VaafrNaezqUweBRi1PYiAF2l3yLZbUQJAf/nN\
4Hz/pzYmzLlWnGugP5WCtnHKkJWoKZBqO2RfOBCq+hY4sxvn3BHVbXqGcXLnZPvo\
YuaK7tTXxZSoYLEzeQJBAL8Mt3AkF1Gci5HOug6jT4s4Z+qDDrUXo9BlTwSWP90v\
wlHF+mkTJpKd5Wacef0vV+xumqNorvLpIXWKwxNaoHM=\
-----END RSA PRIVATE KEY-----'
const priv = forge.pki.privateKeyFromPem(private_key);
const pub = forge.pki.publicKeyFromPem(pub_key);
const g_key_l = [0x42, 0xda, 0x13, 0xba, 0x78, 0x76, 0x8d, 0x37, 0xe8, 0xee, 0x04, 0x91]
const g_key_s = [0x29, 0x23, 0x21, 0x5e]
const g_kts = [0xf0, 0xe5, 0x69, 0xae, 0xbf, 0xdc, 0xbf, 0x5a, 0x1a, 0x45, 0xe8, 0xbe, 0x7d, 0xa6, 0x73, 0x88, 0xde, 0x8f, 0xe7, 0xc4, 0x45, 0xda, 0x86, 0x94, 0x9b, 0x69, 0x92, 0x0b, 0x6a, 0xb8, 0xf1, 0x7a, 0x38, 0x06, 0x3c, 0x95, 0x26, 0x6d, 0x2c, 0x56, 0x00, 0x70, 0x56, 0x9c, 0x36, 0x38, 0x62, 0x76, 0x2f, 0x9b, 0x5f, 0x0f, 0xf2, 0xfe, 0xfd, 0x2d, 0x70, 0x9c, 0x86, 0x44, 0x8f, 0x3d, 0x14, 0x27, 0x71, 0x93, 0x8a, 0xe4, 0x0e, 0xc1, 0x48, 0xae, 0xdc, 0x34, 0x7f, 0xcf, 0xfe, 0xb2, 0x7f, 0xf6, 0x55, 0x9a, 0x46, 0xc8, 0xeb, 0x37, 0x77, 0xa4, 0xe0, 0x6b, 0x72, 0x93, 0x7e, 0x51, 0xcb, 0xf1, 0x37, 0xef, 0xad, 0x2a, 0xde, 0xee, 0xf9, 0xc9, 0x39, 0x6b, 0x32, 0xa1, 0xba, 0x35, 0xb1, 0xb8, 0xbe, 0xda, 0x78, 0x73, 0xf8, 0x20, 0xd5, 0x27, 0x04, 0x5a, 0x6f, 0xfd, 0x5e, 0x72, 0x39, 0xcf, 0x3b, 0x9c, 0x2b, 0x57, 0x5c, 0xf9, 0x7c, 0x4b, 0x7b, 0xd2, 0x12, 0x66, 0xcc, 0x77, 0x09, 0xa6]
var m115_l_rnd_key = genRandom(16)
var m115_s_rnd_key = []
var key_s = []
var key_l = []
function intToByte(i) {
var b = i & 0xFF;
var c = 0;
if (b >= 256) {
c = b % 256;
c = -1 * (256 - c);
} else {
c = b;
}
return c
}
function stringToArray(s) {
var map = Array.prototype.map
var array = map.call(s, function (x) {
return x.charCodeAt(0);
})
return array
}
function arrayTostring(array) {
var result = "";
for (var i = 0; i < array.length; ++i) {
result += (String.fromCharCode(array[i]));
}
return result;
}
function m115_init() {
key_s = []
key_l = []
}
function m115_setkey(randkey, sk_len) {
var length = sk_len * (sk_len - 1)
var index = 0
var xorkey = ''
if (randkey) {
for (var i = 0; i < sk_len; i++) {
var x = intToByte((randkey[i]) + (g_kts[index]))
xorkey += String.fromCharCode(g_kts[length] ^ x)
length -= sk_len
index += sk_len
}
if (sk_len == 4) {
key_s = stringToArray(xorkey)
} else if (sk_len == 12) {
key_l = stringToArray(xorkey)
}
}
}
function xor115_enc(src, key) {
var lkey = key.length
var secret = []
var num = 0
var pad = (src.length) % 4
if (pad > 0) {
for (var i = 0; i < pad; i++) {
secret.push((src[i]) ^ key[i])
}
src = src.slice(pad)
}
for (var j = 0; j < src.length; j++) {
if (num >= lkey) {
num = num % lkey
}
secret.push((src[j] ^ key[num]))
num += 1
}
return secret
}
function genRandom(len) {
var keys = []
var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz23456789';
var maxPos = chars.length;
for (var i = 0; i < len; i++) {
keys.push(chars.charAt(Math.floor(Math.random() * maxPos)).charCodeAt(0));
}
return keys;
}
function m115_encode(plaintext) {
//console.log('m115_encode:')
m115_init()
key_l = g_key_l
m115_setkey(m115_l_rnd_key, 4)
var tmp = xor115_enc(stringToArray(plaintext), key_s).reverse()
var xortext = xor115_enc(tmp, key_l)
var text = arrayTostring(m115_l_rnd_key) + arrayTostring(xortext)
var ciphertext = pub.encrypt(text)
ciphertext = encodeURIComponent(forge.util.encode64(ciphertext))
return ciphertext
}
function m115_decode(ciphertext) {
//console.log('m115_decode:')
var bciphertext = forge.util.decode64(ciphertext)
var block = bciphertext.length / (128)
var plaintext = ''
var index = 0
for (var i = 1; i <= block; ++i) {
plaintext += priv.decrypt(bciphertext.slice(index, i * 128))
index += 128
}
m115_s_rnd_key = stringToArray(plaintext.slice(0, 16))
plaintext = plaintext.slice(16);
m115_setkey(m115_l_rnd_key, 4)
m115_setkey(m115_s_rnd_key, 12)
var tmp = xor115_enc(stringToArray(plaintext), key_l).reverse()
plaintext = xor115_enc(tmp, key_s)
return arrayTostring(plaintext)
}
function PostData(dict) {
var k, tmp, v;
tmp = [];
for (k in dict) {
v = dict[k];
tmp.push(k + "=" + v);
}
return tmp.join('&');
};
function UrlData(dict) {
var k, tmp, v;
tmp = [];
for (k in dict) {
v = dict[k];
tmp.push((encodeURIComponent(k)) + "=" + (encodeURIComponent(v)));
}
return tmp.join('&');
};
function GetSig(userid, fileid, target, userkey) {
var sha1, tmp;
sha1 = new jsSHA('SHA-1', 'TEXT');
sha1.update("" + userid + fileid + fileid + target + "0");
tmp = sha1.getHash('HEX');
sha1 = new jsSHA('SHA-1', 'TEXT');
sha1.update("" + userkey + tmp + "000000");
return sha1.getHash('HEX', {
outputUpper: true
});
}
function download(filename, content, contentType) {
if (!contentType) contentType = 'application/octet-stream';
var a = document.createElement('a');
var blob = new Blob([content], {
'type': contentType
});
a.href = window.URL.createObjectURL(blob);
a.download = filename;
a.click();
}
function RenewCookie() {
var arryCookie = window.cookie.split(';');
arryCookie.forEach(function (kv) {
document.cookie = kv + ";expires=Thu, 01 Jan 2100 00:00:00 UTC;;domain=.115.com"
})
}
function DeleteCookie(resp) {
try {
var reg = /set-cookie: .+;/g;
var setcookie = reg.exec(resp)[0].split(';');
var filecookie = setcookie[0].slice(11) + "; expires=Thu, 01 Jan 1970 00:00:00 UTC;" + setcookie[3] + ";domain=.115.com";
document.cookie = filecookie;
RenewCookie()
return filecookie;
} catch (err) {
return null;
}
}
//#endregion
function hereDoc(f) {
return f.toString().replace(/^[^\/]+\/\*!?\s?/, '').replace(/\*\/[^\/]+$/, '');
}
const TaskType = {
DOWNLOAD: 'Download', //提取
UPLOAD: 'Upload', //转存
};
const MessageType = {
BEGIN: 0,
PROCESSING: 1,
END: 2,
ERROR: 3,
CLOSE: 4,
CANCEL: 5,
BEGIN4UPLOAD: 6,
END4UPLOAD: 7,
NOTIFYINFO: 8,
BEGIN4CONTINUETASK: 9,
SHOWCANCEl: 10,
HIDECANCEL: 11,
};
function createMessage(messageType, msg, id) {
return {
messageType: messageType,
msg: msg,
targetID: id
}
}
String.prototype.format = function () {
if (arguments.length == 0) {
return this;
}
for (var s = this, i = 0; i < arguments.length; i++) {
s = s.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
}
return s;
};
var getTamplateLines = function () {
/*
<div >
<div class="itemContent" style="color: red;text-align: left;margin: 10px 0;">
</div>
<hr />
<div style="height:140px;overflow-x: hidden;overflow-y: auto;">
<ul class="errorList" style="font-size: small;text-align: left;font-style: italic; "></ul>
</div>
</div>
*/
};
//post from iframe
function postSha1Messgae(message) {
var postData = {
eventID: "115sha1",
data: message
};
var text = JSON.stringify(postData);
window.parent.postMessage(text, "https://115.com/");
}
function setTaskCancel() {
GM_setValue("setTaskCancel", true)
}
function resetTaskCancelFlag() {
GM_setValue("setTaskCancel", false)
}
function getTaskCancelFlag() {
return GM_getValue("setTaskCancel");
}
const footerString=`<p><span style="color:#2777F8">[${TIPS.CurrentVersion}]</span>: 操作时,<span class="my115Info">确保本页面置顶</span>,防止脚本休眠!!
<br><span class="my115Info">无</span>115会员,<span class="my115Info">提取速度</span>受限,<span class="my115Info">转存文件大小</span>不超过5GB!!</p>`;
//解决提取时的alert不能全屏的问题
if (window.top === window.self) {
$(function () {
var $itemContent = null;
var $errorList = null;
var getTamplate = hereDoc(getTamplateLines);
$(window).on("message", function (e) {
var dataInfo = JSON.parse(e.originalEvent.data);
if (dataInfo.eventID != "115sha1" || e.originalEvent.origin != "https://115.com") return;
var message = dataInfo.data;
//ui:
if (message.messageType == MessageType.BEGIN) {
Swal.fire({
title: '正在操作中...',
html: getTamplate,
allowOutsideClick: false,
allowEscapeKey: false,
confirmButtonText: `完成`,
showCancelButton: true,
cancelButtonText: `取消操作`,
footer: footerString,
willOpen: function () {
Swal.getCancelButton().style.display = "none";
Swal.showLoading(Swal.getConfirmButton());
var $swalContent1 = $(Swal.getHtmlContainer());
$errorList = $swalContent1.find(".errorList");
$itemContent = $swalContent1.find(".itemContent");
}
}).then((result) => {
if (result.dismiss === Swal.DismissReason.cancel) {
setTaskCancel();
console.log("Download Cancel Task");
Swal.fire({
title: '已取消,等待进行中的任务结束...',
html: getTamplate,
allowOutsideClick: false,
allowEscapeKey: false,
confirmButtonText: `完成`,
footer: footerString,
willOpen: function () {
Swal.showLoading(Swal.getConfirmButton());
var $swalContent1 = $(Swal.getHtmlContainer());
let html = $errorList.eq[0];
$errorList = $swalContent1.find(".errorList");
$errorList.append(html);
$itemContent = $swalContent1.find(".itemContent");
}
})
}
});
} else if (message.messageType == MessageType.PROCESSING) {
$itemContent.html(message.msg);
} else if (message.messageType == MessageType.ERROR) {
$errorList.append('<li><div display: flex;"><p>' + message.msg + '</p><p style="font-style: italic;"><\p><\div><\li><li><hr/></li>');
} else if (message.messageType == MessageType.END) {
$itemContent.html(message.msg);
Swal.getTitle().textContent = "操作完成!";
Swal.getCancelButton().style.display = "none";
Swal.getFooter().style.display = "none";
Swal.hideLoading();
} else if (message.messageType == MessageType.CLOSE) {
Swal.close();
} else if (message.messageType == MessageType.BEGIN4UPLOAD) {
Swal.fire({
title: '正在操作中...',
html: getTamplate,
allowOutsideClick: false,
allowEscapeKey: false,
confirmButtonText: `完成`,
denyButtonText: `打开目录`,
showCancelButton: true,
cancelButtonText: "取消操作",
footer: footerString,
willOpen: function () {
Swal.getCancelButton().style.display = "none";
Swal.getDenyButton().style.display = "none";
Swal.showLoading(Swal.getConfirmButton());
var $swalContent1 = $(Swal.getHtmlContainer());
$errorList = $swalContent1.find(".errorList");
$itemContent = $swalContent1.find(".itemContent");
}
}).then(result => {
if (result.dismiss === Swal.DismissReason.cancel) {
setTaskCancel();
console.log("Upload Cancel Task");
console.log(window.parent.document.myData)
Swal.fire({
title: '已取消,等待进行中的任务完成...',
html: getTamplate,
allowOutsideClick: false,
allowEscapeKey: false,
confirmButtonText: `完成`,
denyButtonText: `打开目录`,
showCancelButton: false,
cancelButtonText: "取消操作",
willOpen: function () {
Swal.getDenyButton().style.display = "none";
Swal.showLoading(Swal.getConfirmButton());
var $swalContent1 = $(Swal.getHtmlContainer());
$errorList = $swalContent1.find(".errorList");
$itemContent = $swalContent1.find(".itemContent");
}
});
}
});
} else if (message.messageType == MessageType.END4UPLOAD) {
$itemContent.html(message.msg);
Swal.getTitle().textContent = "操作完成!";
Swal.getCancelButton().style.display = "none";
Swal.getDenyButton().style.display = "block";
Swal.getDenyButton().addEventListener('click', e => {
console.log("DenyButton click");
console.log(message);
window.location.href = "https://115.com/?cid=" + message.targetID + "&offset=0&tab=&mode=wangpan";
});
Swal.getFooter().style.display = "none";
Swal.hideLoading();
} else if (message.messageType == MessageType.BEGIN4CONTINUETASK) {
let taskFile = '';
Swal.fire({
title: '导入任务文件,继续任务',
html: `<div style="text-align: left;">
选择任务文件(.7task):<input id="continuedTaskFile" type="file" accept=".7task" ></input>
<div style="font-size:14px;color:red;margin:10px;text-align: left;">*在没有移动相关的文件以及文件夹,包括目标的所有目录层级,导入任务可继续</div>
</div>`,
focusConfirm: false,
confirmButtonText: `开始继续任务`,
}).then(t => {
if (t.isConfirmed && taskFile) {
ContinuedTask(taskFile);
}
})
document.getElementById('continuedTaskFile').addEventListener('change', e => {
taskFile = e.target.files[0];
})
} else if (message.messageType == MessageType.SHOWCANCEl) {
if (Swal.getCancelButton()) {
//Swal.getCancelButton().style.display = "block";
}
} else if (message.messageType == MessageType.HIDECANCEL) {
if (Swal.getCancelButton()) {
Swal.getCancelButton().style.display = "none";
}
}
})
});
}
function delay(ms) {
if (ms == 0) {
ms = 1000 * (Math.floor(Math.random() * (11 - 4)) + 4);
}
return new Promise(resolve => setTimeout(resolve, ms))
}
//#region 115 api
//get UploadInfo
//return {state:false,user_id:0,userkey:'0',error:''}
async function getUploadInfo() {
const r = await $.ajax({
url: 'https://proapi.115.com/app/uploadinfo',
dataType: 'json',
xhrFields: {
withCredentials: true
}
});
return r;
}
//add a folder
//return {state: false, error: "该目录名称已存在。", errno: 20004, errtype: "war"}
//return {state: true, error: "", errno: "", aid: 1, cid: "2020455078010511975", …}
async function addFolder(pid, folderName) {
const postData = PostData({
pid: pid,
cname: encodeURIComponent(folderName)
});
const r = await $.ajax({
type: 'POST',
url: 'https://webapi.115.com/files/add',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
//'Origin': 'https://115.com'
},
xhrFields: {
withCredentials: true
},
dataType: 'json',
data: postData
});
return r;
}
//return {data: Array(30), count: 53, data_source: "DB", sys_count: 0, offset: 0, page_size:115, …}
//return Array type:
// [folder]:{cid: "", aid: "1", pid: "", n: "", m: 0, …}
// [file]: {fid: "", uid: 1447812, aid: 1, cid: "", n: "",pc:"",sha:"",s:0,t:"" …}
async function getDirectChildItemsByOffset(cid, offset) {
var tUrl = 'https://webapi.115.com/files?aid=1&cid=' + cid + '&o=file_name&asc=1&offset=' + offset + '&show_dir=1&limit=1150&code=&scid=&snap=0&natsort=1&record_open_time=1&source=&format=json&fc_mix=&type=&star=&is_share=&suffix=&custom_order=';
// var tUrl = "https://aps.115.com/natsort/files.php?aid=1&cid=" + cid + "&o=file_name&asc=1&offset=" + offset + "&show_dir=1&limit=1150&code=&scid=&snap=0&natsort=1&record_open_time=1&source=&format=json&fc_mix=0&type=&star=&is_share=&suffix=&custom_order=";
const result = await $.ajax({
type: 'GET',
url: tUrl,
dataType: "json",
xhrFields: {
withCredentials: true
}
});
return result;
}
//直接子项目少于1200
async function getDirectChildItemsByOffsetlt1200(cid, offset) {
//var tUrl = 'https://webapi.115.com/files?aid=1&cid='+cid+'&o=file_name&asc=1&offset='+offset+'&show_dir=1&limit=1150&code=&scid=&snap=0&natsort=1&record_open_time=1&source=&format=json&fc_mix=&type=&star=&is_share=&suffix=&custom_order=';
var tUrl = "https://aps.115.com/natsort/files.php?aid=1&cid=" + cid + "&o=file_name&asc=1&offset=" + offset + "&show_dir=1&limit=1150&code=&scid=&snap=0&natsort=1&record_open_time=1&source=&format=json&fc_mix=0&type=&star=&is_share=&suffix=&custom_order=";
const result = await $.ajax({
type: 'GET',
url: tUrl,
dataType: "json",
xhrFields: {
withCredentials: true
}
});
return result;
}
//return AllDirect items :{id:"",parentID:cid,isFolder:false,name:"",size:0,pc:"",sha:"",paths[] };
async function getAllDirectItems(cid, folderProcessCallback) {
var items = new Array();
var index = 0;
var flag = true;
var pageIndex = 1;
var first = true;
var isLT1200 = false;
while (flag) {
if (getTaskCancelFlag()) break;
folderProcessCallback(pageIndex);
var result = null;
//1200数量,不同的api;这么写减少发包
if (first) {
result = await getDirectChildItemsByOffset(cid, index);
console.log("first >1200 :{0},{1}".format(result.state, result.count));
if (!result.state) {
result = await getDirectChildItemsByOffsetlt1200(cid, index);
console.log("first <1200 :{0},{1}".format(result.state, result.count));
isLT1200 = true;
}
first = false;
} else {
if (isLT1200) result = await getDirectChildItemsByOffsetlt1200(cid, index);
else result = await getDirectChildItemsByOffset(cid, index);
}
var totalCount = parseInt(result.count);
if (totalCount >= 1) {
result.data.forEach(function (item) {
var pItem = {
id: "",
parentID: cid,
isFolder: false,
name: "",
size: "",
pickCode: "",
sha1: "",
paths: new Array(),
preid: "",
needToRemoved: false
};
if (item.fid) //文件 fid,cid
{
pItem.isFolder = false;
pItem.id = item.fid;
pItem.name = item.n;
pItem.pickCode = item.pc;
pItem.sha1 = item.sha;
pItem.size = item.s;
} else //目录 cid,pid
{
pItem.isFolder = true;
pItem.id = item.cid;
pItem.name = item.n;
pItem.pickCode = item.pc;
}
var itemIndex = items.findIndex(q => q.name == pItem.name && q.pickCode == pItem.pickCode && q.sha1 == pItem.sha1 && (_.isEqual(q.paths, pItem.paths)));
if (itemIndex == -1) items.push(pItem);
else {
//可能存在同一个目录下,两个文件一模一样,
//相同文件处理:不然循环条件退不出
//fix:pickcode不一样,先保存着吧
pItem.needToRemoved = true;
items.push(pItem)
}
})
}
console.log("_______________totalCount " + totalCount);
console.log(items.length)
//当获取到比pagesize小时,获取结束,1200时有个坑。。。
if (totalCount <= items.length) {
break;
} else {
await delay(500);
index = items.length;
pageIndex = pageIndex + 1;
}
}
console.log("cid: {0}, count: {1}".format(cid, items.length));
var noNullItems = items.filter(q => !q.needToRemoved);
console.log("cid: {0}, 除去完全重复count: {1}".format(cid, noNullItems.length));
return noNullItems;
}
//return {file_name:"",pick_code:"",sha1:"",count:"",size:"",folder_count:"",paths:[]}
//return paths:[]层级目录
async function getFolderInfo(cid) {
var pUrl = "https://webapi.115.com/category/get?aid=1&cid=" + cid;
const result = await $.ajax({
type: 'GET',
url: pUrl,
dataType: "json",
xhrFields: {
withCredentials: true
}
});
console.log(result);
var pItem = {
fileCount: parseInt(result.count),
folderCount: parseInt(result.folder_count),
id: cid,
parentID: "",
isFolder: true,
name: result.file_name,
size: result.size,
pickCode: result.pick_code,
sha1: "",
paths: result.paths,
preid: ""
};
return pItem;
}
// get fileArray:{id:"",parentID:cid,isFolder:false,name:"",size:0,pc:"",sha:"",paths[] };
async function getAllFiles(cid, fileArray, topCid, folderProcessCallback) {
var thisFolder = await getFolderInfo(cid);
folderProcessCallback(thisFolder.name, 0);
//空目录,跳过遍历
if (getTaskCancelFlag()) return;
if (thisFolder.fileCount == 0) return;
folderProcessCallback(thisFolder.name)
var directItems = await getAllDirectItems(thisFolder.id, pageIndex => {
folderProcessCallback(thisFolder.name, pageIndex);
});
//空目录,跳过遍历
if (directItems.length == 0) return;
var files = directItems.filter(t => !t.isFolder);
files.forEach(f => {
var index = thisFolder.paths.findIndex(q => q.file_id.toString() == topCid);
var paths = new Array();
if (index != -1) {