-
Notifications
You must be signed in to change notification settings - Fork 4
/
ckylin-bilibili-display-video-id.user.js
2507 lines (2439 loc) · 125 KB
/
ckylin-bilibili-display-video-id.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name 哔哩哔哩自定义视频信息条
// @namespace ckylin-bilibili-display-video-id
// @version 1.19.3
// @description 完全自定义你的视频标题下方信息栏,排序,增加,删除!
// @author CKylinMC
// @match https://www.bilibili.com/video*
// @match https://www.bilibili.com/medialist/play/*
// @resource cktools https://greasyfork.org/scripts/429720-cktools/code/CKTools.js?version=1034581
// @resource popjs https://cdn.jsdelivr.net/gh/CKylinMC/PopNotify.js@master/PopNotify.js
// @resource popcss https://cdn.jsdelivr.net/gh/CKylinMC/PopNotify.js@master/PopNotify.css
// @resource timeago https://unpkg.com/[email protected]/dist/timeago.min.js
// @grant unsafeWindow
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_getResourceText
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @license GPL-3.0-only
// ==/UserScript==
(function () {
//======[Apply all resources]
const resourceList = [
{ name: 'cktools', type: 'js' },
{ name: 'timeago', type: 'js' },
{ name: 'popjs', type: 'js' },
{ name: 'popcss', type: 'css' },
{ name: 'popcsspatch', type: 'rawcss', content: "div.popNotifyUnitFrame{z-index:110000!important;}.CKTOOLS-modal-content{color: #616161!important;max-height: 80vh;overflow: auto;}" },
]
function applyResource() {
resloop: for (let res of resourceList) {
if (!document.querySelector("#" + res.name)) {
let el;
switch (res.type) {
case 'js':
case 'rawjs':
el = document.createElement("script");
break;
case 'css':
case 'rawcss':
el = document.createElement("style");
break;
default:
console.log('Err:unknown type', res);
continue resloop;
}
el.id = res.name;
el.innerHTML = res.type.startsWith('raw') ? res.content : GM_getResourceText(res.name);
document.head.appendChild(el);
}
}
}
applyResource();
//======
const wait = (t) => new Promise(r => setTimeout(r, t));
const waitForPageVisible = async () => {
return document.hidden && new Promise(r => document.addEventListener("visibilitychange", r))
}
const log = (...m) => console.log('[ShowAV]', ...m);
const getAPI = (bvid) => fetch('https://api.bilibili.com/x/web-interface/view?bvid=' + bvid).then(raw => raw.json());
const getAidAPI = (aid) => fetch('https://api.bilibili.com/x/web-interface/view?aid=' + aid).then(raw => raw.json());
const config = {
defaultAv: true,
hideTime: true,
firstTimeLoad: true,
defaultTextTime: true,
foldedWarningTip: true,
forceRemoveAllItem: true,
showInNewLine: false,
forceGap: false,
nobreakline: false,
jssafetyWarning: true,
pnmaxlength: 18,
orders: ['openGUI', 'showArgue', 'showPic', 'showAv', 'showPn'],
all: ['showAv', 'showSAv', 'showSBv', 'showPn', 'showCid', 'showCate', 'openGUI', 'showPic', 'showSize', 'showMore', 'showCTime', 'showViews', 'showDmk', 'showTop', 'showArgue'],
copyitems: ['currTime', 'short', 'shareTime', 'vid'],
copyitemsAll: ['curr', 'currTime', 'short', 'share', 'shareTime', 'md', 'bb', 'html', 'vid'],
customcopyitems: {},
customComponents: {},
vduration: 0,
running: {}
};
const ignoredConfigKeys = ["all", "vduration", "firstTimeLoad", "running"];
const menuId = {
defaultAv: -1,
foldedWarningTip: -1,
showInNewLine: -1,
};
const txtCn = {
showAv: "可切换视频编号和高级复制",
showSAv: "视频AV号和高级复制",
showSBv: "视频BV号和高级复制",
showPn: "视频分P名",
showCid: "视频CID编号",
showCate: "视频所在分区",
showPic: "视频封面",
showSize: "视频分辨率",
showMore: "更多信息",
showCTime: "视频投稿时间",
showViews: "替换视频播放量",
showDmk: "替换视频弹幕量",
showTop: "替换全站排名提示",
showArgue: "显示危险提示",
curr: "当前视频地址",
currTime: "当前视频地址(含视频进度)",
short: "短地址",
share: "快速分享",
shareTime: "快速分享(含视频进度)",
md: "Markdown 格式",
bb: "BBCode 格式",
html: "HTML 格式",
vid: "视频编号",
openGUI: "设置选项"
};
const descCn = {
showAv: "展示视频号(AV号/BV号右键单击可切换),左键单击快速复制(包含当前播放时间),左键长按打开更多格式复制窗口",
showSAv: "展示视频AV号,左键单击快速复制(包含当前播放时间),左键长按打开更多格式复制窗口",
showSBv: "展示视频BV号,左键单击快速复制(包含当前播放时间),左键长按打开更多格式复制窗口",
showPn: "展示视频分P信息以及缓存名(分P名)。可能较长,建议放在最下面,并调整最大长度。",
showCid: "展示视频资源CID编号,通常不需要展示。",
showCate: "展示视频所在的子分区。",
showPic: "提供按钮一键查看封面,长按可以在新标签页打开大图。",
showSize: "展示视频当前分辨率(宽高信息)。",
showMore: "查看视频更多信息。",
showCTime: "用文字方式描述投稿时间,如:一周前",
showViews: "替换展示视频播放量(由于内容相同,将自动隐藏原版播放量信息)",
showDmk: "替换展示视频弹幕量(由于内容相同,将自动隐藏原版弹幕量信息)",
showTop: "替换原版全站排名信息",
showArgue: "如果视频有危险提示,则显示危险提示",
curr: "提供当前视频纯净地址",
currTime: "提供当前视频地址,并在播放时提供含跳转时间的地址(可以直接跳转到当前进度)。",
short: "提供当前视频的b23.tv短地址",
share: "提供当前视频的标题和地址组合文本。",
shareTime: "提供当前视频的标题和地址组合文本,在播放时提供含跳转时间的地址(可以直接跳转到当前进度)。",
md: "提供Markdown特殊语法的快速复制。",
bb: "提供BBCode特殊语法的快速复制。",
html: "提供HTML格式的快速复制。",
vid: "提供当前视频av号/BV号/CID号。请注意此项目不支持快速复制。",
openGUI: "提供按钮快速进入设置选项。"
};
const idTn = {
showAv: 2,
showSAv: 2,
showSBv: 2,
showPn: 5,
showCid: 2,
showCate: 3,
showPic: 1,
showSize: 2,
showMore: 1,
showCTime: -4,
showViews: -2,
showDmk: -2,
showTop: 0,
showArgue: 1,
openGUI: 1
};
let globalinfos = {};
// https://stackoverflow.com/questions/10726638
String.prototype.mapReplace = function (map) {
var regex = [];
for (var key in map)
regex.push(key.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"));
return this.replace(new RegExp(regex.join('|'), "g"), function (word) {
return map[word];
});
};
// CSDN https://blog.csdn.net/namechenfl/article/details/91968396
function numberFormat(value) {
let param = {};
let k = 10000,
sizes = ['', '万', '亿', '万亿'],
i;
if (value < k) {
param.value = value
param.unit = ''
} else {
i = Math.floor(Math.log(value) / Math.log(k));
param.value = ((value / Math.pow(k, i))).toFixed(2);
param.unit = sizes[i];
}
return param;
}
function exec(code,binding=this){
return (async function(){
eval(code);
}).bind(binding);
}
async function saveAllConfig() {
for (let configKey of Object.keys(config)) {
if (ignoredConfigKeys.includes(configKey)) continue;
await GM_setValue(configKey, config[configKey]);
}
popNotify.success("配置保存成功");
}
async function initScript(flag = false) {
for (let menuitem of Object.keys(menuId)) {
if (menuId[menuitem] != -1) GM_unregisterMenuCommand(menuId[menuitem]);
}
for (let configKey of Object.keys(config)) {
if (ignoredConfigKeys.includes(configKey)) continue;
if (typeof (await GM_getValue(configKey)) === 'undefined') {
await GM_setValue(configKey, config[configKey]);
} else {
config[configKey] = await GM_getValue(configKey);
}
}
GM_registerMenuCommand("打开设置", async () => {
await GUISettings();
});
CKTools.addStyle(`
#bilibiliShowPN{
max-width: ${config.pnmaxlength}em!important;
}
`, "showav_pnlen", "update", document.head);
tryInject(flag);
}
async function playerReady() {
let i = 150;
while (--i > 0) {
await wait(100);
console.log('ShowAV waiting for player ready - loop')
if (unsafeWindow.player?.isInitialized()??false) break;
}
console.log('ShowAV waiting for player ready - loop end')
if (i < 0) return false;
console.log('ShowAV waiting for player ready - wait visible')
await waitForPageVisible();
while (1) {
await wait(200);
console.log('ShowAV waiting for player controlls')
if (document.querySelector(".bilibili-player-video-control-wrap, .bpx-player-control-wrap")) return true;
}
}
async function waitForDom(q) {
let i = 50;
let dom;
while (--i >= 0) {
if (dom = document.querySelector(q)) break;
await wait(100);
}
return dom;
}
function getUrlParam(key) {
return (new URL(location.href)).searchParams.get(key);
}
function getOrNew(id, parent,) {
let target = document.querySelector("#" + id);
if (!target) {
target = document.createElement("span");
target.id = id;
parent.appendChild(target);
}
return target;
}
async function getPlayerSeeks() {
const video = await waitForDom(".bilibili-player-video video");
let seconds = 0;
if (video) {
seconds = Math.floor(video.currentTime);
}
if (seconds == 0) {
let fromParam = getUrlParam("t") || 0;
return fromParam;
} else return seconds;
}
function getHEVC(){
return document.querySelector(".bilibili-player-video bwp-video")
}
async function registerVideoChangeHandler() {
const video = await waitForDom(".bilibili-player-video video");
const HEVCplayer = getHEVC();// must behind video loaded(no more waitfordom)
let target = HEVCplayer || video;
if(!target) return;
const observer = new MutationObserver(async e => {
if (e[0].target.src) {
tryInject(true);
}
});
observer.observe(target, { attribute: true, attributes: true, childList: false });
}
function getPageFromCid(cid, infos) {
if (!cid || !infos || !infos.pages) return 1;
let pages = infos.pages;
if (pages.length == 1) return 1;
let page;
for (page of pages) {
if (!page) continue;
if (page.cid == cid) return page.page;
}
return 1;
}
async function feat_showCate() {
const { av_root, infos } = this;
const cate_span = getOrNew("bilibiliShowCate", av_root);
//if (config.showCate) {
cate_span.style.textOverflow = "ellipsis";
cate_span.style.whiteSpace = "nowarp";
cate_span.style.overflow = "hidden";
cate_span.title = "分区: " + infos.tname;
cate_span.innerText = "分区: " + infos.tname;
//} else cate_span.remove();
}
async function feat_showStaticAv() {
const func = feat_showAv.bind(this);
func(true);
}
async function feat_showStaticBv() {
const func = feat_showAv.bind(this);
func(true, 'bv');
}
async function prepareData(infos,el=null){
const defaultVid = el?el.innerText:'av'+infos.aid;
const currpage = new URL(location.href);
let part = infos.p==currpage.searchParams.get("p")
? infos.p
: (currpage.searchParams.get("p") ? currpage.searchParams.get("p") : infos.p);
let url = new URL(location.protocol + "//" + location.hostname + "/video/" + defaultVid);
part == 1 || url.searchParams.append("p", part);
let vidurl = new URL(url);
let shorturl = new URL(location.protocol + "//b23.tv/" + defaultVid);
let t = await getPlayerSeeks();
if (t && t != "0" && t != ("" + config.vduration)) url.searchParams.append("t", t);
try {
partinfo = infos.pages[infos.p - 1];
} catch (e) {
partinfo = infos.pages[0];
}
return {currpage,partinfo,url,vidurl,shorturl,part,t,infos}
}
async function getCopyItem(copyitem,infos,av_span=null){
const {partinfo,url,vidurl,shorturl,part,t} = await prepareData(infos,av_span);
switch (copyitem) {
case "curr":
return {
title: "当前地址",
content: vidurl,
type: "copiable"
};
case "currTime":
return {
title: "含视频进度地址(仅在播放时提供)",
content: url,
type: "copiable"
};
case "short":
return {
title: "短地址格式",
content: shorturl,
type: "copiable"
};
case "share":
return {
title: "快速分享",
content: `${infos.title}_地址:${shorturl}`,
type: "copiable"
};
case "shareTime":
return {
title: "快速分享(含视频进度)",
content: `${infos.title}_地址:${url}`,
type: "copiable"
};
case "md":
return {
title: "MarkDown格式",
content: `[${infos.title}](${vidurl})`,
type: "copiable"
};
case "bb":
return {
title: "BBCode格式",
content: `[url=${vidurl}]${infos.title}[/url]`,
type: "copiable"
};
case "html":
return {
title: "HTML格式",
content: `<a href="${vidurl}">${infos.title}</a>`,
type: "copiable"
};
case "vid":
return {
title: "视频编号",
content: `<div class="shoav_expandinfo">
<div>
AV号
<input class="shortinput" readonly value="av${infos.aid}" onclick="showav_fastcopy(this);" />
</div>
<div>
BV号
<input class="shortinput" readonly value="${infos.bvid}" onclick="showav_fastcopy(this);" />
</div>
<div>
资源CID
<input class="shortinput" readonly value="${infos.cid}" onclick="showav_fastcopy(this);" />
</div>
</div>
`,
type: "component",
copyaction: function(){
copy(this.av_span.innerText);
popNotify.success("已复制到剪贴板",this.av_span.innerText);
}
};
default:
if (Object.keys(config.customcopyitems).includes(copyitem)) {
let ccopyitem = config.customcopyitems[copyitem];
let pat = ccopyitem.content ? ccopyitem.content : "无效内容";
pat = apiBasedVariablesReplacement(pat.mapReplace({
"%timeurl%": url,
"%vidurl%": vidurl,
"%shorturl%": shorturl,
"%seek%": t,
"%title%": infos.title,
"%av%": infos.aid,
"%bv%": infos.bvid,
"%cid%": infos.cid,
"%p%": part,
"%pname%": partinfo.part,
"'": "\'"
}));
return {
title: `(自定义) ${ccopyitem.title}`,
content: pat,
type: "copiable"
}
}else return null;
}
};
function apiBasedVariablesReplacement(txt='',infos=globalinfos){
log("apiBasedVariablesReplacement",infos);
const vars = [...txt.matchAll(/\%[a-zA-Z.]+\%/g)].map(k=>k[0]);
if(vars.length==0) return txt;
const map = {};
for(let replaceVar of vars){
const varName = replaceVar.substring(1,replaceVar.length-1);
const apiResult = recursiveApiResolver(varName,infos);
if(!apiResult) continue;
map[replaceVar] = apiResult;
}
return txt.mapReplace(map);
}
function recursiveApiResolver(name,infos=globalinfos){
const pargs = name.split(".").filter(arr=>arr.length);
if([pargs[0],pargs[pargs.length-1]].includes("")) return null;
let target = infos;
for(let parg of pargs){
if(target.hasOwnProperty(parg)){
target = target[parg];
}else return null;
}
return target.toString();
}
async function feat_showAv(force = false, mode = 'av'/* 'bv' */) {
const { av_root, infos } = this;
const av_span = getOrNew("bilibiliShowAV" + (force ? mode : ''), av_root);
//if (config.showAv) {
if (force) {
if (mode == 'bv') {
av_span.innerText = infos.bvid;
} else {
av_span.innerText = 'av' + infos.aid;
}
} else if (config.defaultAv)
av_span.innerText = 'av' + infos.aid;
else
av_span.innerText = infos.bvid;
av_span.style.overflow = "hidden";
const video = await waitForDom("video");
if (video) {
config.vduration = Math.floor(video.duration);
}
let title = `左键单击复制,${force?'右键单击切换显示,':''}长按打开窗口`;
if(config.copyitems.length){
const firstCopyItem = config.copyitems[0];
const firstInfo = await getCopyItem(firstCopyItem,globalinfos,av_span);
if(firstInfo!==null){
if(firstInfo.type=="copiable"||firstInfo.type=="component"){
av_span.setAttribute('title',title + '\n默认复制: '+firstInfo.title);
}
}else av_span.setAttribute('title',title + '\n没有默认复制行为');
}else{
av_span.setAttribute('title',title + '\n没有默认复制行为');
}
if (av_span.getAttribute("setup") != globalinfos.cid) {
if (!force)
av_span.oncontextmenu = e => {
if (e.target.innerText.startsWith('av')) e.target.innerText = infos.bvid;
else av_span.innerText = 'av' + infos.aid;
e.preventDefault();
};
let runningCfg = config.running['avspanHC'+(force ? mode : '')];
if(runningCfg) runningCfg.uninstall();
runningCfg = new CKTools.HoldClick(av_span);
runningCfg.onclick(async e => {
for (let copyitem of config.copyitems) {
const copyiteminfo = await getCopyItem(copyitem,globalinfos,av_span);
if(copyiteminfo===null) {
log(`[ADVCOPY] warning: unknown custom copy item id "${copyitem}", maybe should clean settings up.`);
continue;
}
if(copyiteminfo.type=="copiable"){
copy(copyiteminfo.content);
popNotify.success(copyiteminfo.title+"复制成功", copyiteminfo.content);
return;
}
else if(copyiteminfo.type=="component"){
if(typeof(copyiteminfo.copyaction)==="function"){
try{
const func = copyiteminfo.copyaction.bind({av_span});
func();
}catch(e){log(copyiteminfo,e);}
}else{
copy(copyiteminfo.copyaction.toString());
popNotify.success("已复制到剪贴板",copyiteminfo.copyaction.toString())
}
return;
}
else continue;
}
popNotify.error("快速复制失败","没有任何已启用的可用快速复制设定");
});
runningCfg.onhold(async e => {
let modalcontent = `
<style scoped>
input:not(.shortinput){
width:100%;
display:block;
}
.shoav_expandinfo>div {
text-align: center;
flex: 1;
}
input.shortinput {
width: 7.8em;
text-align: center;
}
.CKTOOLS-modal-content>div>div{
width: 440px!important;
}
.shoav_expandinfo{
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-content: center;
justify-content: space-around;
align-items: stretch;
}
</style>
<b>点击输入框可以快速复制</b><br>`;
for (let copyitem of config.copyitems) {
const copyiteminfo = await getCopyItem(copyitem,globalinfos,av_span);
if(copyiteminfo.type=="copiable"){
modalcontent+=`<span class="copyitem-title">${copyiteminfo.title}</span><input readonly value="${copyiteminfo.content}" onclick="showav_fastcopy(this);" />`
}
else{
modalcontent+=copyiteminfo.content;
}
}
modalcontent += `<br><hr><a href="javascript:void(0)" onclick="showav_guisettings_advcopy()">⚙ 复制设置</a><br>
<a href="https://github.com/CKylinMC/UserJS/issues/new?assignees=CKylinMC&labels=&template=feature-request.yaml&title=%5BIDEA%5D+ShowAV%E8%84%9A%E6%9C%AC%E9%A2%84%E8%AE%BE%E9%93%BE%E6%8E%A5%E6%A0%BC%E5%BC%8F%E8%AF%B7%E6%B1%82&target=[%E8%84%9A%E6%9C%AC%EF%BC%9A%E8%A7%86%E9%A2%91%E9%A1%B5%E9%9D%A2%E5%B8%B8%E9%A9%BB%E6%98%BE%E7%A4%BAAV/BV%E5%8F%B7]&desp=%E6%88%91%E5%B8%8C%E6%9C%9B%E6%B7%BB%E5%8A%A0%E6%96%B0%E7%9A%84%E9%A2%84%E8%AE%BE%E9%93%BE%E6%8E%A5%E6%A0%BC%E5%BC%8F%EF%BC%8C%E5%A6%82%E4%B8%8B...">缺少你需要的格式?反馈来添加...</a>
`;
modalcontent+= closeButton().outerHTML;
CKTools.modal.alertModal("高级复制", modalcontent, "关闭");
});
av_span.setAttribute("setup", globalinfos.cid);
config.running['avspanHC'+(force ? mode : '')] = runningCfg;
}
//} else av_span.remove();
}
async function feat_showMore() {
const { av_root } = this;
const more_span = getOrNew("bilibiliShowMore", av_root);
more_span.innerHTML = '⋯';
more_span.title = "展示更多信息";
more_span.style.cursor = "pointer";
if (more_span.getAttribute("setup") != globalinfos.cid) {
more_span.addEventListener('click', async e => {
let part, videoData = globalinfos;
try {
part = videoData.pages[globalinfos.p - 1];
} catch (e) {
part = videoData.pages[0];
}
let currentPageName = part.part.length ? part.part : '';
let currentPageNum;
if (videoData.videos != 1) {
currentPageNum = `P ${globalinfos.p}/${videoData.videos}`;
} else {
currentPageNum = "P 1/1";
}
CKTools.modal.alertModal("视频信息", `
<style scoped>
li{
line-height: 2em;
}
</style>
<li>
<b>AV号: </b>av${globalinfos.aid}
</li>
<li>
<b>BV号: </b>${globalinfos.bvid}
</li>
<li>
<b>CID: </b>${globalinfos.cid}
</li>
<li>
<b>分P: </b>${currentPageNum}
</li>
<li>
<b>P名: </b>${currentPageName}
</li>
<li>
<b>长度: </b>${globalinfos.duration}s
</li>
<li>
<b>投稿: </b>${timeago.format(globalinfos.ctime * 1000, 'zh_CN')}
</li>
<li>
<b>分区: </b>${globalinfos.tname}
</li>
<li>
<b>大小: </b>${globalinfos.dimension.width}x${globalinfos.dimension.height}
</li>
<li>
<b>封面: </b><a href="${globalinfos.pic}" target="_blank">点击查看</a>
</li>
`, "确定");
})
more_span.setAttribute("setup", globalinfos.cid);
}
}
async function feat_showCTime() {
const { av_root, infos } = this;
const ct_span = getOrNew("bilibiliShowCTime", av_root);
ct_span.style.textOverflow = "ellipsis";
ct_span.style.whiteSpace = "nowarp";
ct_span.style.overflow = "hidden";
const d = new Date(infos.pubdate * 1000);
let txttime = timeago.format(infos.pubdate * 1000, 'zh_CN');
let rawtime = `${d.getFullYear()}-${(d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1}-${d.getDate() < 10 ? '0' + d.getDate() : d.getDate()} ${d.getHours() < 10 ? '0' + d.getHours() : d.getHours()}:${d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes()}:${d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds()}`;
ct_span.title = "投稿时间 " + (config.defaultTextTime ? rawtime : txttime);
ct_span.innerHTML = config.defaultTextTime ? txttime : rawtime
if (config.hideTime) ct_span.innerHTML += `
<style>
.video-info-detail span:nth-child(3),.video-info-detail span.pupdate{
display:none!important;
}
</style>`;
}
async function feat_showViews() {
const { av_root, infos } = this;
const v_span = getOrNew("bilibiliShowViews", av_root);
v_span.style.textOverflow = "ellipsis";
v_span.style.whiteSpace = "nowarp";
v_span.style.overflow = "hidden";
v_span.title = `播放量 ${infos.stat.view}`;
v_span.innerHTML = (() => {
const res = numberFormat(infos.stat.view);
return `${res.value}${res.unit}播放`;
})();
v_span.innerHTML += `
<style>
.video-info-detail span.view{
display:none!important;
}
</style>`;
}
async function feat_showDmk() {
const { av_root, infos } = this;
const dmk_span = getOrNew("bilibiliShowDmk", av_root);
dmk_span.style.textOverflow = "ellipsis";
dmk_span.style.whiteSpace = "nowarp";
dmk_span.style.overflow = "hidden";
dmk_span.title = `${infos.stat.danmaku}条弹幕`;
dmk_span.innerHTML = (() => {
const res = numberFormat(infos.stat.danmaku);
return `${res.value}${res.unit}条弹幕`;
})();
dmk_span.innerHTML += `
<style>
.video-info-detail span.dm{
display:none!important;
}
</style>`;
}
async function feat_showTop() {
const { av_root, infos } = this;
const top_span = getOrNew("bilibiliShowTop", av_root);
top_span.style.textOverflow = "ellipsis";
top_span.style.whiteSpace = "nowarp";
top_span.style.overflow = "hidden";
top_span.title = `全站最高排行第${infos.stat.his_rank}名`;
top_span.innerHTML = ''
top_span.innerHTML += `
<style>
.video-info-detail span.rank,.video-info-detail a.honor{
display:none!important;
}
</style>`;
if (infos.stat.his_rank === 0) {
top_span.style.display = "none";
setTimeout(() => {
if (top_span.nextElementSibling) {
top_span.nextElementSibling.style.marginLeft = 0;
}
}, 100);
} else {
top_span.innerHTML += '📊 ' + infos.stat.his_rank;
}
}
async function feat_showPic() {
const { av_root, infos } = this;
const pic_span = getOrNew("bilibiliShowPic", av_root);
pic_span.style.textOverflow = "ellipsis";
pic_span.style.whiteSpace = "nowarp";
pic_span.style.overflow = "hidden";
pic_span.title = "查看封面";
pic_span.innerHTML = "🖼️";
pic_span.style.cursor = "pointer";
if (pic_span.getAttribute("setup") != globalinfos.cid) {
config.running.picHC && config.running.picHC.uninstall();
config.running.picHC = new CKTools.HoldClick(pic_span);
config.running.picHC.onclick(() => {
CKTools.modal.alertModal("封面", `
<img src="${globalinfos.pic}" style="width:100%" onload="this.parentElement.style.width='100%'" />
`, "关闭");
});
config.running.picHC.onhold(() => {
open(globalinfos.pic);
});
pic_span.setAttribute("setup", globalinfos.cid);
}
}
async function feat_showCid() {
const { av_root, infos } = this;
const cid_span = getOrNew("bilibiliShowCID", av_root);
//if (config.showCid) {
cid_span.style.textOverflow = "ellipsis";
cid_span.style.whiteSpace = "nowarp";
cid_span.style.overflow = "hidden";
cid_span.title = "CID:" + infos.cid;
cid_span.innerText = "CID:" + infos.cid;
if (cid_span.getAttribute("setup") != globalinfos.cid) {
config.running.cidspanHC && config.running.cidspanHC.uninstall();
config.running.cidspanHC = new CKTools.HoldClick(cid_span);
config.running.cidspanHC.onclick(() => {
copy(currentPageName);
popNotify.success("CID复制成功", globalinfos.cid);
});
config.running.cidspanHC.onhold(() => {
CKTools.modal.alertModal("CID信息", `
<input readonly style="width:440px" value="${globalinfos.cid}" />
`, "关闭");
});
cid_span.setAttribute("setup", globalinfos.cid);
}
//} else cid_span.remove();
}
async function feat_showSize() {
const { av_root, infos } = this;
const size_span = getOrNew("bilibiliShowSize", av_root);
//if (config.showCid) {
size_span.style.textOverflow = "ellipsis";
size_span.style.whiteSpace = "nowarp";
size_span.style.overflow = "hidden";
size_span.title = `${infos.dimension.width}x${infos.dimension.height}`;
size_span.innerText = `${infos.dimension.width}x${infos.dimension.height}`;
//} else cid_span.remove();
}
async function feat_openGUI() {
const { av_root, infos } = this;
const gui_span = getOrNew("bilibiliShowGUISettings", av_root);
gui_span.innerHTML = "⚙";
gui_span.title = "ShowAV 设置";
gui_span.style.overflow = "hidden";
gui_span.style.cursor = "pointer";
gui_span.onclick = e => GUISettings();
}
async function feat_showArgue() {
const { av_root, infos } = this;
const argue_span = getOrNew("bilibiliShowArgue", av_root);
const original = document.querySelector(".argue.item");
if(!original) argue_span.style.display = "none";
else argue_span.style.display = "block";
argue_span.style.color = "rgb(255, 170, 44)";
argue_span.innerHTML = "<i class='van-icon-info_warning'></i>";
argue_span.title = (original&&original.title)||"警告";
argue_span.style.overflow = "hidden";
}
async function feat_showPn() {
const { av_root, infos } = this;
const pn_span = getOrNew("bilibiliShowPN", av_root);
//if (config.showPn) {
const videoData = infos;
if (!videoData) return;
let part = {
part: 'P' + infos.p
}
try {
part = videoData.pages[infos.p - 1];
} catch (e) {
part = videoData.pages[0];
}
let currentPageName = part.part.length ? part.part : '';
let currentPageNum;
let delimiters;
if (videoData.videos != 1) {
currentPageNum = `P ${infos.p}/${videoData.videos}`;
delimiters = ["\n", " "];
} else {
currentPageNum = "";
delimiters = ["", ""];
}
pn_span.style.textOverflow = "ellipsis";
pn_span.style.whiteSpace = "nowarp";
pn_span.style.overflow = "hidden";
pn_span.title = currentPageNum + delimiters[0] + currentPageName
pn_span.innerText = currentPageNum + delimiters[1] + currentPageName;
if (pn_span.getAttribute("setup") != globalinfos.cid) {
config.running.pnspanHC && config.running.pnspanHC.uninstall();
config.running.pnspanHC = new CKTools.HoldClick(pn_span);
config.running.pnspanHC.onclick(() => {
copy(currentPageName);
popNotify.success("分P标题复制成功", currentPageName);
});
config.running.pnspanHC.onhold(() => {
CKTools.modal.alertModal("分P标题", `
<input readonly style="width:440px" value="${currentPageName}" />
`, "关闭");
});
pn_span.setAttribute("setup", globalinfos.cid);
}
//} else pn_span.remove();
}
async function feat_custom(itemid){
const { av_root, infos } = this;
const that = this;
that.window = unsafeWindow;
const custom_span = getOrNew("bilibili_"+itemid, av_root);
const {partinfo,url,vidurl,shorturl,part,t} = await prepareData(infos);
const parseTxt = txt=>apiBasedVariablesReplacement(txt.mapReplace({
"%timeurl%": url,
"%vidurl%": vidurl,
"%shorturl%": shorturl,
"%seek%": t,
"%title%": infos.title,
"%av%": infos.aid,
"%bv%": infos.bvid,
"%cid%": infos.cid,
"%p%": part,
"%pname%": partinfo.part,
"'": "\'"
}));
if(Object.keys(config.customComponents).includes(itemid)){
const item = config.customComponents[itemid];
let content = item.content;
if(item.content.startsWith("js:")){
content = item.content.replace("js:","");
}
else content = parseTxt(item.content);
custom_span.style.overflow = "hidden";
try{
if(item.title.startsWith("js:")){
let itemtitle = item.title.substr(3);
custom_span.innerHTML = eval(parseTxt(itemtitle));
}else
custom_span.innerHTML = parseTxt(item.title);
}catch(e){
custom_span.innerHTML = parseTxt(item.title);
}
custom_span.title = `自定义组件: ${item.title}\n长按管理自定义组件`;
if(custom_span.getAttribute("setup")!=globalinfos.cid){
custom_span.setAttribute("setup",globalinfos.cid);
config.running[itemid] && config.running[itemid].uninstall();
config.running[itemid] = new CKTools.HoldClick(custom_span);
config.running[itemid].onclick(e => {
console.log(item.content)
if(item.content.startsWith("js:")){
log("executing:",content);
exec(content,that)();
}else{
copy(content);
popNotify.success("已复制"+item.title,content);
}
});
config.running[itemid].onhold(e=>{
GUISettings_customcomponents();
})
}
}else{
log("Errored while handling custom components:",k,"not found");
custom_span.remove();
}
}
function getSideloadModules(){
if(!unsafeWindow.ShowAVModules) return {};
const mods = {};
for(const modName of Object.keys(unsafeWindow.ShowAVModules)){
const mod = unsafeWindow.ShowAVModules[modName];
if(mod&&(typeof(mod.name)==='string')&&(typeof(mod.onload)==='function')&&(typeof(mod.onclick)==='function')&&(typeof(mod.onhold)==='function')){
mods[modName] = mod;
}
}
return mods;
}
function mappedSideloadModules(){
const sideloads = getSideloadModules();
const mods = {};
for(const modName of Object.keys(sideloads)){
mods['sideload_'+modName] = sideloads[modName];
}
return mods;
}
async function runSideloadModule(module,moduleInternalID = (Math.floor(Math.random()*10000))){
let slm_span = null;
try{
const { av_root }=this;
const onloadFn = module.onload.bind(this);
const onclickFn = module.onclick.bind(this);
const onholdFn = module.onhold.bind(this);
const name = "showav_slm_" + moduleInternalID;
slm_span = getOrNew(name, av_root);
slm_span.innerHTML = '';
slm_span.style.textOverflow = "ellipsis";
slm_span.style.whiteSpace = "nowarp";
slm_span.style.overflow = "hidden";
slm_span.title = "模块:" + module.name;
if(module.tip){
if(typeof(module.tip)=='function') slm_span.title+='\n'+module.tip.bind(this)();
else slm_span.title+='\n'+module.tip;
}else if(module.description){
slm_span.title+='\n'+module.description;
}
slm_span.appendChild(await onloadFn(slm_span));
if (slm_span.getAttribute("setup") != globalinfos.cid) {
config.running[name] && config.running[name].uninstall();
config.running[name] = new CKTools.HoldClick(slm_span);
config.running[name].onclick(onclickFn);
config.running[name].onhold(onholdFn);
slm_span.setAttribute("setup", globalinfos.cid);
}
}catch(e){
log('[ERR]',module.name,e);
(slm_span&&(slm_span instanceof HTMLElement)&&slm_span.remove());
}
}
async function tryInject(flag) {
console.log('ShowAV waiting for player ready')
if (flag && config.orders.length === 0) return log('Terminated because no option is enabled.');
if (!(await playerReady())) return log('Can not load player in time.');
if (config.firstTimeLoad) {
registerVideoChangeHandler();
config.firstTimeLoad = false;
}
console.log('ShowAV start inject')
CKTools.addStyle(`.video-container-v1 .copyright.item{display:none!important;}.video-container-v1 .video-info-detail{flex-wrap: wrap!important;}`,"showav_patchNewPlayer","update",document.head);