-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathhikerLibs.js
More file actions
1631 lines (1583 loc) · 59.7 KB
/
Copy pathhikerLibs.js
File metadata and controls
1631 lines (1583 loc) · 59.7 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
var updateLog = `
2022/08/24 增加一级通用函数
2022/08/23 增加翻页组件的足迹处理函数,分别为储存足迹(在二级监听返回函数用),加载足迹
2022/08/22 初步模块化
`.trim();
var version={
author:"道长",
ver:"1.0.2",
appv:2400,
requireId:"https://dr.playdreamer.cn/libs/hikerLibs.js",
update:'2022/08/24 11:16',
info:updateLog,
ua:';get;utf-8;{User-Agent@Mozilla/5.0&&Cookie@}',
ok:'https://okjx.cc/?url=',
jsRoot:'https://dr.playdreamer.cn/libs/',
};
function objectI18n(obj,i18n){//对象翻译
let new_obj = {};
for(let key in i18n){
new_obj[i18n[key]] = obj[key]
}
Object.assign(obj,new_obj);
}
function 初始化(){
log('初始化海阔视界道长组件库,引入全局函数中...');
$.extend({
依赖:version.requireId,
ejListPath: "hiker://files/cache/json/",
getList(key,defaultList){
defaultList = defaultList||[];
let code = fetch(this.ejListPath+key);
try {
let list = JSON.parse(code);
return Array.isArray(list) ? list :defaultList
}catch (e) {
log('获取列表发生了错误:'+e.message);
return defaultList
}
},
putList(key,list){
if(!Array.isArray(list)){
throw new Error('"list" must be list(json object) type');
}
writeFile(this.ejListPath+key,JSON.stringify(list));
},
readCache(key,defaultValue){
defaultValue = defaultValue||'';
let code = fetch(this.ejListPath+key);
return code||defaultValue
},
saveCache(key,value){
writeFile(this.ejListPath+key,value);
},
});
}
function color(text, color) {
text += "";
if (text.indexOf("““””") === 0) {
text.replace("““””", "");
}
return "““””<font color='" + color + "'>" + text + "</font>";
}
function htmlTag(tag, text) {
text += "";
if (text.indexOf("““””") === 0) {
text.replace("““””", "");
}
return "““””" + "<" + tag + ">" + text + "</" + tag + ">";
}
function small(text) {
return htmlTag("small", text);
}
function right(text) {
return '<span style="float:right">'+text+'</span>';
}
function blank(){
return '\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'
}
function addTb(html){//解决jsoup在table取值吞标签问题
return (/<td>/.test(html)&&/<\/td>/.test(html)&&!/<table>/.test(html))?('<table>'+html+'</table>'):html;
}
function getLazy(url,lazy) {//动态获取动态解析可兼容磁力链接
if ((typeof(lazy)==='undefined'||!lazy) && /^magnet:\?|^ftp:|^thunder:/.test(url.trim())) {//处理磁力
return ''
} else {
def_lazy = (typeof(def_lazy)==='undefined'||!def_lazy)?'':def_lazy;
return lazy || def_lazy
}
}
function 获取搜索链接(){
if(MY_URL.startsWith('hiker://empty##')){
var api = MY_RULE.url.replace('hiker://empty##','').split('#')[0].split('?')[0];
var host = getHome(api); // 获取域名
var sapi = MY_URL.replace("hiker://empty##","");//搜索接口
MY_URL=sapi.startsWith('http')?sapi:host+sapi;//看搜索接口是不是完整链接
}
log('搜索链接:'+MY_URL);
return MY_URL
}
function getCode(){//用于一级函数获取源码
let curl=MY_TYPE==='search'?获取搜索链接(MY_URL):MY_URL;
return /<\/html>/.test(getResCode())?getResCode():获取源码(curl)
}
function 获取源码(url,ua,referer,cookie,extraHeaders){//传url,ua和refer
url = url.replace('hiker://empty##','').split('#')[0];//获取源码自动去除占位的前缀
let def_ua = config.ua==='手机'?MOBILE_UA:PC_UA;
def_ua = config.指定ua?config.指定ua:def_ua;//如果传了指定ua给预处理,优先级更高,必须是ua字符串
ua = ua||def_ua;
extraHeaders = extraHeaders||{};
let headers = {
'User-Agent': ua
};
if(typeof(referer)!=='undefined'&&referer.length>4){
headers.Referer = referer
}
if(typeof(cookie)!=='undefined'&&cookie.length>4){
headers.Cookie = cookie
}else{
// 获取源码在接入下载管理跳到其他规则子页面可能会无法获取,需要在进去的时候处理
if(getMyVar('cookie','')){
headers.Cookie = getMyVar('cookie');
}
}
try{
Object.assign(headers, extraHeaders);//合并其他的请求头
// log(headers);
putMyVar('请求头',JSON.stringify(headers)); // 把这个放进去,为了后面方便打印的时候进行读取
let html = fetch(url, {
headers: headers
});
if (/\?btwaf=/.test(html)) {//宝塔验证
url=url.split('#')[0]+'?btwaf'+html.match(/btwaf(.*?)\"/)[1];
log("宝塔验证跳转到:"+url);
html = fetch(url, {
headers: headers
});
}
return html
}catch(e){
log('获取源码出错'+e.message);
return ''
}
}
var 工具 = {
color:color,//给文字增加颜色
htmlTag:htmlTag,//给文字增加html标签
small:small,//文字缩小
addTb:addTb,//添加表
right:right,//文字右对齐
blank:blank,//加空格
similar(s, t, f) {//判断两个字符串之间的相似度
if (!s || !t) {
return 0
}
if(s === t){
return 100;
}
var l = s.length > t.length ? s.length : t.length
var n = s.length
var m = t.length
var d = []
f = f || 2
var min = function (a, b, c) {
return a < b ? (a < c ? a : c) : (b < c ? b : c)
}
var i, j, si, tj, cost
if (n === 0) return m
if (m === 0) return n
for (i = 0; i <= n; i++) {
d[i] = []
d[i][0] = i
}
for (j = 0; j <= m; j++) {
d[0][j] = j
}
for (i = 1; i <= n; i++) {
si = s.charAt(i - 1)
for (j = 1; j <= m; j++) {
tj = t.charAt(j - 1)
if (si === tj) {
cost = 0
} else {
cost = 1
}
d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost)
}
}
let res = (1 - d[n][m] / l) *100
return res.toFixed(f)
},
ChineseMap:{
"零": 0, "一": 1, "壹": 1, "二": 2, "贰": 2, "两": 2, "三": 3, "叁": 3,
"四": 4, "肆": 4, "五": 5, "伍": 5, "六": 6, "陆": 6, "七": 7, "柒": 7,
"八": 8, "捌": 8, "九": 9, "玖": 9, "十": 10, "拾": 10, "百": 100, "佰": 100,
"千": 1000, "仟": 1000, "万": 10000, "十万": 100000, "百万": 1000000, "千万": 10000000, "亿": 100000000
},
ChineseToNumber(chinese_number){//中文转数字
let len = chinese_number.length;
if (len === 0) return -1;
if (len === 1) return (this.ChineseMap[chinese_number] <= 10) ? this.ChineseMap[chinese_number] : -1;
let summary = 0;
if (this.ChineseMap[chinese_number[0]] === 10) {
chinese_number = "一" + chinese_number;
len++;
}
if (len >= 3 && this.ChineseMap[chinese_number[len - 1]] < 10) {
let last_second_num = this.ChineseMap[chinese_number[len - 2]];
if (last_second_num === 100 || last_second_num === 1000 || last_second_num === 10000 || last_second_num === 100000000) {
for (let key in this.ChineseMap) {
if (this.ChineseMap[key] === last_second_num / 10) {
chinese_number += key;
len += key.length;
break;
}
}
}
}
if (chinese_number.match(/亿/g) && chinese_number.match(/亿/g).length > 1) return -1;
let splited = chinese_number.split("亿");
if (splited.length === 2) {
let rest = splited[1] === "" ? 0 : this.ChineseToNumber(splited[1]);
return summary + this.ChineseToNumber(splited[0]) * 100000000 + rest;
}
splited = chinese_number.split("万");
if (splited.length === 2) {
let rest = splited[1] === "" ? 0 : this.ChineseToNumber(splited[1]);
return summary + this.ChineseToNumber(splited[0]) * 10000 + rest;
}
let i = 0;
while (i < len) {
let first_char_num = this.ChineseMap[chinese_number[i]];
let second_char_num = this.ChineseMap[chinese_number[i + 1]];
if (second_char_num > 9)
summary += first_char_num * second_char_num;
i++;
if (i === len)
summary += first_char_num <= 9 ? first_char_num : 0;
}
return summary;
},
force_order(list,fn){//强制正序
fn = fn||function (list){//默认为视界的列表
return list.map(x=>x.title)
};
let start = Math.floor(list.length/2); // 0
let end = Math.min(list.length-1,start+1); // list.slice(-1)[0]
let listFn = fn(list);
let first = listFn[start];
let second = listFn[end];
try{
if(first.match(/(\d+)/)&&second.match(/(\d+)/)){ //数字章节的
if(parseInt(first.match(/(\d+)/)[0])>parseInt(second.match(/(\d+)/)[0])){
list.reverse()
}
}else{ // 中文转换
if(this.ChineseToNumber(first)>this.ChineseToNumber(second)){
list.reverse()
}
}
}catch(e){}
return list
},
sleep(timeout) {//延时
java.lang.Thread.sleep(timeout);
},
nameCompare(a, b) {//名称排序
if (a == null || b == null) {
return a == null ? b == null ? 0 : -1 : 1;
}
a = a.replace(/([零一壹二贰两三叁四肆五伍六陆七柒八捌九玖十拾百佰千仟万亿])/g, function(match, p1, p2, p3, offset, string) {
// p1 is nondigits, p2 digits, and p3 non-alphanumerics
return this.ChineseToNumber(p1);
});
b = b.replace(/([零一壹二贰两三叁四肆五伍六陆七柒八捌九玖十拾百佰千仟万亿])/g, function(match, p1, p2, p3, offset, string) {
// p1 is nondigits, p2 digits, and p3 non-alphanumerics
return this.ChineseToNumber(p1);
});
let NUMBERS = java.util.regex.Pattern.compile("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
let split1 = NUMBERS.split(new java.lang.String(a));
let split2 = NUMBERS.split(new java.lang.String(b));
for (let i = 0; i < Math.min(split1.length, split2.length); i++) {
let c1 = split1[i].charCodeAt(0);
let c2 = split2[i].charCodeAt(0);
let cmp = 0;
let zeroCharCode = '0'.charCodeAt(0);
let nineCharCode = '9'.charCodeAt(0);
if (c1 >= zeroCharCode && c1 <= nineCharCode && c2 >= zeroCharCode && c2 <= nineCharCode) {
cmp = new java.math.BigInteger(split1[i]).compareTo(new java.math.BigInteger(split2[i]));
}
if (cmp === 0) {
let regex = /[a-zA-Z0-9]/;
let s1 = String(split1[i]);
let s2 = String(split2[i]);
if (regex.test(s1) || regex.test(s2)) {
cmp = new java.lang.String(split1[i]).compareTo(new java.lang.String(split2[i]));
// cmp = s1.localeCompare(s2, 'en')
} else {
cmp = s1.localeCompare(s2, 'zh');
}
}
if (cmp !== 0) {
return cmp;
}
}
let lengthCmp = split1.length - split2.length;
// if (lengthCmp !== 0) lengthCmp = lengthCmp > 0 ? -1 : 1;
return lengthCmp;
},
isPic(str){//判断是否为图片
if(!str){
return false
}
return /\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(str);
},
blockRules:['baidu.*.png','.mp3', '.mp4', '.flv', '.avi', '.3gp', '.mpeg', '.wmv', '.mov', '.rmvb', '.gif', '.png', '.ico', '.svg'],
isVideo(playUrl,rechange){//判断是否为视频,是的话返回加料的视频链接
//注意.php不可以被排除否则融兴解析不了 |.php$
//如果是播放地址就直接返回地址加上UA,不是的话就返回false
// let t1 = new Date().getTime();
let cacheRegx = new RegExp('file:///storage/emulated/(.*?)\\.m3u8|hiker://files/(.*?)\\.m3u8');
if(cacheRegx.test(playUrl)){
return playUrl
}
function getHost(url){
// fba的parseLazy太慢了千万别用
try {
return url.match(/^http(s)?:\/\/(.*?)\//)[0].slice(0,-1);
}catch (e) {
return false
}
}
let pUrl=playUrl.split(";")[0];//获取抠掉海阔ua等参数的网页播放链接
let host = getHost(pUrl); // 获取域名
if(!host){//判断无域名直接不是视频
return false
}
function print(data){
if(typeof(log)==='undefined'){
return fba.log(data)
}else {
return log(data)
}
}
rechange=typeof(rechange)==="function"?rechange:function(playUrl){return playUrl};
// let exceptWords = '.js$|.css$|.ts$|.html$|.htm$|.gif$|.jpg$|.jpeg$|.png$|.ico$|.svg$|.txt$'.split('|').map(it=>'\\'+it).join('|');
// var exceptKeys = new RegExp(exceptWords);
var exceptKeys = /\.(js|css|ts|html|htm|gif|jpg|png|ico|svg|txt)$/;
// let exceptWords1 = 'referer=|url='.split('|').map(it=>it).join('|');
// var exceptKeys1 = new RegExp(exceptWords1);
var exceptKeys1 = /(referer|url)=/;
let replaceKeys = /playm3u8|m3u8\.tv/g;
let videoWords = "/video/tos|.mp4$|.m3u8$|.flv$|.avi$|.3gp$|.mpeg$|.wmv$|.mov$|rmvb|.dat$|.mp3$|.m4a$|qqBFdownload|mime=video%2F|mime_type=video_|type=m3u8|pt=m3u8".split('|').map((it)=>{
//type=mp4
if(it.startsWith(".")){
return '\\'+it
}else{
return it
}
}).join("|");
let videoKeys = new RegExp(videoWords);
let rUrl = pUrl.replace(host,'');//获取除开域名的剩余链接
let pUrl2=pUrl.split("&")[0].split("?")[0];//获取不带参数的网页链接
let rurl2 = pUrl2.replace(host,'');//获取除开域名的剩余不带参数链接
let hasKey = videoKeys.test(rUrl)||videoKeys.test(rurl2);
let parUrl = pUrl.replace(pUrl.split("?")[0],''); // 分割问号后剩余参数的完整链接
let excKey = exceptKeys1.test(parUrl);
if(rUrl.split('?').length>2){
let rUrl3=rUrl.split("?")[1];//获取?分割后的第一段
hasKey = hasKey||videoKeys.test(rUrl3);
}
if(hasKey&&!excKey){
let tips = '检测到疑似多媒体的地址:';
print("js中"+tips+pUrl);
print("分割问号后:"+parUrl);
}
if ((hasKey||videoKeys.test(rUrl.replace(replaceKeys,"").split("&")[0].split("?")[0]) )&& !exceptKeys.test(pUrl2)&&!exceptKeys1.test(pUrl2)) {
if(!(/User-Agent|Referer@/.test(playUrl))){
if(/lecloud\.com|bilivideo/.test(playUrl)){
playUrl+=";{Referer@https://www.bilibili.com/&&User-Agent@Mozilla/5.0}";
}else if(/ixigua\.com/.test(playUrl)){
playUrl+=";{Referer@https://www.ixigua.com/&&User-Agent@Mozilla/5.0}#isVideo=true#";
}
else if(/mgtv\.com|byteamone/.test(playUrl)){
playUrl+=";{User-Agent@Mozilla/5.0}";
}else if(/ptwo\.wkfile\.com/.test(playUrl)&&/url=/.test(playUrl)){
playUrl=playUrl.split("url=")[1]+";{Referer@https://fantuan.tv}"
}
}
playUrl=rechange(playUrl);
if(!/#isVideo=true#/.test(playUrl)){
playUrl+="#isVideo=true#";
}
return playUrl;
}else{
return false;
}
},
通免(_reChange){
// 嗅探链接再处理函数
_reChange = _reChange||false; // 必传,false
let lazy=$("").lazyRule((_reChange)=>{
const {lazyParse} = $.require('hiker://page/globalParse?rule=道长仓库Pro');
return lazyParse(input,null,null,_reChange);
},_reChange);
return lazy
},
bytesToSize(size) {//体积格式化
if (size < 0.1 * 1024) {
//小于0.1KB,则转化成B
size = size.toFixed(2) + "B";
} else if (size < 0.1 * 1024 * 1024) {
// 小于0.1MB,则转化成KB
size = (size / 1024).toFixed(2) + "KB";
} else if (size < 0.1 * 1024 * 1024 * 1024) {
// 小于0.1GB,则转化成MB
size = (size / (1024 * 1024)).toFixed(2) + "MB";
} else {
// 其他转化成GB
size = (size / (1024 * 1024 * 1024)).toFixed(2) + "GB";
}
// 转成字符串
let sizeStr = size + "",
// 获取小数点处的索引
index = sizeStr.indexOf("."),
// 获取小数点后两位的值
dou = sizeStr.substr(index + 1, 2);
// 判断后两位是否为00,如果是则删除00
if (dou === "00") return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2);
return size;
},
};
var 工具_翻译 = {
color:'颜色',
htmlTag:'标签',
small:'缩小',
right:'右对齐',
blank:'空格',
ChineseToNumber:'中文转数字',
force_order:'强制正序',
similar:'相似度',
sleep:'延时',
nameCompare:'名称对比',
isPic:'是否图片',
isVideo:'是否视频',
bytesToSize:'体积格式化',
addTb:'添加表',
};
objectI18n(工具,工具_翻译);
var 储存 = (function() {
//自定义
const KEYS = "daozhangyyds";
const PATH = "hiker://files/localStorage/StorageDz.local";
//核心代码勿动
const symbolSet = Object.freeze({
init: Symbol("init"),
save: Symbol("save"),
data: Symbol("data")
});
function LocalStorage(path) {
this.path = path;
this[symbolSet.data] = this[symbolSet.init]();
}
const LSPT = LocalStorage.prototype;
LSPT[symbolSet.save] = function(data) {
data = data || this[symbolSet.data];
if (data) {
writeFile(this.path, aesEncode(KEYS, JSON.stringify(data)));
} else {
throw new Error("data exception");
}
}
LSPT[symbolSet.init] = function() {
let plaintext = request(this.path);
try {
return JSON.parse(aesDecode(KEYS, plaintext));
} catch (e) {
this[symbolSet.save]({});
return {};
}
}
Object.assign(LSPT, {
constructor: LocalStorage,
setItem(key, value, expiredTimeMS) {
if (typeof key !== "string" || typeof value !== "string") {
throw new Error('"key" and "value" must be string type');
}
if ((expiredTimeMS === 0) || (expiredTimeMS == null)) {
this[symbolSet.data][key] = {
value: value
}
} else {
if (typeof expiredTimeMS !== "number") {
throw new Error('"expiredTime" must be number type');
}
this[symbolSet.data][key] = {
value: value,
est: new Date().getTime(),
etm: expiredTimeMS
}
}
this[symbolSet.save]();
},
getItem(key,value) {
value = value||'';
let item = this[symbolSet.data][key];
if (item === void 0) {
return value?value:undefined;
}
if (!item.est || !item.etm) {
return item.value;
}
let curTime = new Date().getTime();
let sum = item.est + item.etm;
if (sum > curTime) {
return item.value;
} else {
//this.removeItem(key);
//this[symbolSet.save]();
return null;
}
},
removeItem(key) {
this[symbolSet.data][key] = undefined;
this[symbolSet.save]();
},
hasItem(key) {
return this[symbolSet.data].hasOwnProperty(key);
},
isExpired(key) {
let item = this[symbolSet.data][key];
if (item === void 0) {
return true;
}
if (!item.est || !item.etm) {
return false;
}
let curTime = new Date().getTime();
let sum = item.est + item.etm;
return sum <= curTime;
},
expiredReset(key, expiredTimeMS) {
if (typeof key !== "string") {
throw new Error('"key" must be string type');
}
if (typeof expiredTimeMS !== "number") {
throw new Error('"expiredTime" must be number type');
}
let item = this[symbolSet.data][key];
if (item === void 0) {
throw new Error(key + " does not exist");
}
if ((expiredTimeMS === 0) || (expiredTimeMS == null)) {
this[symbolSet.data][key] = {
value: item.value
};
} else {
this[symbolSet.data][key] = {
value: item.value,
est: new Date().getTime(),
etm: expiredTimeMS
};
}
this[symbolSet.save]();
},
clear() {
this[symbolSet.data] = {};
this[symbolSet.save]();
}
});
return new LocalStorage(PATH);
})();
var lsg = 储存;
var 文件 = (function(){
const File = java.io.File;
const {
Files,
Paths,
StandardCopyOption,
StandardOpenOption
} = java.nio.file;
const javaString = java.lang.String;
let javaScope = new JavaImporter(java.io, java.lang, java.lang.reflect, java.util.Vector);
function deleteFiles(fileName) {
let file = new File(fileName);
if (!file.exists()) {
//log("删除文件失败:" + fileName + "文件不存在");
return false;
} else {
if (file.isFile()) {
return deleteFile(fileName);
} else {
return deleteDirectory(fileName);
}
}
}
/**
* 删除单个文件
*
* @param fileName
* 被删除文件的文件名
* @return 单个文件删除成功返回true,否则返回false
*/
function deleteFile(fileName) {
let file = new File(fileName);
if (file.isFile() && file.exists()) {
file.delete();
//log("删除单个文件" + fileName + "成功!");
return true;
} else {
//log("删除单个文件" + fileName + "失败!");
return false;
}
}
/**
* 删除目录(文件夹)以及目录下的文件
*
* @param dir
* 被删除目录的文件路径
* @return 目录删除成功返回true,否则返回false
*/
function deleteDirectory(dir) {
// 如果dir不以文件分隔符结尾,自动添加文件分隔符
if (!dir.endsWith(File.separator)) {
dir = dir + File.separator;
}
let dirFile = new File(dir);
// 如果dir对应的文件不存在,或者不是一个目录,则退出
if (!dirFile.exists() || !dirFile.isDirectory()) {
//log("删除目录失败" + dir + "目录不存在!");
return false;
}
let flag = true;
// 删除文件夹下的所有文件(包括子目录)
let files = dirFile.listFiles();
for (let i = 0; i < files.length; i++) {
// 删除子文件
if (files[i].isFile()) {
flag = deleteFile(files[i].getAbsolutePath());
if (!flag) {
break;
}
} else { // 删除子目录
flag = deleteDirectory(files[i].getAbsolutePath());
if (!flag) {
break;
}
}
}
if (!flag) {
//log("删除目录失败");
return false;
}
// 删除当前目录
if (dirFile.delete()) {
//log("删除目录" + dir + "成功!");
return true;
} else {
//log("删除目录" + dir + "失败!");
return false;
}
}
//copy单个文件
function copyFile(source, target, isCover){
let sourcePath = Paths.get(source);
let targetPath = Paths.get(target);
let isExist = Files.exists(targetPath);
if(Files.isDirectory(sourcePath)||(isExist&&!isCover)||(isExist&&Files.isDirectory(targetPath))){
return false;
}
try{
if(!isExist){
Files.createDirectories(targetPath.getParent());
}
if(isCover === true){
Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
return true;
} else {
Files.copy(sourcePath, targetPath, StandardCopyOption.COPY_ATTRIBUTES);
return true;
}
} catch(e) {
return false;
}
}
/**
*
* @param source 源文件夹
* @param target 目标文件夹
* @param pattern 0:格式化目标文件夹在复制 1:不格式化但覆盖目标文件夹里重复的文件 2:跳过已经有的文件
* @returns {boolean|*|boolean}
*/
function copyDirs(source, target, pattern){
pattern = pattern || 0;
let sourceDir = new File(source);
let targetDir = new File(target);
if(pattern === 0&&targetDir.exists()&&targetDir.isDirectory()){
if(!deleteFiles(target)) return false;
}
if(targetDir.isFile()&&targetDir.exists()){
if(pattern === 0){
if(!deleteFiles(target)) return false;
}else{
return false;
}
}
let copy;
if(pattern===0||pattern===1){
copy=(source, target)=>copyFile(source, target, true);
}else if(pattern===2){
copy=(source, target)=>copyFile(source, target, false);
}else{
return false;
}
return copyDir(sourceDir, targetDir, copy);
}
function copyDir(sourceDir, targetDir, copy){
let files = sourceDir.listFiles();
if(files == null) return false;
for(let file of files){
let file1 = new File(targetDir, file.getName());
if(file.isFile()){
return copy(file.toString(),file1.toString());
} else {
file1.mkdir();
return copyDir(file,file1, copy);
}
}
}
function forEachs(options){
let v = Object.assign({
baseDir: "",
targetDepth: 5,
isIgnoreDir: true,
callback: null
}, options);
if(!v.baseDir || typeof v.callback!=="function"){
throw new Error("参数错误");
}
v.baseDir=new File(v.baseDir);
forEach(v.baseDir,v.targetDepth,v.isIgnoreDir,v.callback);
}
function forEach(baseDir, targetDepth, isIgnoreDir, callback, depth) {
depth = depth || 0;
if (!baseDir.exists() || !baseDir.isDirectory() || depth >= targetDepth) {
return;
}
let files = baseDir.listFiles();
if(files == null){
return;
}
for (let file of files) {
let isDirectory = file.isDirectory();
if ((!isIgnoreDir&&isDirectory)||!isDirectory) {
callback({
name: String(file.getName()),
path: String(file.getPath()),
isDirectory: isDirectory
});
}
if (isDirectory) {
forEach(file, targetDepth, isIgnoreDir, callback, depth + 1);
}
}
}
function getFileTime(path) {
let file = new File(path);
let lastModified = file.lastModified();
let date = new Date(lastModified);
return date.getTime();
}
function getName(path) {
return new File(path).getName() + "";
}
function getFilePath(path, type, expand) {
type = type || "file";
if (!["file", "dir"].includes(type)) throw new Error("类型错误");
let fileType = type === "file" ? "isFile" : "isDirectory";
let file = new File(path);
let array = file.listFiles() || [];
let pathList = [];
for (let i = 0; i < array.length; i++) {
if (array[i][fileType]()) {
pathList.push({
name: array[i].getName() + "",
path: array[i].getPath() + ""
});
}
}
if (expand) {
pathList = pathList.filter(it => it.name.endsWith(expand));
}
return pathList;
}
function renameFile(fromPath, name, isCover) {
isCover=isCover||false;
let fromFile = new File(fromPath);
let toFile = new File(fromFile.getParent() + "/" + name);
try {
if (!fromFile.exists()) {
return false;
}
if(String(fromFile.toString())===String(toFile.toString())){
return false;
}
if (toFile.exists()) {
if (isCover&&!deleteFiles(toPath)) {
return false;
} else if(!isCover){
return false;
}
}
Files.move(fromFile.toPath(), toFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
return toFile.toString();
} catch (e) {
log(e.toString());
return false;
}
}
function moveFiles(fromPath, toPath) {
let fromFile = new File(fromPath);
let toFile = new File(toPath);
try {
if (!fromFile.exists()) {
return false;
}
if (toFile.exists()) {
if (!deleteFiles(toPath)) {
return false;
}
}
Files.move(fromFile.toPath(), toFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
return true;
} catch (e) {
log(e.toString());
return false;
}
}
function fileWrite(path, content) {
writeFile("file://" + path, content)
}
function fileWriteAppend(path, content) {
let file = new File(path);
let paths = file.toPath();
if (file.exists()) {
Files.write(paths, new javaString(content).getBytes(), StandardOpenOption.APPEND);
} else {
writeFile("file://" + path, content);
}
}
function getTotalSizeOfFilesInDir(file) {
if (file.isFile()) {
return file.length();
}
let children = file.listFiles();
let total = 0;
if (children != null) {
for (let child of children) {
total += getTotalSizeOfFilesInDir(child);
}
}
return total;
}
function getFileSize(filePath) {
//Byte
let size = getTotalSizeOfFilesInDir(new File(filePath));
if (size < 0) {
return null;
}
let unitForm = ["Byte", "KB", "MB", "GB", "TB"];
for (let i = 0, len = unitForm.length; i < len; i++) {
if (size > 1024) {
size /= 1024;
continue;
} else {
return Math.ceil(size) + unitForm[i];
}
}
return "ERROR:数值过大";
}
function fileRule(filesInput, fileOut, intercept) {
with(javaScope) {
const BUFFER_SIZE = 0x300000;
let tmpFile = new File(filesInput);
if(!(tmpFile.exists()&&tmpFile.isFile())){
return false;
}
let outFile = new File(fileOut);
let tis = new FileInputStream(tmpFile);
let os = new BufferedOutputStream(new FileOutputStream(outFile));
let len = 0;
let bys = Array.newInstance(Byte.TYPE, BUFFER_SIZE);
while ((len = tis.read(bys)) != -1) {
let nbys = intercept(new String(bys,0,len));
os.write(nbys, 0, nbys.length);
}
tmpFile.delete();
tis.close();
os.close();
return true;
}
}
/**
* 获取文件后缀
* @param originalFilename 原文件名/文件路径
* @returns {string}
*/
function getExtension(originalFilename) {
originalFilename = String(originalFilename).trim();
let i = originalFilename.lastIndexOf(".");
if (i === -1) {
return "";
}
let suffix = originalFilename.substring(i);
return suffix.toLowerCase();
}
return {
getExtension: (path) => getExtension(path),
getFileTime: (path) => getFileTime(path),
getFilePath: (path, type, expand) => getFilePath(path, type, expand),
deleteFiles: (path) => deleteFiles(path),
renameFile: (path, name, isCover) => renameFile(path, name, isCover),
moveFiles: (fromPath, toPath) => moveFiles(fromPath, toPath),
fileWrite: (path, content) => fileWrite(path, content),
fileWriteAppend: (path, content) => fileWriteAppend(path, content),
getName: (path) => getName(path),
getFileSize: (filePath) => getFileSize(filePath),
fileRule: (filesInput, fileOut, intercept) => fileRule(filesInput, fileOut, intercept),
copyFile: (source, target, isCover) => copyFile(source, target, isCover),
copyDirs: (source, target, pattern) => copyDirs(source, target, pattern),
forEachs: (options) => forEachs(options)
}
})();
var 组件 = {
一级传参(d,obj){
let def_obj = {
noRef:false,//图片不用referer
noCj:false,//不用沉浸
}
obj = obj||{};
obj = Object.assign(def_obj,obj);
d.forEach((it)=>{
if(!obj.noRef&&工具.isPic(it.pic_url)&&!/@Referer=/.test(it.pic_url)){
it.pic_url+='@Referer=';
}
if(!obj.noRef&&工具.isPic(it.img)&&!/@Referer=/.test(it.img)){
it.img+='@Referer=';
}
if(!obj.noCj&&!/#immersiveTheme#/.test(it.url)&&!/@lazyRule=|@rule=/.test(it.url)){//加上沉浸
it.url+='#immersiveTheme#';
}
if(!it.extra){
it.extra = {};
}
it.extra.url = it.url||'';
it.extra.pic_url = (it.pic_url||it.img)||'';
it.extra.title = it.title||'';
it.extra.desc = it.desc||'';
it.extra.content = it.content||'';
});
return d