-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathali.js
More file actions
4538 lines (4399 loc) · 210 KB
/
Copy pathali.js
File metadata and controls
4538 lines (4399 loc) · 210 KB
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
const ali = {
rulePath: 'hiker://files/rules/icy/ali.js',
urls: {
settingPath: 'hiker://files/rules/icy/icy-settings-ali.json',
customerSettingPath: 'hiker://files/rules/icy/icy-ali-customer.json',
tokenPath: 'hiker://files/rules/icy/icy-ali-token.json',
// settingHtmlPath: 'file:///storage/emulated/0/Android/data/com.example.hikerview/files/Documents/rules/icy/icy-settings-ali.html',
remoteConfig: ['https://gitee.com/fly1397/hiker-icy/raw/master/settings-ali.json', 'https://cdn.jsdelivr.net/gh/fly1397/hiker-icy/settings-ali.json', 'http://lficy.com:30000/mrfly/hiker-icy/raw/master/settings-ali.json'],
},
images: {
zimu: 'https://hikerfans.com/tubiao/more/186.png',
folder: 'https://hikerfans.com/tubiao/more/201.png',
img: 'https://hikerfans.com/tubiao/more/295.png',
video: 'https://hikerfans.com/tubiao/more/321.png',
audio: 'https://hikerfans.com/tubiao/music/115.svg',
book: 'https://hikerfans.com/tubiao/more/133.png',
unknown: 'https://hikerfans.com/tubiao/more/2.png',
order: 'https://hikerfans.com/tubiao/more/31.png',
view: 'https://hikerfans.com/tubiao/more/213.png',
source: 'https://hikerfans.com/tubiao/movie/16.svg',
},
version: '2023/05/13',
randomPic: 'htt/ps://api.lmrjk.cn/mt', //二次元 http://api.lmrjk.cn/img/api.php 美女 https://api.lmrjk.cn/mt
// dev 模式优先从本地git获取
isDev: false,
// 强制更新config
forceConfigUpdate: false,
// 阿里共享账号设置
usePublicToken: false,
publicToken: '',
//开起热搜榜
useSuggestQuery: true,
sourcePlay: false,
// 颜色
primaryColor: '#f47983',
update: function(){
const version = getItem('icy_ali_version');
if(version !== null && Number(version) !== 0 && version != this.version) {
var js = $.toString(() => {
eval(fetch("hiker://files/rules/icy/ali.js"));
ali.initConfig(true);
setItem("icy_ali_version", ali.version);
refreshPage();
confirm({
title:"更新成功",
content:"最新版本:" + ali.version
})
})
// eval(js)
confirm({
title: '版本更新 ',
content: (version || 'N/A') +'=>'+ this.version + '\n1,更新转码播放地址',
confirm: 'eval(fetch("hiker://files/rules/icy/ali.js"));ali.initConfig(true);setItem("icy_ali_version", ali.version);refreshPage();confirm({title:"更新成功",content:"最新版本:" + ali.version})'
})
}
},
linkProcessing:function(res,url){
if(!JSON.parse(res).links.first.startsWith('http')){
var h=url.match(/https?:\/\/(\w+\.?)+/)[0];
var r=JSON.parse(res);
r.links.first=h+r.links.first;
r.links.next=h+r.links.next;
res=JSON.stringify(r);
}
return res;
},
formatBytes: function(a, b) {
if (0 == a) return "0 B";
var c = 1024, d = b || 2, e = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], f = Math.floor(Math.log(a) / Math.log(c));
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f];
},
getEmptyTitle: function(_title, _desc){
// 修复部分贴没有标题,提取「分享主题」作为标题
let desc = _desc.trim();
let title = _title;
if(!title){
const maName = desc.match(/[译|片]\s*名\s*(.*)/);
const maDesc = desc.match(/「(.*)」,?/);
const maDesc_2 = desc.match(/『(.*)』/);
if(maName && maName[1]){
title = maName[1].split('◎')[0].replace(':', '');
}else if(maDesc) {
title = maDesc[1].split('」')[0];
} else if(maDesc_2) {
title = maDesc_2[1];
} else {
if(desc.includes(',')){
title = desc.split(/,/)[0];
} else {
title = desc.split(/\s+/)[0];
if(title.length < 2) {
title = desc
}
}
}
}
const titleDom = '<div class="fortext">' + title || '' + '</div>';
let result = parseDomForHtml(titleDom, '.fortext&&Text');
let len = 24;
if(result.length > len) {
result = result.substr(0, len) + '...'
}
return result;
},
formatDate: function(_date, _fmt) {
let fmt = _fmt || "yyyy-MM-dd HH:mm:ss";
const date = !isNaN(_date) ? new Date(_date*1000) : new Date(_date);
const o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"h+": date.getHours()%12 == 0 ? 12 : date.getHours()%12,
"H+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(let k in o) {
if(new RegExp("("+ k +")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
}
}
return fmt;
},
formatSize: function(size){
if(!size) {
return '';
}
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let i = 0;
while (size >= 1024) {
size /= 1024;
i++;
}
size = i ? Number(size.toFixed(2)) : size;
return `${size} ${units[i]}`;
},
searchFetch: function(host, url, keyword, page, cookie){
const {fyarea, fyclass, fyyear, fysort} = this.getFilter(true);
const link = url.replace('**', keyword).replace('fypage', (((page||1) - 1) * 20)).replace('fyarea', fyarea).replace('fyclass', fyclass).replace('fyyear', fyyear).replace('fysort', fysort);
const headers = {"Referer": link, 'User-Agent': MOBILE_UA,};
headers['cookie'] = (cookie || '');
var res =fetch(link, {headers: headers});
res=this.linkProcessing(res,link);
return res
},
activeModel: function(searchPage) {
let model_search = getVar('icy_ali_model');
this.getConfig();
const {searchModel} = this;
if(searchPage) {
model_search = getVar('icy_ali_model_search');
}
let deafultModel = searchModel[0];
const hasToken = fileExist(this.urls.tokenPath) == 'true' || fileExist(this.urls.tokenPath) == true;
if(hasToken) {
deafultModel = null;
}
return searchModel ? searchModel.find(item => item.val == model_search) || (searchPage ? searchModel[0] : deafultModel): null;
},
objData: function(obj, path){
let _obj = obj;
path.split('&&').forEach(_path => {
_obj = _obj[_path];
})
return _obj;
},
strData: function(obj, path){
let _obj = obj;
path.split('&&').forEach(_path => {
_obj = _obj[_path];
})
return _obj;
},
searchModel: [],
emptyRule: $("#noLoading#").lazyRule(()=>{return "toast://Emmm~~!"}),
getConfig: function(){
const {settingPath, remoteConfig, customerSettingPath} = this.urls;
putVar('icy_ali_customer', customerSettingPath);
const haveSetting = fileExist(settingPath) == 'true' || fileExist(settingPath) == true;
let json = haveSetting ? fetch(settingPath) : '';
const firstConfigPath = this.isDev ? remoteConfig[2] : remoteConfig[0];
if(!json) {
json = fetch(firstConfigPath);
if(!json || !json.includes('name')) {
json = fetch(remoteConfig[1]);
}
if(!json || !json.includes('name')) {
json = fetch(remoteConfig[2]);
}
}
if(!haveSetting && json) {
writeFile(settingPath, json);
}
if(json) {
this.searchModel = JSON.parse(json).sort((a,b) => a.index - b.index);
const haveCustomerSetting = fileExist(customerSettingPath) == 'true' || fileExist(customerSettingPath) == true;
this.searchModel = JSON.parse(json).sort((a,b) => a.index - b.index);
if(haveCustomerSetting) {
const customerSetting = JSON.parse(fetch(customerSettingPath));
if(customerSetting.customerResouce) {
this.searchModel = JSON.parse(json).map(item => {
const customer = customerSetting.customerResouce.find(_customer => _customer.key == item.key);
this.mergeObj(customer || {},item);
return item;
}).sort((a,b) => a.index - b.index);
}
this.usePublicToken = customerSetting.usePublicToken;
this.publicToken = customerSetting.publicToken;
this.useSuggestQuery = customerSetting.useSuggestQuery;
this.primaryColor = customerSetting.primaryColor;
this.sourcePlay = !!customerSetting.sourcePlay;
}
}
},
initConfig: function(forceConfigUpdate){
const {settingPath, remoteConfig, customerSettingPath} = this.urls;
putVar('icy_ali_customer', customerSettingPath);
const firstConfigPath = this.isDev ? remoteConfig[2] : remoteConfig[0];
const haveSetting = fileExist(settingPath) == 'true' || fileExist(settingPath) == true;
let json = haveSetting ? fetch(settingPath) : '';
if(!json || forceConfigUpdate || this.isDev) {
json = fetch(firstConfigPath);
if(!json || !json.includes('name')) {
json = fetch(remoteConfig[1]);
}
if(!json || !json.includes('name')) {
json = fetch(remoteConfig[2]);
}
}
if(json) {
writeFile(settingPath, json);
this.searchModel = JSON.parse(json).sort((a,b) => a.index - b.index);
}
const haveCustomerSetting = fileExist(customerSettingPath) == 'true' || fileExist(customerSettingPath) == true;
if(haveCustomerSetting) {
const customerSetting = JSON.parse(fetch(customerSettingPath));
if(customerSetting.customerResouce) {
let customerResouce = [];
this.searchModel.forEach(item => {
const customer = customerSetting.customerResouce.find(_customer => _customer.key == item.key);
if(customer) {
customer.val = item.val;
customer.name = item.name;
customer.key = item.key;
customer.needKey = item.needKey;
customerResouce.push(customer);
} else {
customerResouce.push({
val: item.val,
key: item.key,
name: item.name,
needKey: item.needKey,
index: (customerResouce.length + 1)
});
}
});
customerSetting.customerResouce = customerResouce;
}
writeFile(customerSettingPath, JSON.stringify(customerSetting));
}
},
mergeObj: function(targt, source){
Object.keys(targt).forEach(key => {
source[key] = targt[key];
})
},
updateRule: function(){
let ruleCode = "海阔视界规则分享,当前分享的是:小程序¥home_rule_v2¥base64://@云盘汇影@eyJsYXN0X2NoYXB0ZXJfcnVsZSI6IiIsInRpdGxlIjoi5LqR55uY5rGH5b2xIiwiYXV0aG9yIjoiTXJGbHkiLCJ1cmwiOiJoaWtlcjovL2VtcHR5JCQkZnlwYWdlIiwidmVyc2lvbiI6NiwiY29sX3R5cGUiOiJ0ZXh0XzEiLCJjbGFzc19uYW1lIjoiIiwidHlwZSI6ImFsbCIsImNsYXNzX3VybCI6IiIsImFyZWFfbmFtZSI6IiIsImFyZWFfdXJsIjoiIiwic29ydF9uYW1lIjoiIiwieWVhcl9uYW1lIjoiIiwic29ydF91cmwiOiIiLCJ5ZWFyX3VybCI6IiIsImZpbmRfcnVsZSI6ImpzOlxuZXZhbChmZXRjaCgnaGlrZXI6Ly9maWxlcy9ydWxlcy9pY3kvYWxpLmpzJykpO1xuYWxpLmhvbWVQYWdlKCk7Iiwic2VhcmNoX3VybCI6Imhpa2VyOi8vZW1wdHkkJCQqKiQkJGZ5cGFnZSQkJCIsImdyb3VwIjoi4pGg5o6o6I2QIiwic2VhcmNoRmluZCI6ImpzOlxuZXZhbChmZXRjaCgnaGlrZXI6Ly9maWxlcy9ydWxlcy9pY3kvYWxpLmpzJykpO1xuYWxpLnNlYXJjaFBhZ2UodHJ1ZSk7XG4iLCJkZXRhaWxfY29sX3R5cGUiOiJtb3ZpZV8xIiwiZGV0YWlsX2ZpbmRfcnVsZSI6ImpzOlxuZXZhbChmZXRjaCgnaGlrZXI6Ly9maWxlcy9ydWxlcy9pY3kvYWxpLmpzJykpO1xuYWxpLmRldGFpbFBhZ2UoKTsiLCJzZGV0YWlsX2NvbF90eXBlIjoibW92aWVfMSIsInNkZXRhaWxfZmluZF9ydWxlIjoiIiwidWEiOiJtb2JpbGUiLCJwcmVSdWxlIjoidmFyIGFsaWpzID0gZmV0Y2goJ2h0dHBzOi8vZ2l0ZWUuY29tL2ZseTEzOTcvaGlrZXItaWN5L3Jhdy9tYXN0ZXIvYWxpLmpzJyk7XG5pZighYWxpanMgfHwgIWFsaWpzLmluY2x1ZGVzKCdhbGknKSl7XG5cdGFsaWpzID0gZmV0Y2goJ2h0dHBzOi8vY2RuLmpzZGVsaXZyLm5ldC9naC9mbHkxMzk3L2hpa2VyLWljeS9hbGkuanMnKVxufVxuaWYoIWFsaWpzIHx8ICFhbGlqcy5pbmNsdWRlcygnYWxpJykpe1xuXHRhbGlqcyA9IGZldGNoKCdodHRwOi8vbGZpY3kuY29tOjMwMDAwL21yZmx5L2hpa2VyLWljeS9yYXcvbWFzdGVyL2FsaS5qcycpXG59XG5pZihhbGlqcykge1xuXHR3cml0ZUZpbGUoXCJoaWtlcjovL2ZpbGVzL3J1bGVzL2ljeS9hbGkuanNcIixhbGlqcyk7XG5cdGV2YWwoYWxpanMpO1xuXHRhbGkucHJlUnVsZSgpO1xufVxuIiwicGFnZXMiOiJbe1wiY29sX3R5cGVcIjpcIm1vdmllXzNcIixcIm5hbWVcIjpcIue9keebmOivpuaDhVwiLFwicGF0aFwiOlwiZGV0YWlsXCIsXCJydWxlXCI6XCJqczpcXG5ldmFsKGZldGNoKCdoaWtlcjovL2ZpbGVzL3J1bGVzL2ljeS9hbGkuanMnKSk7XFxuYWxpLmluaXRDb25maWcoKTtcXG5hbGkuYWxpUnVsZSgpO1wifSx7XCJjb2xfdHlwZVwiOlwibW92aWVfMV9sZWZ0X3BpY1wiLFwibmFtZVwiOlwi6LWE5rqQ572R6aG16K+m5oOFXCIsXCJwYXRoXCI6XCJzaXRlLWRldGFpbFwiLFwicnVsZVwiOlwianM6XFxuZXZhbChmZXRjaCgnaGlrZXI6Ly9maWxlcy9ydWxlcy9pY3kvYWxpLmpzJykpO1xcbmFsaS5kZXRhaWxQYWdlKCk7XCJ9LHtcImNvbF90eXBlXCI6XCJtb3ZpZV8zXCIsXCJuYW1lXCI6XCLkuKrkurrnvZHnm5jor6bmg4VcIixcInBhdGhcIjpcImRyaXZlXCIsXCJydWxlXCI6XCJqczpcXG5ldmFsKGZldGNoKCdoaWtlcjovL2ZpbGVzL3J1bGVzL2ljeS9hbGkuanMnKSk7XFxuYWxpLmluaXRDb25maWcoKTtcXG5hbGkubXlBbGlSdWxlKCk7XCJ9XSIsImljb24iOiJodHRwczovL2dpdGVlLmNvbS9mbHkxMzk3L2hpa2VyLWljeS9yYXcvbWFzdGVyL2FsaXl1bi5wbmcifQ==";
let importUrl = "rule://" + base64Encode(ruleCode);
return importUrl;
},
getRefreshToken: function(_url) {
const {tokenPath} = this.urls;
const haveToken = fileExist(tokenPath) == 'true' || fileExist(tokenPath) == true;
setPageTitle('阿里云盘');
addListener('onClose', () => {
let token = getVar('icy-ali-tokens');
if(token) {
saveFile('hiker://files/rules/icy/icy-ali-token.json', token);
}
clearVar('icy-ali-tokens')
})
let d = [];
let url = _url || 'https://www.aliyundrive.com/drive';
// if(getItem('haveShared', '') && !haveToken) {
// // url = 'https://pages.aliyundrive.com/mobile-page/web/beinvited.html?code=8281833';
// // url = 'https://www.aliyundrive.com/s/BFiLLN5Uu58';
// setItem('haveShared', '1')
// }
var js = $.toString(()=> {
var isShare = location.href.startsWith('https://www.aliyundrive.com/s/');
var isInvited = location.href.startsWith('https://pages.aliyundrive.com/');
var click = false;
const tokenFunction = function () {
var token = null;
var deviceID = "";
if(isShare) {
try{
if(!click){
var btn = document.querySelector('.btn--2uN28');
if(btn) {
btn.click();
click=true;
}
}
} catch(e){};
var saved = false;
var savetext = document.querySelector('.title--lRzap');
if(savetext) {
saved = savetext.innerText=='转存成功';
}
var _token = JSON.parse(localStorage.getItem('token'));
if(
_token && _token.user_id &&
(
(saved && isShare)
)
){
alert('保存成功,感谢支持!');
localStorage.clear();
fy_bridge_app.back();
return;
}
} else if(isInvited) {
try{
if(!click){
var btn = document.querySelector('.BeInvited--btn--eapb4-i');
if(btn) {
btn.click();
click=true;
}
}
} catch(e){};
var _token = JSON.parse(localStorage.getItem('token'));
if(
_token && _token.user_id
){
alert('注册成功,返回后重新选择登录页面进行登录!');
localStorage.clear();
fy_bridge_app.back();
return;
}
} else {
token = JSON.parse(localStorage.getItem('token'));
deviceID = localStorage.getItem('APLUS_CNA').includes('_') ? localStorage.getItem('APLUS_CNA').split('_')[1] : '';
// if(!location.href.startsWith('https://auth.aliyundrive.com') || !location.href.startsWith('https://www.aliyundrive.com/sign/callback')) {
// location.replace('https://auth.aliyundrive.com/v2/oauth/authorize?login_type=custom&response_type=code&redirect_uri=https%3A%2F%2Fwww.aliyundrive.com%2Fsign%2Fcallback&client_id=25dzX3vbYqktVxyX&state=%7B%22origin%22%3A%22*%22%7D#/login')
// }
}
if(token && token.user_id){
let token_url = 'hiker://files/rules/icy/icy-ali-token.json';
let _tokens = JSON.parse(request(token_url) || '[]');
let tokens = _tokens.length ? _tokens : (_tokens.user_id ? [_tokens] : [] );
let _token = tokens.find(item => item.user_id == token.user_id);
token.deviceID = deviceID
if(_token) {
_token = token;
} else {
tokens.push(token)
}
// alert(JSON.stringify(tokens))
fy_bridge_app.putVar('icy-ali-tokens', JSON.stringify(tokens))
// fy_bridge_app.writeFile('hiker://files/rules/icy/icy-ali-token.json',JSON.stringify(tokens));
localStorage.clear();
alert('TOKEN获取成功,请勿泄漏个人隐私!退出该页面后刷新重试!');
// if(location.href.includes('auth.aliyundrive.com')) {
// fy_bridge_app.back();
// }else if(location.href.includes('beinvited')) {
// fy_bridge_app.back();
// } else if(!location.href.includes('#token') && isShare) {
// location.href = 'https://www.aliyundrive.com/drive#token';
// }
fy_bridge_app.back();
return;
}else{
token_timer();
}
}
var token_timer= function(){
setTimeout(tokenFunction, 300)
};
token_timer();
tokenFunction();
})
d.push({
url: url,
col_type: 'x5_webview_single',
desc: '100%&&float',
extra: {
canBack: true,
js: js,
}
})
setHomeResult({
data: d
})
},
getAliToken: function() {
let needRefresh = true;
const {tokenPath, customerSettingPath} = this.urls;
this.getConfig();
if(this.usePublicToken && this.publicToken) {
try {
eval('function tokenFunction(){\n'+this.publicToken+'\n};');
if(tokenFunction().replace('Bearer ', '')) {
return tokenFunction().replace('Bearer ', '');
} else {
return 'toast://共享TOKEN获取失败,建议重启app再试试!'
}
} catch(e){
return 'toast://共享TOKEN代码运行失败了'
}
}
try {
const haveToken = fileExist(tokenPath) == 'true' || fileExist(tokenPath) == true;
if(haveToken) {
let _tokens = JSON.parse(readFile(tokenPath) || '[]');
let tokens = _tokens.length ? _tokens : (_tokens && _tokens.user_id ? [_tokens] : [] );
let customerSettings = JSON.parse(fetch(customerSettingPath));
let token = tokens.find(item => item.user_id == customerSettings.user_id) || tokens[0];
let deviceID = token.deviceID;
if((token && (!token.access_token || !token.refresh_token)) || !token) {
deleteFile(tokenPath);
return 'toast://TOKEN获取失败,已经删除阿里登录信息,重新登录试试'
}
if(!!needRefresh) {
const tokenRes = JSON.parse(fetch('https://auth.aliyundrive.com/v2/account/token', {
headers: {
"Content-Type": "application/json",
"User-Agent": MOBILE_UA,
},
method: 'POST',
body: '{"refresh_token":"'+token.refresh_token+'","grant_type":"refresh_token"}',
}));
if(tokenRes && tokenRes.user_id) {
tokenRes.deviceID = deviceID;
var access_token = tokenRes.access_token;
putVar("access_token", access_token);
let _token = tokens.find(item => item.user_id == tokenRes.user_id);
if(_token) {
tokens = tokens.map(item => {
if(item.user_id == tokenRes.user_id) {
item = tokenRes;
}
return item;
})
} else {
tokens.push(tokenRes);
}
saveFile(tokenPath,JSON.stringify(tokens));
return access_token;
} else if(tokenRes.code && tokenRes.code.included('InvalidParameter.RefreshToken')) {
return 'toast://登录状态已经过期,需要重新登录'
} else if(tokenRes.message){
return 'toast://' + tokenRes.message
}
} else {
let _access_token = token.access_token || token.token;
putVar("access_token", _access_token);
return _access_token;
}
} else {
this.aliLogin();
return false;
}
} catch (e) {
log(JSON.stringify(e));
// deleteFile(tokenPath);
return 'toast://TOKEN获取失败,重新登录试试'
}
},
pageManually: function(host, url){
setPageTitle('云盘汇影--手动档')
let d = [];
var js = $.toString((url)=> {
var isShare = location.href.startsWith('https://www.aliyundrive.com/s/');
var timer = function(){
setTimeout(()=>{
if(isShare){
fba.open(JSON.stringify({
rule:'云盘汇影',
url:'hiker://page/detail?rule=云盘汇影&url='+location.href+'??fypage'
}));
history.back(-1);
}else{
document.querySelector('.davwheat-ad').style.display = 'none';
timer();
}
},500)
};
timer();
}, url)
d.push({
url: host,
col_type: 'x5_webview_single',
desc: '100%&&float',
extra: {
canBack: true,
js: js
}
})
setHomeResult({
data: d
})
},
aliLogin: function(_d){
let d = _d || []
setPageTitle('阿里云盘账号设置');
const {tokenPath, customerSettingPath} = this.urls;
if(!getVar('icy_ali_customer','')) {
putVar('icy_ali_customer', customerSettingPath)
}
if(!getVar('icy_ali_tokenPath','')) {
putVar('icy_ali_tokenPath', tokenPath)
}
let customerSettings = JSON.parse(fetch(getVar('icy_ali_customer')) || '{}');
const haveToken = fileExist(tokenPath) == 'true' || fileExist(tokenPath) == true;
if(!haveToken) {
d.push({
title: '还没有设置阿里云盘账号信息',
desc: '阿里云盘在线观看需要设置登录信息,\n您可以选择登录/注册账号,或者他人共享的账号!',
url: this.emptyRule,
col_type: 'text_1'
})
} else {
let _tokens = JSON.parse(readFile(tokenPath) || '[]');
let tokens = _tokens.length ? _tokens : (_tokens && _tokens.user_id ? [_tokens] : [] );
let user_id = customerSettings && tokens[0] ? customerSettings.user_id || tokens[0].user_id : '';
tokens.forEach((item, index) => {
let title = item.user_id == user_id ? "<b>当前登录:"+'<span style="color: '+ this.primaryColor +'">⭐ '+item.nick_name+'</span></b>' : item.nick_name;
d.push({
title: title,
desc: '切换账号',
img: item.avatar+'@Referer=https://www.aliyundrive.com/',
url: $('#noLoading#').lazyRule((token) => {
eval(fetch('hiker://files/rules/icy/ali.js'));
ali.activeToken = token;
let customerSettings = JSON.parse(fetch(getVar('icy_ali_customer')));
customerSettings.user_id = token.user_id;
writeFile(getVar('icy_ali_customer'), JSON.stringify(customerSettings));
refreshPage(false);
return 'toast://账号切换至:' + token.nick_name;;
}, item),
col_type: 'avatar',
})
d.push({
title: '““””<small><span style="color: #999999">❌ 删除阿里云盘账号: <b>' + item.nick_name + '</b></span></small>',
url: $("确定要删除?")
.confirm((index) => {
let _tokens = JSON.parse(readFile(getVar('icy_ali_tokenPath')) || '[]');
let tokens = _tokens.length ? _tokens : (_tokens.user_id ? [_tokens] : [] );
tokens.splice(index, 1);
saveFile(getVar('icy_ali_tokenPath'), JSON.stringify(tokens));
refreshPage(false);
return 'toast://删除成功';
}, index),
col_type: 'text_1'
})
})
}
d.push({
col_type: "line_blank"
});
d.push({
title: '登录阿里云盘',
desc: '支持查看个人云盘文件,支持多账号模式\n登录后会自动清除信息方便下次重新登录',
url: $('hiker://empty').rule(() => {
eval(fetch('hiker://files/rules/icy/ali.js'));
ali.getRefreshToken();
}),
col_type: 'text_1'
})
d.push({
title: '注册阿里云盘',
desc: '支持作者邀请码注册,这里不做登录处理',
url: $('hiker://empty').rule(() => {
eval(fetch('hiker://files/rules/icy/ali.js'));
ali.getRefreshToken('https://pages.aliyundrive.com/mobile-page/web/beinvited.html?code=1906385');
}),
col_type: 'text_1'
})
d.push({
col_type: "line_blank"
});
d.push({
title: '去启用共享账号',
desc: '随时可以在设置页面启用或关闭共享账号',
url: $('hiker://empty').rule(() => {
eval(fetch('hiker://files/rules/icy/ali.js'));
ali.settingPage();
}),
col_type: 'text_1'
})
if(!_d) {
setResult({data: d});
}
},
preRule: function(){
const {settingPath, customerSettingPath, tokenPath} = this.urls;
this.initConfig(this.forceConfigUpdate);
this.getConfig();
this.update();
const activeModel = this.activeModel();
if(!getVar('icy_ali_model') && activeModel) {
const {areas, cats, years, sorts, val} = activeModel;
putVar('icy_ali_model', val || '');
if(areas) {
const _areas = areas.filter(item => item.withType != -1);
putVar('icy_ali_area', _areas[0] ? _areas[0].val : '');
}
if(cats) {
const _cats = cats.filter(item => item.withType != -1);
putVar('icy_ali_cat', _cats[0] ? _cats[0].val : '');
}
if(years) {
const _years = years.filter(item => item.withType != -1);
putVar('icy_ali_year', _years[0] ? _years[0].val : '');
}
if(sorts) {
const _sorts = sorts.filter(item => item.withType != -1);
putVar('icy_ali_sort' , _sorts[0] ? _sorts[0].val : '')
}
putVar("icy_ali_search", '');
};
if(!getVar('icy_ali_customer','')) {
putVar('icy_ali_customer', customerSettingPath)
}
if(!getVar('icy_ali_tokenPath','')) {
putVar('icy_ali_tokenPath', tokenPath)
}
if(!getVar('icy_ali_setting','')) {
putVar('icy_ali_setting', settingPath)
}
},
manualLogin: function(key){
const { customerSettingPath} = this.urls;
let activeModel = this.activeModel();
const haveCustomerSetting = fileExist(customerSettingPath) == 'true' || fileExist(customerSettingPath) == true;
if(haveCustomerSetting) {
const customerSetting = JSON.parse(fetch(getVar('icy_ali_customer')));
if(customerSetting.customerResouce) {
activeModel = customerSetting.customerResouce.find(item => item.key == activeModel.key) || activeModel;
}
} else {
this.getConfig();
}
var host = activeModel.val;
setPageTitle('资源站登录');
let d = [];
var js = $.toString((key)=> {
const tokenFunction = function () {
var cookie = null;
cookie = fy_bridge_app.getCookie(location.href);
if(cookie){
let customer_url = 'hiker://files/rules/icy/icy-ali-customer.json';
let customerSetting = JSON.parse(request(customer_url) || '[]');
let activeModel = customerSetting.customerResouce.find(item => item.key == key);
activeModel.cookie = cookie;
alert(cookie)
fy_bridge_app.writeFile(customer_url,JSON.stringify(customerSetting));
alert('COOKIE获取成功,请返回后刷新页面重试');
fy_bridge_app.back();
return;
}else{
alert('没有cookie')
}
}
var doButton = false
const insertFN = function() {
var loginButton = document.querySelector('#getCookie');
if(loginButton) {
if(!doButton) {
alert('登录完成后点击底部获取cookie按钮')
loginButton.addEventListener('click', tokenFunction);
doButton = true;
}
} else {
HTMLElement.prototype.appendHTML = function(html) {
var divTemp = document.createElement("div"), nodes = null
, fragment = document.createDocumentFragment();
divTemp.innerHTML = html;
nodes = divTemp.childNodes;
for (var i=0, length=nodes.length; i<length; i+=1) {
fragment.appendChild(nodes[i].cloneNode(true));
}
this.appendChild(fragment);
nodes = null;
fragment = null;
};
document.body.appendHTML(`<div style="
position: fixed;
z-index: 10000;
height: 50px;
bottom: 0;
width: 100%;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
"><button id="getCookie" style="
background: #67C23A;
border: 0;
border-radius: 10px;
line-height: 40px;
padding: 0 20px;
min-width: 200px;
color: #fff;
">获取cookie</button></div>`);
token_timer();
}
}
var token_timer= function(){
setTimeout(insertFN, 1000)
};
insertFN();
document.onreadystatechange = function() {
if(document.readyState == 'complete') {
token_timer();
insertFN();
}
}
}, key)
d.push({
url: host,
col_type: 'x5_webview_single',
desc: '100%&&float',
extra: {
canBack: true,
js: js,
}
})
setHomeResult({
data: d
})
},
login: function (key){
const { customerSettingPath} = this.urls;
let activeModel = this.activeModel();
const haveCustomerSetting = fileExist(customerSettingPath) == 'true' || fileExist(customerSettingPath) == true;
if(haveCustomerSetting) {
const customerSetting = JSON.parse(fetch(getVar('icy_ali_customer')));
if(customerSetting.customerResouce) {
activeModel = customerSetting.customerResouce.find(item => item.key == activeModel.key) || activeModel;
}
} else {
this.getConfig();
}
const {username, password, val} = activeModel;
var host = val;
if(!username || !password) {
confirm({
title: '请设置用户名密码',
content: '输入对应的账号和密码!',
});
return false;
}
const pageResult = JSON.parse(fetch(host, {
headers: {'User-Agent': MOBILE_UA,},
withHeaders: true
}));
let cookie = pageResult.headers['set-cookie'].join(';');
const _token = pageResult.headers['x-csrf-token'].join(';');
cookie = cookie.split(';').filter(item => !item.includes('Path=') && !item.includes('Expires=') && !item.includes('Max-Age=') && !item.includes('SameSite=') && item.includes('=')).join(';')
const token = pageResult.body.match(/csrfToken":"([\w|\d]*)"/);
if(!token || !token[1] || !cookie) {
return false;
}
const login = JSON.parse(fetch(host + '/login', {
headers: {
"Content-Type": "application/json",
"User-Agent": MOBILE_UA,
"cookie": cookie,
"X-CSRF-Token": token[1],
},
method: 'POST',
body: '{"identification": "'+username+'","password": "'+password+'","remember":true}',
withHeaders: true
}));
if(login.body && login.body.includes('errors') && login.body.includes('not_authenticated')) {
confirm({
title: '登录失败',
content: '需要配置正确的账号和密码!',
});
activeModel.loginError = true;
} else if(login.headers['set-cookie'] && login.headers['set-cookie'].length) {
activeModel.loginError = false;
activeModel.cookie = login.headers['set-cookie'].join(';');
}
writeFile(customerSettingPath, JSON.stringify(customerSetting));
},
settingPage: function(key){
addListener('onClose', $.toString((params) => {
params.forEach(item => {
clearVar(item)
})
}, ["select_index", "login", "publicToken"]))
const {settingPath, customerSettingPath, tokenPath} = this.urls;
var d = [];
setPageTitle('设置');
const haveCustomerSetting = fileExist(customerSettingPath) == 'true' || fileExist(customerSettingPath) == true;
const haveToken = fileExist(tokenPath) == 'true' || fileExist(tokenPath) == true;
let customerSettings = null;
if(!getVar('icy_ali_customer','')) {
putVar('icy_ali_customer', customerSettingPath)
}
if(!haveCustomerSetting || (haveCustomerSetting && !JSON.parse(fetch(customerSettingPath)).customerResouce)) {
const customer = [];
const settings = JSON.parse(fetch(settingPath)).sort((a,b) => a.index - b.index);
settings.forEach(item => {
const config = {
name: item.name,
key: item.key,
index: item.index,
}
if(item.needKey) {
config.val = item.val;
config.needKey = item.needKey;
config.username = item.username;
config.password = item.password;
config.cookie = item.cookie;
}
customer.push(config)
})
customerSettings = {customerResouce:customer, usePublicToken: false, publicToken: '', useSuggestQuery: true, primaryColor: '#f47983', sourcePlay: false};
writeFile(getVar('icy_ali_customer'), JSON.stringify(customerSettings));
}
customerSettings = JSON.parse(fetch(getVar('icy_ali_customer')));
let primaryColor = customerSettings.primaryColor;
const customerResouce = customerSettings.customerResouce.sort((a,b) => a.index - b.index).map((item, index) => {item.index = index; return item;});
const loginList = customerResouce.filter(item => item.needKey).map(item => item.name);
const selectLoginName = getVar("login", '') || (customerResouce.find(item => item.key == key) ? customerResouce.find(item => item.key == key).name : getVar("login", ''));
const selectLogin = customerResouce.filter(item => item.needKey).find(item => item.name == selectLoginName);
d.push({
title: '💘 排序',
desc: '先点一个资源站,再点另外一个,会与目标对换位置',
url: this.emptyRule,
col_type: 'text_1'
})
const selectIndex = getVar('select_index', '');
customerResouce.forEach((item, index) => {
var name = item.name.includes(' ') ? item.name.split(' ')[1].trim() : item.name;
var title = String(index) === selectIndex ? "““””<b>"+'<span style="color: '+primaryColor+'">'+name+'</span></b>' : name;
d.push({
title: title,
url: $("#noLoading#").lazyRule((key, index, _customerSettings)=>{
const customerSettings = JSON.parse(JSON.stringify(_customerSettings));
var selectIndex = getVar('select_index', '');
if(!selectIndex) {
putVar('select_index', String(index));
refreshPage(false);
return "hiker://empty"
}
let source = null;
let source_index = null;
let target = customerSettings.customerResouce.find(item => item.key == key);
let targetIndex = customerSettings.customerResouce.findIndex(item => item.key == key);
if(selectIndex && selectIndex != index) {
source = customerSettings.customerResouce.find(item => item.index == selectIndex);
source_index = JSON.parse(JSON.stringify(source)).index;
target.index = source_index;
source.index = targetIndex;
}
writeFile(getVar('icy_ali_customer'), JSON.stringify(customerSettings));
putVar('select_index', '');
refreshPage(false);
return selectIndex != index ? 'toast://保存成功' : "hiker://empty";
}, item.key, index, customerSettings),
col_type: 'text_3'
})
})
d.push({
col_type: "line_blank"
});
d.push({
title: '🔍 海阔搜索设置 hiker://search',
desc: '默认为当前/排序第一的资源网站, 可以多选',
url: 'hiker://search',
col_type: 'text_1'
})
const activeModel = this.activeModel();
customerResouce.forEach(item => {
var name = item.name.includes(' ') ? item.name.split(' ')[1].trim() : item.name;
var title = (!!item.forHikerSearch) ? "““””<b>"+'<span style="color: '+ primaryColor +'">'+name+'</span></b>' : name;
d.push({
title: title,
url: $("#noLoading#").lazyRule((key, _customerSettings, activeModelKey)=>{
const customerSettings = JSON.parse(JSON.stringify(_customerSettings));
// if(key == activeModelKey && customerSettings.customerResouce.filter(item => item.forHikerSearch).length < 2) {
// return 'toast://这个是当前资源站,不能排除哦!';
// }
let target = customerSettings.customerResouce.find(item => item.key == key);
if(target) {
target.forHikerSearch = !target.forHikerSearch;
}
writeFile(getVar('icy_ali_customer'), JSON.stringify(customerSettings));
refreshPage(false);
return 'toast://保存成功';
}, item.key, customerSettings, (activeModel ? activeModel.key : '')),
col_type: 'text_3'
})
})
d.push({
col_type: "line_blank"
});
// const loginlazy = $(loginList, 2)
// .select(() => {
// putVar("login",input);
// refreshPage(false);
// });
// d.push({
// title: '🔓 资源网站登录设置',
// desc: (selectLoginName || '⛏️ 请选择资源网站') + ' ❗保存时会重置登录信息',
// url: loginlazy,
// col_type: 'text_1'
// })
// if(selectLogin) {
// d.push({
// title: "用户名",
// desc: "请输入用户名",
// col_type: 'input',
// extra: {
// titleVisible: false,
// defaultValue: selectLogin.username,
// type: '',
// onChange: 'putVar("' + selectLogin.key + '_username", input)'
// }
// })
// d.push({
// title: "密码",
// desc: "请输入密码",
// col_type: 'input',
// extra: {
// titleVisible: false,
// defaultValue: selectLogin.password,
// type: '',
// onChange: 'putVar("' + selectLogin.key + '_password", input)'
// }
// })
// d.push({
// title: '保存账号',
// col_type: 'text_center_1',
// url: $()
// .lazyRule((key, customerSettings) => {
// const item = customerSettings.customerResouce.find(item => item.key == key);
// item.username = getVar(key + '_username','');
// item.password = getVar(key + '_password','');
// item.loginError = false;
// item.cookie = '';
// writeFile(getVar('icy_ali_customer'), JSON.stringify(customerSettings));
// return 'toast://保存成功,需要返回刷新登录'
// }, selectLogin.key, customerSettings)
// })
// d.push({
// col_type: "blank_block"
// });
// d.push({
// title: '““””<small><span style="color:#4395FF;">资源站账号注册 >></span></small>',
// url: 'web://' + selectLogin.val,
// col_type: 'text_center_1'
// })
// }
// d.push({
// col_type: "line_blank"
// });
d.push({
title: '““””🔥 热门搜索词 <b><span style="color: '+ primaryColor +'">' + (customerSettings.useSuggestQuery ? '启用' : '不启用') + '</span></b>',
desc: '数据来源:360影视',
url: $("#noLoading#").lazyRule((useSuggestQuery, customerSettings)=>{
customerSettings.useSuggestQuery = !useSuggestQuery;