forked from swsoyee/psnine-enhanced-version
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsnineplus.js
4269 lines (4119 loc) · 181 KB
/
psnineplus.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
/* eslint-disable max-len */
// ==UserScript==
// @name PSN中文网功能增强
// @namespace https://swsoyee.github.io
// @version 1.0.29
// @description 数折价格走势图,显示人民币价格,奖杯统计和筛选,发帖字数统计和即时预览,楼主高亮,自动翻页,屏蔽黑名单用户发言,被@用户的发言内容显示等多项功能优化P9体验
// eslint-disable-next-line max-len
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAMFBMVEVHcEw0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNuEOyNSAAAAD3RSTlMAQMAQ4PCApCBQcDBg0JD74B98AAABN0lEQVRIx+2WQRaDIAxECSACWLn/bdsCIkNQ2XXT2bTyHEx+glGIv4STU3KNRccp6dNh4qTM4VDLrGVRxbLGaa3ZQSVQulVJl5JFlh3cLdNyk/xe2IXz4DqYLhZ4mWtHd4/SLY/QQwKmWmGcmUfHb4O1mu8BIPGw4Hg1TEvySQGWoBcItgxndmsbhtJd6baukIKnt525W4anygNECVc1UD8uVbRNbumZNl6UmkagHeRJfX0BdM5NXgA+ZKESpiJ9tRFftZEvue2cS6cKOrGk/IOLTLUcaXuZHrZDq3FB2IonOBCHIy8Bs1Zzo1MxVH+m8fQ+nFeCQM3MWwEsWsy8e8Di7meA5Bb5MDYCt4SnUbP3lv1xOuWuOi3j5kJ5tPiZKahbi54anNRaaG7YElFKQBHR/9PjN3oD6fkt9WKF9rgAAAAASUVORK5CYII=
// @author InfinityLoop, mordom0404, Nathaniel_Wu, JayusTree
// @include *psnine.com/*
// @include *d7vg.com/*
// @require http://libs.baidu.com/jquery/2.1.4/jquery.min.js
// @require https://code.highcharts.com/11.1.0/highcharts.js
// @require https://code.highcharts.com/11.1.0/modules/histogram-bellcurve.js
// @require https://unpkg.com/tippy.js@3/dist/tippy.all.min.js
// @license MIT
// @supportURL https://github.com/swsoyee/psnine-night-mode-CSS/issues/new
// @compatible chrome
// @compatible firefox
// @compatible edge
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-start
// ==/UserScript==
/* globals $, Highcharts, tippy, GM_getValue, GM_setValue */
(function () {
const settings = {
// 功能0-3设置:鼠标滑过黑条即可显示内容
hoverUnmark: true, // 设置为false则选中才显示
// 功能0-5设置:是否开启自动签到
autoCheckIn: true,
// 功能0-6: 自动翻页
autoPaging: 0, // 自动往后翻的页数
// 功能0-7:个人主页下显示所有游戏
autoPagingInHomepage: true,
// 功能1-4:回复内容回溯
replyTraceback: true,
// 功能1-1设置:高亮发帖楼主功能
highlightBack: '#3890ff', // 高亮背景色
highlightFront: '#ffffff', // 高亮字体颜色
// 功能1-2设置:高亮具体ID功能(默认管理员id)
// 注:此部分功能源于@mordom0404的P9工具包:
// https://greasyfork.org/zh-CN/scripts/29343-p9%E5%B7%A5%E5%85%B7%E5%8C%85
highlightSpecificID: ['mechille', 'sai8808', 'jimmyleo', 'jimmyleohk', 'monica_zjl', 'yinssk'], // 需要高亮的ID数组
highlightSpecificBack: '#d9534f', // 高亮背景色
highlightSpecificFront: '#ffffff', // 高亮字体颜色
// 功能1-6设置:屏蔽黑名单中的用户发言内容
blockList: [], // 请在左侧输入用户ID,用逗号进行分割,如: ['use_a', 'user_b', 'user_c'] 以此类推
// 屏蔽词,
blockWordsList: [],
// 问答页面状态UI优化
newQaStatus: true,
// 功能1-11设置:鼠标悬浮于头像显示个人奖杯卡
hoverHomepage: true,
// 功能4-3设置:汇总以获得和未获得奖杯是否默认折叠
foldTrophySummary: false, // true则默认折叠,false则默认展开
// 功能5-1设置:是否在`游戏`页面启用降低无白金游戏的图标透明度
filterNonePlatinumAlpha: 0.2, // 透密 [0, 1] 不透明,如果设置为1则关闭该功能
// 设置热门标签阈值
hotTagThreshold: 20,
// 夜间模式
nightMode: false,
// 自动夜间模式
autoNightMode: {
value: 'SYSTEM',
enum: ['SYSTEM', 'TIME', 'OFF'], // options in settings panel have to be in the same order
},
// 约战页面去掉发起人头像
removeHeaderInBattle: false,
// 机因、问答页面按最新排序
listPostsByNew: false,
// 载入全部问答答案
showAllQAAnswers: false,
// 答案按最新排列
listQAAnswersByNew: false,
// 答案显示隐藏回复
showHiddenQASubReply: false,
// 检测纯文本中的链接
fixTextLinks: true,
// 修复D7VG链接
fixD7VGLinks: true,
// 站内使用HTTPS链接
fixHTTPLinks: false,
// 尝试关联不同版本的游戏
referGameVariants: true,
// 查询游戏版本优先使用搜索
preferSearchForFindingVariants: false,
// 展开隐藏的子评论
expandCollapsedSubcomments: true,
// 约战页面显示相关游戏个人游戏进度
showGameProgressInBattle: true,
// 约战缓存更新时间
BattleInfoUpdateInterval: 60 * 60 * 1000,
};
if (window.localStorage) {
if (window.localStorage['psnine-night-mode-CSS-settings']) {
const localSettings = JSON.parse(window.localStorage['psnine-night-mode-CSS-settings']);
let settingTypeUpdated = false;
Object.keys(settings).forEach((key) => {
if (typeof settings[key] !== typeof localSettings[key]) {
localSettings[key] = settings[key];
settingTypeUpdated = true;
}
});
$.extend(settings, localSettings); // 用storage中的配置项覆盖默认设置
if (settingTypeUpdated) localStorage['psnine-night-mode-CSS-settings'] = JSON.stringify(localSettings);
}
} else {
console.log('浏览器不支持localStorage,使用默认配置项');
}
// 获取自己的PSN ID
const psnidCookie = document.cookie.match(/__Psnine_psnid=(\w+);/);
// 全局优化
function onDocumentStart() { // run before anything is downloaded
// 站内使用HTTPS链接
if (settings.fixHTTPLinks && /^http:\/\//.test(window.location.href)) window.location.href = window.location.href.replace('http://', 'https://');
// 机因、问答页面按最新排序
if (settings.listPostsByNew && /\/((gene)|(qa))($|(\/$))/.test(window.location.href)) {
window.location.href += '?ob=date';
}
// 功能0-2:夜间模式
const toggleNightMode = () => {
if (settings.nightMode) {
const node = document.createElement('style');
node.id = 'nightModeStyle';
node.type = 'text/css';
node.appendChild(document.createTextNode(`
li[style="background:#f5faec"]{background:#344836 !important;}li[style="background:#fdf7f7"]{background:#4f3945 !important;}li[style="background:#faf8f0"]{background:#4e4c39 !important;}li[style="background:#f4f8fa"]{background:#505050 !important;}span[style="color:blue;"]{color:#64a5ff !important;}span[style="color:red;"],span[style="color:#a10000"]{color:#ff6464 !important;}span[style="color:brown;"]{color:#ff8864 !important;}.tit3{color:white !important;}.mark{background:#bbb !important;color:#bbb;}body.bg{background:#2b2b2b !important;}.list li,.box .post,td,th{border-bottom:1px solid #555;}.list li:nth-last-child(1),th:nth-last-child(1){border-bottom:none;}.psnnode{background:#656565;}.box{background:#3d3d3d !important;}.title a{color:#bbb;}.text-strong,strong,.storeinfo,.content{color:#bbb !important;}.alert-warning,.alert-error,.alert-success,.alert-info{background:#4b4b4b !important;}.alert-error{color:#ec6666;}.text-error{color:#ec6666 !important;}h1,.title2{color:#ffffff !important;}.twoge{color:#ffffff !important;}.inav{background:#3d3d3d !important;}.inav li.current{background:#4b4b4b !important;}.ml100 p{color:#ffffff !important;}.t1{background:#657caf !important;}.t2{background:#845e2f !important;}.t3{background:#707070 !important;}.t4{background:#8b4d2d !important;}blockquote{background:#bababa !important;}.text-gray{color:#bbb !important;}.tradelist li{color:white !important;border-bottom:1px solid #666;}.tbl{background:#3c3c3c !important;}.genelist li:hover,.touchclick:hover{background:#333 !important;}.showbar{background:radial-gradient(at center top,#7B8492,#3c3c3c);}.darklist,.cloud{background-color:#3c3c3c;}.side .hd3,.header,.dropdown ul{background-color:#222;}.list li .sonlist li{background-color:#333;border-color:#555;}.node{background-color:#3b4861;}.rep{background-color:#3b4861;}.btn-gray{background-color:#666;}.btn-white{background-color:#444;color:#999 !important;}.dropmenu .o_btn{margin-right:0;color:#bbb;border-color:#bbb;}.dropmenu .o_btn.select{margin-right:0;color:#fff;border-color:#3498db;background-color:#3498db;}.tipContainer > .list{box-shadow:rgba(0,0,0,0.2) 0px 0px 100px inset !important;}.replyTraceback{background:rgba(0,0,0,0.2) !important;}.sidetitle{background:#222;}form[method="POST"]{color:#999;}
`));
const heads = document.getElementsByTagName('head');
if (heads.length > 0) {
heads[0].appendChild(node);
} else { // no head yet, stick it whereever
document.documentElement.appendChild(node);
}
} else {
$('#nightModeStyle').remove();
}
};
const setNightMode = (isOn) => {
settings.nightMode = isOn;
toggleNightMode();
};
switch (settings.autoNightMode.value) {
case 'SYSTEM':
if (window.matchMedia) { // if the browser/os supports system-level color scheme
setNightMode(window.matchMedia('(prefers-color-scheme: dark)').matches);
const darkThemeQuery = window.matchMedia('(prefers-color-scheme: dark)');
if (darkThemeQuery.addEventListener) darkThemeQuery.addEventListener('change', (e) => setNightMode(e.matches));
else darkThemeQuery.addListener((e) => setNightMode(e.matches)); // deprecated
break;
}
// eslint-disable-next-line no-fallthrough
case 'TIME': {
const hour = (new Date()).getHours();
setNightMode(hour > 18 || hour < 7);// TODO: time selector in settings panel
break;
}
default:
toggleNightMode();
}
/*
* 功能:黑条文字鼠标悬浮显示
* param: isOn 是否开启功能
*/
const showMarkMessage = (isOn) => {
if (isOn) {
$(document).on('mouseenter', '.mark', function () {
$(this).css({ color: settings.nightMode ? 'rgb(0,0,0)' : 'rgb(255,255,255)' });
});
$(document).on('mouseleave', '.mark', function () {
$(this).css({ color: '' });
});
}
};
showMarkMessage(settings.hoverUnmark);
}
onDocumentStart();
function onDOMContentReady() { // run when DOM is loaded
let numberOfHttpCSS = 0;
let numberOfHttpsCSSLoaded = 0;
const httpCSSFixed = () => numberOfHttpsCSSLoaded === numberOfHttpCSS;
const fixLinksOnThePage = () => {
// 检测纯文本中的链接
const duplicatedSchemeRegex1 = /((href|src)=")((https?:\/\/)+)/g;
const duplicatedSchemeRegex2 = /(<a( [^<]+?)?>)((https?:\/\/)+)/g;
const untaggedUrlRegex = /(?<!((href|src)="|<a( [^<]+?)?>))(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([A-Za-z0-9\-._~:/?#[\]@!$&'()*+,;=%]*))(?!("|<\/a>))/g;// https://stackoverflow.com/a/3809435 & https://stackoverflow.com/a/1547940
const fixTextLinksOnThePage = (isOn) => {
if (isOn && /(\/(topic|gene|qa|battle|trade)\/\d+)|(\/psnid\/.+?\/comment)|(\/my\/notice)|(\/psngame\/\d+\/comment)|(\/trophy\/\d+)/.test(window.location.href)) $('div.content').each((i, e) => { e.innerHTML = e.innerHTML.replace(duplicatedSchemeRegex1, '$1$4').replace(duplicatedSchemeRegex2, '$1$4').replace(untaggedUrlRegex, '<a href="$4" target="_blank">$4</a>'); });
};
// 修复D7VG链接
const linkReplace = (link, substr, newSubstr) => {
if (link.href) {
link.href = (link.href === link.innerText)
? (link.innerText = link.innerText.replace(substr, newSubstr))
: link.href.replace(substr, newSubstr);
} else if (link.src) link.src = link.src.replace(substr, newSubstr);
};
const fixD7VGLinksOnThePage = (isOn) => {
if (isOn) {
$("a[href*='//d7vg.com'], a[href*='//www.d7vg.com']").each((i, a) => {
if (!/d7vg\.com($|\/$)/.test(a.href)) { // 排除可能特意指向d7vg.com的链接
linkReplace(a, 'd7vg.com', 'psnine.com');
}
});
}
};
// 站内使用HTTPS链接
const fixHTTPLinksOnThePage = (isOn) => {
if (isOn) {
const httpCSS = $("link[href*='http://psnine.com'], link[href*='http://www.psnine.com']");
numberOfHttpCSS = httpCSS.length;
httpCSS.each((i, l) => {
const replacement = document.createElement('link');
replacement.addEventListener('load', () => { numberOfHttpsCSSLoaded += 1; }, false);
replacement.type = 'text/css';
replacement.rel = 'stylesheet';
replacement.href = l.href.replace('http://', 'https://');
l.remove();
document.head.appendChild(replacement);
});
$("a[href*='http://psnine.com'], a[href*='http://www.psnine.com'], img[src*='http://psnine.com'], img[src*='http://www.psnine.com'], iframe[src*='http://player.bilibili.com']").each((i, a) => linkReplace(a, 'http://', 'https://'));
const scriptSources = [];
$("script[src*='http://psnine.com'], script[src*='http://www.psnine.com']").each((i, s) => {
scriptSources.push(s.src.replace('http://', 'https://'));
s.remove();
});
$('head').find('script').each((i, s) => {
if (/^\s*var u\s*=\s*'http:\/\/(www\.)?psnine\.com';\s*$/.test(s.text)) {
s.remove();
const replacement = document.createElement('script');
replacement.type = 'text/javascript';
replacement.text = `var u = '${window.location.href.match(/^.+?\.com/)[0]}'`;
document.head.appendChild(replacement);
return false;
}
return true;
});
const scripts = [];
scriptSources.forEach((src) => {
$.ajax({ method: 'GET', dataType: 'text', url: src }).then((data) => {
const replacement = document.createElement('script');
replacement.type = 'text/javascript';
replacement.text = data;
scripts.push({
source: src,
script: replacement,
});
if (scripts.length === scriptSources.length) {
scriptSources.forEach((originalSrc) => {
const index = scripts.findIndex((s) => originalSrc.replace('http://', 'https://') === s.source);
document.head.appendChild(scripts[index].script);
scripts.splice(index, 1);
});
}
});
});
}
};
fixTextLinksOnThePage(settings.fixTextLinks);
fixD7VGLinksOnThePage(settings.fixD7VGLinks);
fixHTTPLinksOnThePage(settings.fixHTTPLinks);
};
fixLinksOnThePage();
Highcharts.setOptions({
lang: {
contextButtonTitle: '图表导出菜单',
decimalPoint: '.',
downloadJPEG: '下载JPEG图片',
downloadPDF: '下载PDF文件',
downloadPNG: '下载PNG文件',
downloadSVG: '下载SVG文件',
drillUpText: '返回 {series.name}',
loading: '加载中',
months: [
'一月',
'二月',
'三月',
'四月',
'五月',
'六月',
'七月',
'八月',
'九月',
'十月',
'十一月',
'十二月',
],
noData: '没有数据',
numericSymbols: ['千', '兆', 'G', 'T', 'P', 'E'],
printChart: '打印图表',
resetZoom: '恢复缩放',
resetZoomTitle: '恢复图表',
shortMonths: [
'1月',
'2月',
'3月',
'4月',
'5月',
'6月',
'7月',
'8月',
'9月',
'10月',
'11月',
'12月',
],
thousandsSep: ',',
weekdays: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
},
});
// 暴力猴中已经删掉了GM_addStyle函数,因此需要自己定义
// eslint-disable-next-line camelcase
function GM_addStyle(css) {
const style = document.getElementById('GM_addStyleBy8626') || (function () {
// eslint-disable-next-line no-shadow
const style = document.createElement('style');
style.type = 'text/css';
style.id = 'GM_addStyleBy8626';
document.head.appendChild(style);
return style;
}());
const { sheet } = style;
sheet.insertRule(css, (sheet.rules || sheet.cssRules || []).length);
}
// 增加图标
GM_addStyle(`
.fa-check-circle {
width: 15px; height: 15px;
float: left;
margin-top: 3px;
margin-right: 3px;
background: url('data:image/svg+xml;utf8,<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="check-circle" class="svg-inline--fa fa-check-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="%23659f13" d="M504 256c0 136.967-111.033 248-248 248S8 392.967 8 256 119.033 8 256 8s248 111.033 248 248zM227.314 387.314l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.249-16.379-6.249-22.628 0L216 308.118l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.249 16.379 6.249 22.628.001z"></path></svg>') no-repeat center;
}`);
GM_addStyle(`
.fa-question-circle {
width: 15px; height: 15px;
float: left;
margin-top: 3px;
margin-right: 3px;
background: url('data:image/svg+xml;utf8,<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="question-circle" class="svg-inline--fa fa-question-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="%23c09853" d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zM262.655 90c-54.497 0-89.255 22.957-116.549 63.758-3.536 5.286-2.353 12.415 2.715 16.258l34.699 26.31c5.205 3.947 12.621 3.008 16.665-2.122 17.864-22.658 30.113-35.797 57.303-35.797 20.429 0 45.698 13.148 45.698 32.958 0 14.976-12.363 22.667-32.534 33.976C247.128 238.528 216 254.941 216 296v4c0 6.627 5.373 12 12 12h56c6.627 0 12-5.373 12-12v-1.333c0-28.462 83.186-29.647 83.186-106.667 0-58.002-60.165-102-116.531-102zM256 338c-25.365 0-46 20.635-46 46 0 25.364 20.635 46 46 46s46-20.636 46-46c0-25.365-20.635-46-46-46z"></path></svg>') no-repeat center;
}`);
GM_addStyle(`
.fa-comments {
width: 15px; height: 15px;
float: left;
margin-top: 3px;
margin-right: 3px;
background: url('data:image/svg+xml;utf8,<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="comments" class="svg-inline--fa fa-comments fa-w-18" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="%233a87ad" d="M416 192c0-88.4-93.1-160-208-160S0 103.6 0 192c0 34.3 14.1 65.9 38 92-13.4 30.2-35.5 54.2-35.8 54.5-2.2 2.3-2.8 5.7-1.5 8.7S4.8 352 8 352c36.6 0 66.9-12.3 88.7-25 32.2 15.7 70.3 25 111.3 25 114.9 0 208-71.6 208-160zm122 220c23.9-26 38-57.7 38-92 0-66.9-53.5-124.2-129.3-148.1.9 6.6 1.3 13.3 1.3 20.1 0 105.9-107.7 192-240 192-10.8 0-21.3-.8-31.7-1.9C207.8 439.6 281.8 480 368 480c41 0 79.1-9.2 111.3-25 21.8 12.7 52.1 25 88.7 25 3.2 0 6.1-1.9 7.3-4.8 1.3-2.9.7-6.3-1.5-8.7-.3-.3-22.4-24.2-35.8-54.5z"></path></svg>') no-repeat center;
}`);
GM_addStyle(`
.fa-coins {
width: 15px; height: 15px;
float: left;
background: url('data:image/svg+xml;utf8,<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="coins" class="svg-inline--fa fa-coins fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="%23bf6a3a" d="M0 405.3V448c0 35.3 86 64 192 64s192-28.7 192-64v-42.7C342.7 434.4 267.2 448 192 448S41.3 434.4 0 405.3zM320 128c106 0 192-28.7 192-64S426 0 320 0 128 28.7 128 64s86 64 192 64zM0 300.4V352c0 35.3 86 64 192 64s192-28.7 192-64v-51.6c-41.3 34-116.9 51.6-192 51.6S41.3 334.4 0 300.4zm416 11c57.3-11.1 96-31.7 96-55.4v-42.7c-23.2 16.4-57.3 27.6-96 34.5v63.6zM192 160C86 160 0 195.8 0 240s86 80 192 80 192-35.8 192-80-86-80-192-80zm219.3 56.3c60-10.8 100.7-32 100.7-56.3v-42.7c-35.5 25.1-96.5 38.6-160.7 41.8 29.5 14.3 51.2 33.5 60 57.2z"></path></svg>') no-repeat center;
}`);
// 修复PSPC平台图标显示(临时)
const fixPspcIcon = () => {
let pspcIconFixed = true;
document.querySelectorAll('span.pf_pspc').forEach((e) => {
if (getComputedStyle(e).backgroundColor === 'rgba(0, 0, 0, 0)') pspcIconFixed = false;
});
if (!pspcIconFixed) {
GM_addStyle(`
.pf_pspc {
font-size: 11px;
color: white;
border-radius: 2px;
padding: 2px 6px;
margin-right: 4px;
font-weight: 300;
background-color: #171d25;
}`);
// 通用修复:带列表的页面(搜索结果、约战、帖子里的游戏列表)、详情页上的图标修复
GM_addStyle(`
.imgbgnb{
object-fit: cover;
}`);
// 问答详情页中的图标
GM_addStyle(`
.darklist img{
object-fit: cover;
}`);
}
};
fixPspcIcon();
/*
* 页面右下角追加点击跳转到页面底部按钮
*/
const toPageBottom = () => {
$('.bottombar').append("<a id='scrollbottom' class='yuan mt10'>B</a>");
$('#scrollbottom').click(() => {
$('body,html').animate({
scrollTop: document.body.clientHeight,
},
500);
}).css({
cursor: 'pointer',
});
};
// 功能0-2:夜间模式
const nightModeStyle = document.getElementById('nightModeStyle');
// ensures that night mode css is after native psnine css
if (nightModeStyle) {
document.head.appendChild(nightModeStyle);
}
/*
1.游戏列表添加按难度排列按钮
2.游戏列表根据已记录的完成度添加染色
*/
const hdElement = document.querySelector('.hd');
if (hdElement && hdElement.textContent.trim() === '游戏列表') {
// 添加徽章 CSS 类
GM_addStyle(`
span.completion-badge {
background-color: rgb(5 96 175);
font-size: 11px;
color: white;
border-radius: 2px;
padding: 2px 6px;
margin-right: 4px;
font-weight: 300;
}`);
// 背景 CSS 进度条计算,含夜间模式
const progressPlatinumBG = (p) => `background-image: linear-gradient(90deg, rgba(200,240,255,0.6) ${p}%, rgba(200,255,250,0.15) ${p}%)`;
const progressPlatinumBGNight = (p) => `background-image: linear-gradient(90deg, rgba(200,240,255,0.15) ${p}%, rgba(200,255,250,0.05) ${p}%)`;
const progressGoldBG = (p) => `background-image: linear-gradient(90deg, rgba(220,255,220,0.8) ${p}%, rgba(220,255,220,0.15) ${p}%);`;
const progressGoldBGNight = (p) => `background-image: linear-gradient(90deg, rgba(101,159,19,0.15) ${p}%, rgba(101,159,19,0.05) ${p}%);`;
// 获取游戏列表下所有游戏的 DOM 元素指针
const tdElements = document.querySelectorAll('table.list > tbody > tr');
// 获取已保存的完成度
const personalGameCompletions = GM_getValue('personalGameCompletions', []);
// 根据已保存的完成度添加染色
tdElements.forEach((tr) => {
const gameID = tr.getAttribute('id') || 0;
const thisGameCompletion = personalGameCompletions.find((item) => item[0] === gameID);
// if game hase platinum 由于个人页面的白金判断是记录的个人完成度,这里需要判断游戏本身是否有白金
const gameHasPlatinum = tr.querySelector('td.pd10 > .meta > em.text-platinum').textContent === '白1';
if (thisGameCompletion) {
if (gameHasPlatinum && settings.nightMode) { tr.setAttribute('style', progressPlatinumBGNight(thisGameCompletion[1])); }
if (gameHasPlatinum && !settings.nightMode) { tr.setAttribute('style', progressPlatinumBG(thisGameCompletion[1])); }
if (!gameHasPlatinum && settings.nightMode) { tr.setAttribute('style', progressGoldBGNight(thisGameCompletion[1])); }
if (!gameHasPlatinum && !settings.nightMode) { tr.setAttribute('style', progressGoldBG(thisGameCompletion[1])); }
// 添加进度徽章
const gameText = tr.querySelector('td.pd10 > p > a');
if (gameText) {
const completion = thisGameCompletion[1];
const completionBadge = document.createElement('span');
completionBadge.className = 'completion-badge';
completionBadge.textContent = `${completion}%`;
completionBadge.title = '奖杯完成度';
gameText.parentNode.insertBefore(completionBadge, gameText);
}
}
});
// 添加按难度排列按钮
const spanElement = document.createElement('span');
spanElement.className = 'btn';
spanElement.textContent = '按难度排列';
// 添加 span 元素并设置样式
hdElement.appendChild(spanElement);
const style = document.createElement('style');
style.textContent = `
.hd {
display: flex;
justify-content: space-between;
align-items: center;
}
.hd span { margin-top: 0px; }
`;
document.head.appendChild(style);
// 状态变量,跟踪当前的排序顺序,初始为 false 表示降序
let ascending = false;
// 为 span 元素添加点击排序功能
spanElement.addEventListener('click', () => {
const tdArray = Array.from(tdElements).map((tr) => {
const valueElement = tr.querySelector('td.twoge > em');
const value = valueElement ? parseFloat(valueElement.textContent) : null;
return { tr, value };
});
// 根据当前的排序顺序进行排序
tdArray.sort((a, b) => {
if (a.value === null) return 1; // a 为空则放到最后
if (b.value === null) return -1; // b 为空则放到最后
return ascending ? a.value - b.value : b.value - a.value;
});
const tbody = document.querySelector('table.list tbody');
tbody.innerHTML = '';
tdArray.forEach((item) => {
tbody.appendChild(item.tr);
});
// 切换排序顺序
ascending = !ascending;
});
}
/* 用背景进度条显示约战列表中,自己有奖杯记录且未完美的游戏。 */
if (settings.showGameProgressInBattle) {
if (/battle$/.test(window.location.href)) {
const progressPlatinumBG = (p) => `background-image: linear-gradient(90deg, rgba(200,240,255,0.6) ${p}%, rgba(200,255,250,0.15) ${p}%)`;
const progressPlatinumBGNight = (p) => `background-image: linear-gradient(90deg, rgba(200,240,255,0.15) ${p}%, rgba(200,255,250,0.05) ${p}%)`;
const personalGameCompletions = GM_getValue('personalGameCompletions', []);
const tdElements = document.querySelectorAll('table.list > tbody > tr');
tdElements.forEach((tr) => {
const gameID = tr.querySelector('td.pdd15 a').href.match(/\/psngame\/(\d+)/)[1];
const thisGameCompletion = personalGameCompletions.find((item) => item[0] === gameID);
if (thisGameCompletion && thisGameCompletion[1] < 100) {
// 约战页面没有显示游戏本身是否有白金,就直接默认白金底色显示了
if (settings.nightMode) { tr.setAttribute('style', progressPlatinumBGNight(thisGameCompletion[1])); }
if (!settings.nightMode) { tr.setAttribute('style', progressPlatinumBG(thisGameCompletion[1])); }
}
});
}
}
/* ↓↓↓ 约战监控与通知相关功能开始 ↓↓↓↓
1. 用户是否设置了监控
2. 约战缓存是否存在或过期,否则从约战页更新数据
3. 比较两组数据,并更新顶部菜单
*/
// 添加消息通知数量图标样式(伪元素)
GM_addStyle(`
.notice::after {
content: attr(data-notice);
position: absolute;
top: 8px;
right: 0px;
background-color: red;
color: white;
border-radius: 6px;
padding: 2px 2px;
font-size: 12px;
line-height: 0.9em;
display: inline-block;
min-width: 12px;
text-align: center;
}`);
// 定义两个变量,用户设置的游戏约战监控列表,和当前存在的约战列表(缓存)
let userBattleMonitors = GM_getValue('userBattleMonitors', []);
let cacheBattleInfo = GM_getValue('cacheBattleInfo', {});
const updateTopMenuNotice = (lista, listb) => { // 定义函数:变更顶部菜单通知红点,多处执行
let count = 0;
lista.forEach((item) => {
if (listb.includes(item)) count += 1;
});
if (count > 0) {
document.querySelectorAll('#pcmenu li, #mobilemenu li').forEach((el) => {
const a = el.querySelector('a');
if (a && a.innerText === '约战') {
el.classList.add('notice');
el.setAttribute('data-notice', count);
}
});
} else {
document.querySelectorAll('#pcmenu li, #mobilemenu li').forEach((el) => el.classList.remove('notice'));
}
};
const updateBattleRecuritInfo = () => { // 定义函数:更新约战信息
const result = [];
$.ajax({
type: 'GET',
url: 'https://psnine.com/battle',
dataType: 'html',
async: true,
success(data, status) {
if (status === 'success') {
const page = document.createElement('html');
page.innerHTML = data;
const list = page.querySelectorAll('.box table.list > tbody > tr');
list.forEach((tr) => {
const gameID = tr.querySelector('td.pdd15 a').href.match(/\/psngame\/(\d+)/)[1];
result.push(gameID);
});
cacheBattleInfo = { list: result, lastUpdate: new Date().getTime() };
GM_setValue('cacheBattleInfo', cacheBattleInfo);
updateTopMenuNotice(userBattleMonitors, cacheBattleInfo.list);
}
},
error: () => { console.log('无法获取约战信息'); },
});
};
// 页面加载时执行约战监测功能
if (cacheBattleInfo.lastUpdate && new Date().getTime() - cacheBattleInfo.lastUpdate < settings.BattleInfoUpdateInterval) {
updateTopMenuNotice(userBattleMonitors, cacheBattleInfo.list);
} else {
updateBattleRecuritInfo();
}
// 在游戏的约战页面添加约战监控按钮
if (/\/psngame\/\d+\/battle\/?$/.test(window.location.href)) {
const gameID = window.location.href.match(/\/psngame\/(\d+)/)[1];
const actionArea = document.querySelector('center.pd10');
const monitorBTN = document.createElement('p');
monitorBTN.className = 'btn btn-large btn-info';
monitorBTN.title = '当有用户发起该游戏的约战时,顶部菜单会出现红点通知。';
monitorBTN.textContent = userBattleMonitors.includes(gameID) ? '移除约战监控' : '添加约战监控';
// 添加 span 元素并设置样式
actionArea.appendChild(monitorBTN);
const style = document.createElement('style');
style.textContent = `
center.pd10 {
display: flex;
justify-content: space-between;
align-items: center;
}
center.pd10 * {
flex: 1;
width: calc(50% - 8px);
margin: 0 4px;
}`;
document.head.appendChild(style);
// 为 span 元素添加点击事件,切换约战监控状态
monitorBTN.addEventListener('click', () => {
if (userBattleMonitors.includes(gameID)) {
userBattleMonitors = userBattleMonitors.filter((id) => id !== gameID);
monitorBTN.textContent = '添加约战监控';
} else {
userBattleMonitors.push(gameID);
monitorBTN.textContent = '移除约战监控';
}
GM_setValue('userBattleMonitors', userBattleMonitors);
updateTopMenuNotice(userBattleMonitors, cacheBattleInfo.list);
});
}
/* ↑↑↑↑ 约战监控与通知相关功能结束 ↑↑↑↑ */
/*
* 自动签到功能
* @param isOn 是否开启功能
*/
const repeatUntilSuccessful = (functionPtr, interval) => {
if (!functionPtr()) {
setTimeout(() => {
repeatUntilSuccessful(functionPtr, interval);
}, interval);
}
};
const automaticSignIn = (isOn) => {
// 如果签到按钮存在页面上
if (isOn && $('[class$=yuan]').length > 0) {
repeatUntilSuccessful(() => {
if (typeof qidao !== 'function') return false;
let signed = false;
$('[class$=yuan]').each((i, e) => {
if (!signed && /^\s*签\s*$/.test(e.innerText)) {
e.click();
signed = true;
}
});
return true;
}, 200);
}
};
automaticSignIn(settings.autoCheckIn);
/*
* 获取当前页面的后一页页码和链接
* @return nextPage 后一页页码
* @return nextPageLink 后一页的链接
*/
const getNextPageInfo = () => {
// 获取下一页页码
const nextPage = Number($('.page > ul > .current:last').text()) + 1;
// 如果地址已经有地址信息
let nextPageLink = '';
if (/page/.test(window.location.href)) {
nextPageLink = window.location.href.replace(
/page=.+/,
`page=${nextPage}`,
);
} else {
nextPageLink = `${window.location.href}&page=${nextPage}`;
}
return { nextPage, nextPageLink };
};
GM_addStyle(
`#loadingMessage {
position : absolute;
bottom : 0px;
position : fixed;
right : 1px !important;
display : none;
color : white;
}`,
);
/*
在 LocatStorage 中保存个人游戏完成度函数,为避免过多的页面重复请求,逻辑梳理如下:
场景:
1. 更新的奖杯一定在前,但用户可能会隐藏游戏或解除隐藏,导致内容不再确定。
2. 隐藏游戏条目不影响本地已有数据,也不要求本地数据作对应删除,但影响页码数和对应的更新记录
3. 由于设置为 Ajax 5 秒翻页,所以存在前几页数据已更新,后几页数据因为用户关闭页面而未更新的情况
4. 用户新开坑,可能导致页面数量增长,此时,最后几页也未记录更新时间,但实际是不需要更新的
简化:
1. 没有时间记录的页面,都需要更新,有时间记录的页面,从前往后更新,遇到无变化奖杯条目的就停止
2. 当用户进行异常操作时,需要自行通过翻页刷新数据
*/
// 测试用清除数据
// GM_setValue('personalGameCompletions', []);
// console.log(GM_getValue('personalGameCompletions', []));
// GM_setValue('personalGameCompletionsLastUpdate', []);
const parseCompletionPage = (content) => {
// 游戏进度信息
const tdElements = content.querySelectorAll('table.list tbody > tr');
const thisPageCompletions = Array.from(tdElements).map((tr) => {
const completionElement = tr.querySelector('div.progress > div');
const completion = completionElement ? parseFloat(completionElement.textContent) : 0;
const platinumElement = tr.querySelector('span.text-platinum');
const platinum = platinumElement ? platinumElement.textContent === '白1' : false;
const gameIDElement = tr.querySelector('a');
const gameID = gameIDElement.href.match(/\/psngame\/(\d+)/)[1];
return [gameID, completion, platinum];
});
// 获得总页数和总条目数
let totalPages = 0; let
totalItems = 0;
const PaginationEle = content.querySelectorAll('.page > ul > li > a');
if (PaginationEle.length > 2) {
totalPages = parseInt(PaginationEle[PaginationEle.length - 2].innerText, 10);
totalItems = parseInt(PaginationEle[PaginationEle.length - 1].innerText, 10);
}
return { totalPages, totalItems, thisPageCompletions };
};
const updateCompletions = (updateList) => {
const gameCompletionHistory = GM_getValue('personalGameCompletions', []);
let addCounts = 0;
updateList.forEach((completion) => {
const index = gameCompletionHistory.findIndex((historyItem) => historyItem[0] === completion[0]);
if (index !== -1) {
if (gameCompletionHistory[index][1] !== completion[1]) { addCounts += 1; }
gameCompletionHistory[index] = completion;
} else {
gameCompletionHistory.push(completion);
addCounts += 1;
}
});
GM_setValue('personalGameCompletions', gameCompletionHistory);
const totalRecords = gameCompletionHistory.length;
return { addCounts, totalRecords };
};
// 后台更新主函数
const loadGameCompletions = (userid, startPageID) => {
// console.log(`https://psnine.com/psnid/${userid}/psngame?page=${startPageID}`)
$.ajax({
type: 'GET',
url: `https://psnine.com/psnid/${userid}/psngame?page=${startPageID}`,
dataType: 'html',
async: true,
success: (data, status) => {
if (status === 'success') {
// 读取历史数据
let pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []);
// 2024.07.30 bug fix: 错误地保存他人的游戏完成度 - 已经修复,但用户端的旧数据需要清除
if (Array.isArray(pagesUpdateTime) === false
|| pagesUpdateTime[0] === undefined
|| pagesUpdateTime[0] < 1722333600000 // 2024-07-30 18:00 GMT+0800
) {
GM_setValue('personalGameCompletions', []);
pagesUpdateTime = [];
}
// 读取当前页奖杯完成数据
const page = document.createElement('html');
page.innerHTML = data;
const o = parseCompletionPage(page);
const { thisPageCompletions } = o;
const totalPages = o.totalPages || pagesUpdateTime.length || 1;
const { addCounts } = updateCompletions(thisPageCompletions);
// 更新页面记录时间
pagesUpdateTime[startPageID - 1] = new Date().getTime();
GM_setValue('personalGameCompletionsLastUpdate', pagesUpdateTime);
// 根据规则计算下一页
if (addCounts === thisPageCompletions.length && startPageID < totalPages - 1) {
setTimeout(() => { loadGameCompletions(userid, startPageID + 1); }, 5000);
return true;
}
const fullfilledUpdateTime = pagesUpdateTime.concat(Array(totalPages - pagesUpdateTime.length).fill(0));
const nextIdx = fullfilledUpdateTime.findIndex((time) => time === undefined || time === 0 || time === null);
if (nextIdx !== -1) {
setTimeout(() => { loadGameCompletions(userid, nextIdx + 1); }, 5000);
return true;
}
return false;
}
return true;
},
error: (e) => { console.log('loadGameCompletions error', e); },
});
};
// 获取个人 ID
const myHomePage = document.querySelectorAll('ul.r li.dropdown ul li a')[0].href;
const myUserId = myHomePage.match(/\/psnid\/([A-Za-z0-9_-]+)/)[1] || '*';
// const myGamePageURLRegex = new RegExp(`psnid/${myUserId}/?(?:psngame(?:\\?page=(\\d+))?|$)`);
const myHomepageURLRegex = new RegExp(`psnid/${myUserId}/?`);
const myGamePageURLRegex = new RegExp(`psnid/${myUserId}/psngame(?:\\?page=(\\d+))?`);
// 后台更新频次控制
const bgUpdateMyGameCompletion = () => {
const pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []);
const now = new Date().getTime();
if (pagesUpdateTime[0] === undefined || now - pagesUpdateTime[0] > 60 * 60 * 1000) {
loadGameCompletions(myUserId, 1);
}
};
// 在用户浏览个人页面或个人游戏列表页时,无视 Interval 白嫖一次数据更新
if (myGamePageURLRegex.test(window.location.href)) {
const pageid = parseInt(window.location.href.match(myGamePageURLRegex)[1], 10) || 1;
const { totalItems, thisPageCompletions } = parseCompletionPage(document);
const { totalRecords } = updateCompletions(thisPageCompletions);
const pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []);
pagesUpdateTime[pageid - 1] = new Date().getTime();
GM_setValue('personalGameCompletionsLastUpdate', pagesUpdateTime);
if (totalRecords < totalItems || totalItems === 0) {
const nextPageID = pageid === 1 ? 2 : 1;
loadGameCompletions(myUserId, nextPageID);
}
} else if (myHomepageURLRegex.test(window.location.href)) {
const { thisPageCompletions } = parseCompletionPage(document);
updateCompletions(thisPageCompletions);
const pagesUpdateTime = GM_getValue('personalGameCompletionsLastUpdate', []);
pagesUpdateTime[0] = new Date().getTime();
GM_setValue('personalGameCompletionsLastUpdate', pagesUpdateTime);
} else {
bgUpdateMyGameCompletion(); // 定时更新
}
/// /////////////////////////////////////////////////////////////////////////////////
/* 在奖杯页提供扩展功能,把每个奖杯页的评论直接展示在当前页面。
可以单点展开一个奖杯的 tips。
// 一次性展开所有奖杯 tips 的逻辑可能会造成服务器压力过大,已隐藏
同时改进页面默认的排序功能并阻止页面跳转行为。
*/
// 节流,防止用户多次点击
const throttleDebounce = (func, delay) => {
let timeout = null;
return (...args) => {
if (!timeout) {
func.apply(this, args);
timeout = setTimeout(() => { timeout = null; }, delay);
}
};
};
// const myGameTrophyPageRegex = new RegExp(`psngame/(\\d+)\\?psnid=${myUserId}`);
// if (myGameTrophyPageRegex.test(window.location.href)) {
// 不再限制到自己的游戏页,现在在别人的游戏页也会执行
const gameTrophyPageRegex = new RegExp('psngame/\\d+\\?psnid=');
if (gameTrophyPageRegex.test(window.location.href)) {
const height = Math.min(Math.max(window.innerHeight - 100, 320), 1200);
GM_addStyle(`.tipContainer > .list {max-height:${height}px; overflow-y:auto; box-shadow:inset 0 0 100px rgba(0,0,0,0.05); padding: 10px 0; border-left: 2px solid #00a8e6;}`);
GM_addStyle('.tipContainer { padding: 10px 10px 10px 84px; margin: 0;}');
GM_addStyle('.tipContainer > ul.list > li {padding: 4px 14px 4px 8px;}');
GM_addStyle('.tipContainer > ul.list > li:first-child { padding:4px 14px 4px 8px;}');
GM_addStyle('table.list td > p > em.alert-success{cursor:pointer}');
GM_addStyle('table.list td > p > em.alert-success::after{content:""; width:0; height:0px; border-top:5px solid #659f13; border-left: 5px solid transparent; border-right: 5px solid transparent; margin-left: 7px; display: inline-block; position: relative; top: -2px}');
const trophyTables = Array.from(document.querySelectorAll('table.list')); // every dlc has one table
const thisPageTrophyList = trophyTables
.flatMap((table) => Array.from(table.querySelectorAll('tr[id]'))
.map((tr) => {
const ID = parseInt(tr.id, 10);
const tds = Array.from(tr.querySelectorAll('td'));
const trophyLink = tds[0].querySelector('a').href;
const trophyTypeMatch = tds[0].className.match(/\b(t1|t2|t3|t4)\b/);
const trophyType = trophyTypeMatch ? trophyTypeMatch[1] : '';
const tipNumberEle = tds[1].querySelector('p em.alert-success b');
const tipNumber = tipNumberEle ? parseInt(tipNumberEle.innerText, 10) : 0;
const earned = tds.length === 4 && !!tds[2].querySelector('em');
const percentage = parseFloat(tds[tds.length - 1].innerText) || 0;
return {
ID,
trophyLink,
trophyType,
tipNumber,
earned,
percentage,
trDom: tr,
table,
tipListDom: null,
tipShow: false,
};
}));
// 添加对象代理以便数据更新后自动渲染对应 DOM,并且在 tipShow 为 true 时自动加载
const myTrophyList = thisPageTrophyList.map((item) => new Proxy(item, {
set: (target, prop, value) => {
let flag = false;
if (prop === 'tipListDom' || prop === 'tipShow') { flag = true; }
target[prop] = value;
// eslint-disable-next-line no-use-before-define
if (flag) { refreshTrophyTip(); }
return true;
},
}));
// 根据当前状态刷新 tipListDom,维护列表的正常展示顺序
const refreshTrophyTip = () => {
// eslint-disable-next-line no-use-before-define
mutationsOff();
myTrophyList.filter((t) => t.tipListDom).forEach((t) => {
if (t.trDom.style.display !== 'none' && t.tipShow === true) { // 应当显示
t.trDom.insertAdjacentElement('afterend', t.tipListDom); // 插入或移动
} else {
t.tipListDom.remove(); // 不显示则移出文档,重复 remove() 无影响
}
});
// eslint-disable-next-line no-use-before-define
mutationsOn();
};
// 独立实现黑名单与屏蔽词,因为只在 getTipContent() 中用到一次。
// 旧版的黑名单与屏蔽词函数是基于页面当前 dom 渲染的,会在 refreshTrophyTip 后重置
const userListLowerCase = settings.blockList.map((user) => user.toLowerCase());
const blockWordsList = settings.blockWordsList.map((word) => word.toLowerCase());
const filterBlockUser = (rootEle, itemSelector, itemAuthorSelector) => {
const items = rootEle.querySelectorAll(itemSelector);
if (items.length > 0) {
items.forEach((item) => {
const authorEle = item.querySelector(itemAuthorSelector);
if (authorEle) {
const author = authorEle.innerText.toLowerCase();
if (userListLowerCase.includes(author.toLowerCase())) {
item.remove();
}
}
});
}
};
const filterBlockWords = (rootEle, itemSelector, contentSelector) => {
const posts = rootEle.querySelectorAll(itemSelector);
if (posts.length > 0) {
posts.forEach((post) => {
const contentEle = post.querySelector(contentSelector);
if (contentEle) {
const content = contentEle.textContent.toLowerCase();
if (blockWordsList.some((word) => content.includes(word))) {
const warningDiv = document.createElement('div');
warningDiv.textContent = '====== 内容包含您的屏蔽词,点击查看屏蔽内容 ======';
warningDiv.className = 'btn btn-gray font12';
warningDiv.style.marginBottom = '2px';
warningDiv.onclick = () => {
warningDiv.previousElementSibling.style.display = 'block';
warningDiv.style.display = 'none';
};
post.style.display = 'none';
post.insertAdjacentElement('afterend', warningDiv);
}
}
});