Repository navigation
Expand file tree
/
Copy pathMagnetic_Assistant.js
More file actions
1378 lines (1274 loc) · 66.4 KB
/
Copy pathMagnetic_Assistant.js
File metadata and controls
1378 lines (1274 loc) · 66.4 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
// ==UserScript==
// @name 磁力&电驴链接助手
// @namespace https://github.com/ZiPenOk
// @version 3.5.8
// @description 点击按钮显示绿色勾(验车按钮除外),支持复制(自动精简链接,保留xt和dn并提取番号)、推送到qB/115,新增磁力信息验车功能,截图轮播。
// @icon https://uxwing.com/wp-content/themes/uxwing/download/seo-marketing/magnet-magnetic-icon.png
// @match *://*/*
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @connect *
// @connect whatslink.info
// @homepageURL https://github.com/ZiPenOk/scripts
// @supportURL https://github.com/ZiPenOk/scripts/issues
// @updateURL https://raw.githubusercontent.com/ZiPenOk/scripts/main/Magnetic_Assistant.js
// @downloadURL https://raw.githubusercontent.com/ZiPenOk/scripts/main/Magnetic_Assistant.js
// @run-at document-start
// ==/UserScript==
(function () {
'use strict';
const config = {
enableCopy: GM_getValue('enableCopy', true),
enableQb: GM_getValue('enableQb', true),
enableBc: GM_getValue('enableBc', false),
enable115: GM_getValue('enable115', false),
enableCheck: GM_getValue('enableCheck', true),
qbtHost: GM_getValue('qbtHost', 'http://127.0.0.1:8080'),
qbtUser: GM_getValue('qbtUser', 'admin'),
qbtPass: GM_getValue('qbtPass', 'adminadmin'),
bcHost: GM_getValue('bcHost', 'http://127.0.0.1:8080'),
bcUser: GM_getValue('bcUser', 'admin'),
bcPass: GM_getValue('bcPass', ''),
bcSavePath: GM_getValue('bcSavePath', ''),
u115Cid: GM_getValue('u115Cid', GM_getValue('u115Uid', '')),
u115Uid: GM_getValue('u115Uid', '')
};
GM_registerMenuCommand("⚙️ 脚本综合设置", showSettingsModal);
const ICONS = {
copy: `<svg viewBox="0 0 24 24" width="14" height="14" fill="#666"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>`,
qb: `<svg viewBox="0 0 24 24" width="14" height="14" fill="#0078d4"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"/></svg>`,
bc: `<svg viewBox="0 0 24 24" width="14" height="14" fill="none"><circle cx="12" cy="12" r="10" fill="#1677ff"/><path d="M8 7h5.2c2 0 3.3 1 3.3 2.6 0 1-.5 1.8-1.4 2.2 1.1.4 1.8 1.2 1.8 2.5 0 1.8-1.4 2.9-3.6 2.9H8V7zm2.2 2v2h2.7c.8 0 1.3-.4 1.3-1s-.5-1-1.3-1h-2.7zm0 3.8v2.4h3c.9 0 1.4-.4 1.4-1.2s-.5-1.2-1.5-1.2h-2.9z" fill="#fff"/></svg>`,
u115: `<svg viewBox="0 0 24 24" width="16" height="16"><circle cx="12" cy="12" r="11" fill="#2777F8"/><text x="12" y="17" font-family="Arial" font-size="12" font-weight="900" fill="white" text-anchor="middle">5</text></svg>`,
car: `<svg viewBox="0 0 24 24" width="14" height="14" fill="#ff9800"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm1-13h-2v6l5.25 3.15L17 12.23l-4-2.37V7z"/></svg>`,
checkActive: `<svg viewBox="0 0 24 24" width="14" height="14" fill="#28a745"><path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/></svg>`
};
const style = document.createElement('style');
style.innerHTML = `
.mag-btn-group {
display: inline-flex !important;
vertical-align: middle !important;
margin-left: 6px !important;
gap: 4px !important;
background: #f8f9fa !important;
padding: 2px 3px !important;
border-radius: 6px !important;
border: 1px solid #dee2e6 !important;
box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
transition: box-shadow 0.2s;
}
.mag-btn-group:hover {
box-shadow: 0 2px 4px rgba(0,0,0,0.08) !important;
}
.mag-btn {
display: flex !important;
align-items: center !important;
justify-content: center !important;
width: 24px !important;
height: 20px !important;
background: #ffffff !important;
border: 1px solid #ced4da !important;
border-radius: 5px !important;
cursor: pointer !important;
transition: all 0.2s ease !important;
box-shadow: 0 1px 1px rgba(0,0,0,0.03) !important;
position: relative;
overflow: hidden;
}
.mag-btn:hover {
background: #e9ecef !important;
border-color: #0078d4 !important;
transform: translateY(-1px);
box-shadow: 0 2px 3px rgba(0,120,212,0.15) !important;
}
.mag-btn.active {
border-color: #28a745 !important;
background: #f0fff4 !important;
box-shadow: 0 0 0 2px rgba(40,167,69,0.2) !important;
}
/* 涟漪效果 */
.mag-btn::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
border-radius: 50%;
background: rgba(0,120,212,0.3);
transform: translate(-50%, -50%);
transition: width 0.3s, height 0.3s;
}
.mag-btn:active::after {
width: 80px;
height: 80px;
}
/* 绿色勾弹入动画 */
@keyframes popIn {
0% { transform: scale(0); opacity: 0; }
80% { transform: scale(1.2); }
100% { transform: scale(1); opacity: 1; }
}
.mag-btn.active svg {
animation: popIn 0.2s ease-out;
}
#jav-nong-table .nong-copy,
#jav-nong-table .nong-check,
#nong-table-new .nong-copy,
#nong-table-new .nong-check {
display: none !important;
pointer-events: none !important;
}
#jav-nong-table .nong-115-head,
#jav-nong-table .nong-115-cell,
#nong-table-new .nong-115-head,
#nong-table-new .nong-115-cell {
display: none !important;
}
#jav-nong-table .nong-op-cell,
#nong-table-new td:nth-child(3) {
min-width: 88px;
text-align: center;
}
#jav-nong-table .nong-op-cell:not(.mag-laosiji-ready-cell)::after,
#nong-table-new td:nth-child(3):not(.mag-laosiji-ready-cell)::after {
content: '';
display: inline-block;
width: 84px;
height: 24px;
border-radius: 7px;
border: 1px solid #e5e7eb;
background: linear-gradient(90deg, #f8fafc 0%, #eef2f7 48%, #f8fafc 100%);
background-size: 180% 100%;
vertical-align: middle;
animation: magLaosijiHold 1.2s ease-in-out infinite;
}
#jav-nong-table td.mag-laosiji-ready-cell::after,
#nong-table-new td.mag-laosiji-ready-cell::after {
content: none !important;
}
@keyframes magLaosijiHold {
0%, 100% { background-position: 0 0; opacity: .62; }
50% { background-position: 100% 0; opacity: .9; }
}
#jav-nong-table .mag-btn-group,
#nong-table-new .mag-btn-group {
margin-left: 0 !important;
gap: 2px !important;
padding: 2px 2px !important;
border-radius: 6px !important;
vertical-align: middle !important;
}
#jav-nong-table .mag-btn,
#nong-table-new .mag-btn {
width: 22px !important;
height: 20px !important;
border-radius: 5px !important;
}
#jav-nong-table .mag-btn svg,
#nong-table-new .mag-btn svg {
width: 13px !important;
height: 13px !important;
}
#jav-nong-table td,
#nong-table-new td {
overflow: hidden;
}
#magnet-table td:first-child .mag-btn-group {
margin-left: 6px !important;
white-space: nowrap !important;
}
#magnets-content .item .magnet-name {
display: flex !important;
align-items: flex-start !important;
gap: 6px !important;
min-width: 0 !important;
}
#magnets-content .item .magnet-name > a[href^="magnet:"] {
flex: 0 1 auto !important;
width: auto !important;
min-width: 0 !important;
max-width: calc(100% - 140px) !important;
}
#magnets-content .item .magnet-name > .mag-btn-group {
flex: 0 0 auto !important;
margin-left: 0 !important;
white-space: nowrap !important;
}
/* 验车弹窗样式 */
.magnet-link {
color: #1b6ad0;
word-break: break-all;
}
.magnet-link:hover {
color: #155a8a;
text-decoration: underline;
}
.ed2k-link {
color: #d63384;
word-break: break-all;
}
.ed2k-link:hover {
color: #b32a69;
text-decoration: underline;
}
.ftp-link {
color: #ffc107;
word-break: break-all;
}
.ftp-link:hover {
color: #e0a800;
text-decoration: underline;
}
.http-link {
color: #28a745;
word-break: break-all;
}
.http-link:hover {
color: #218838;
text-decoration: underline;
}
.whatslink-overlay { position: fixed; inset: 0; z-index: 10000040; display: flex; align-items: center; justify-content: center; padding: 18px; background: transparent; backdrop-filter: none; }
.whatslink-modal, .whatslink-modal.no-shots { position: relative; inset: auto; width: min(1140px,calc(100vw - 36px)); max-width: 1140px; height: auto; max-height: calc(100vh - 36px); display: block; overflow: visible; border: 0; border-radius: 0; background: transparent; box-shadow: none; font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; }
.whatslink-gallery-scene { position: relative; inset: auto; display: grid; grid-template-rows: minmax(0,1fr) auto auto; row-gap: 3px; width: 100%; height: auto; align-items: center; justify-items: center; overflow: hidden; background: transparent; }
.whatslink-gallery-visual { position: relative; z-index: 1; grid-row: 1; width: 100%; height: auto; min-height: 0; margin: 0 !important; display: grid; place-items: center; overflow: hidden; }
.whatslink-gallery-hero { position: relative; z-index: 1; width: 100%; height: 100%; min-height: 0; object-fit: contain; display: block; }
.whatslink-gallery-close { position: absolute; top: 12px; right: 14px; z-index: 4; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; color: #fff; background: rgba(42,45,49,.76); cursor: pointer; padding: 0 0 2px; font-family: Arial,sans-serif; font-size: 23px; line-height: 1; }
.whatslink-gallery-close:hover, .whatslink-gallery-arrow:hover { background: rgba(22,25,28,.92); }
.whatslink-gallery-arrow { position: absolute; top: 50%; z-index: 3; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; transform: translateY(-50%); border: 0; border-radius: 50%; color: #fff; background: rgba(38,42,45,.76); cursor: pointer; padding: 0 0 3px; font-family: Arial,sans-serif; font-size: 27px; line-height: 1; }
.whatslink-gallery-prev { left: 16px; } .whatslink-gallery-next { right: 16px; }
.whatslink-gallery-info { grid-row: 2; position: relative; z-index: 3; margin: 0 !important; min-height: 27px; display: flex; align-items: center; gap: 9px; padding: 5px 12px; border-radius: 4px; color: #fff; background: rgba(38,40,42,.68); font: 14px ui-monospace,SFMono-Regular,Consolas,monospace; font-weight: 600; white-space: nowrap; }
.whatslink-gallery-info span + span::before { content: " · "; margin-right: 8px; color: rgba(255,255,255,.42); }
.whatslink-gallery-thumbs { grid-row: 3; position: relative; z-index: 3; margin: 0 !important; display: flex; justify-content: center; gap: 3px; width: auto; max-width: 100%; padding: 3px; border-radius: 4px; background: rgba(29,31,34,.68); box-shadow: none; }
.whatslink-gallery-thumb { width: 88px; height: 50px; padding: 0; overflow: hidden; border: 2px solid transparent; border-radius: 3px; background: transparent; cursor: pointer; }
.whatslink-gallery-thumb.active { border-color: #e3a05b; }
.whatslink-gallery-thumb img { width: 100%; height: 100%; display: block; object-fit: cover; }
.whatslink-gallery-empty { position: absolute; z-index: 2; display: none; width: min(420px,72%); text-align: center; color: rgba(55,65,81,.78); }
.whatslink-modal.no-shots .whatslink-gallery-empty { display: block; }
.whatslink-modal.no-shots .whatslink-gallery-visual { width: 100%; height: min(460px,calc(100vh - 100px)); }
.whatslink-modal.no-shots .whatslink-gallery-hero, .whatslink-modal.no-shots .whatslink-gallery-arrow, .whatslink-modal.no-shots .whatslink-gallery-thumbs { display: none; }
.whatslink-gallery-empty-icon { width: 56px; height: 56px; margin: 0 auto 14px; display: grid; place-items: center; border: 1px solid rgba(55,65,81,.24); border-radius: 50%; color: #b45309; font-size: 24px; }
.whatslink-gallery-empty-title { margin-bottom: 7px; color: #374151; font-size: 17px; font-weight: 800; }
.whatslink-gallery-empty-text { margin: 0; font-size: 13px; line-height: 1.6; }
.whatslink-loading { color: #374151; font-size: 14px; }
@media (max-width: 768px) {
.whatslink-overlay { padding: 10px; }
.whatslink-modal, .whatslink-modal.no-shots { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); }
.whatslink-gallery-thumb { width: 60px; height: 38px; }
.whatslink-gallery-close { top: 10px; right: 10px; width: 40px; height: 40px; }
.whatslink-gallery-arrow { width: 32px; height: 32px; }
.whatslink-gallery-thumbs { max-width: calc(100% - 16px); overflow: hidden; }
}
/* 深色模式 */
@media (prefers-color-scheme: dark) {
.mag-btn-group {
background: #2d2d2d !important;
border-color: #404040 !important;
}
.mag-btn {
background: #3a3a3a !important;
border-color: #555 !important;
}
.mag-btn:hover {
background: #4a4a4a !important;
border-color: #3399ff !important;
}
.mag-btn.active {
background: #1e3a2a !important;
border-color: #34ce57 !important;
}
.magnet-link { color: #66b0ff; }
.ed2k-link { color: #ff79b0; }
.ftp-link { color: #ffd966; }
.http-link { color: #6fcf97; }
}
`;
(document.head || document.documentElement).appendChild(style);
function showToast(msg, success = true) {
const toast = document.createElement('div');
toast.style.cssText = `position:fixed;bottom:50px;right:30px;background:${success?'#28a745':'#dc3545'};color:white;padding:10px 20px;border-radius:8px;z-index:100000;font-size:14px;box-shadow:0 4px 12px rgba(0,0,0,0.15);`;
toast.textContent = msg;
document.body.appendChild(toast);
setTimeout(() => toast.remove(), 2000);
}
function setBtnActive(clickedBtn, group) {
group.querySelectorAll('.mag-btn').forEach(btn => {
btn.innerHTML = btn.dataset.origIcon;
btn.classList.remove('active');
});
clickedBtn.innerHTML = ICONS.checkActive;
clickedBtn.classList.add('active');
}
function highlightBtn(btn) {
const originalBg = btn.style.backgroundColor;
btn.style.backgroundColor = '#ffb74d';
btn.style.transition = 'background-color 0.2s';
setTimeout(() => {
btn.style.backgroundColor = originalBg;
}, 200);
}
function hasOtherMagnetButtons(target) {
const parent = target.parentElement;
if (!parent) return false;
const otherSelectors = [
'.magnet-combined-button',
'.magnet-button-part',
'.magnet-loading-btn',
'.whatslink-modal'
];
return otherSelectors.some(sel => parent.querySelector(sel));
}
function extractCodeFromText(text) {
if (!text) return null;
const patterns = [
/([A-Z]{2,15})-(\d{2,10})(?:-(\d+))?/i,
/([A-Z]{2,15})-([A-Z]{0,2}\d{2,10})/i,
/FC2[-\s_]?(?:PPV)?[-\s_]?(\d{6,9})/i,
/(\d{6})[-_ ]?(\d{2,3})/,
/([A-Z]{1,2})(\d{3,4})/i
];
for (let i = 0; i < patterns.length; i++) {
const match = text.match(patterns[i]);
if (match) {
if (i === 0) {
return match[3] ? `${match[1]}-${match[2]}-${match[3]}` : `${match[1]}-${match[2]}`;
} else if (i === 1) {
return match[0];
} else if (i === 2) {
return `FC2-PPV-${match[1]}`;
} else if (i === 3) {
return `${match[1]}-${match[2]}`;
} else if (i === 4) {
return match[0];
}
}
}
return null;
}
function GM_Request({ method = "GET", url, data = null, headers = {} }) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method,
url,
headers,
data: data && typeof data === "object" ? JSON.stringify(data) : data,
onload: (res) => {
try {
const contentType = res.responseHeaders || "";
if (contentType.includes("application/json")) {
resolve(JSON.parse(res.responseText));
} else {
resolve(res.responseText);
}
} catch (err) {
reject(err);
}
},
onerror: (err) => reject(err)
});
});
}
async function getMagnetInfo(magnet) {
const url = `https://whatslink.info/api/v1/link?url=${encodeURIComponent(magnet)}`;
try {
return await GM_Request({ method: "GET", url, headers: { "Accept": "application/json" } });
} catch (err) {
console.error("获取磁力信息失败", err);
return null;
}
}
function formatBytes(bytes) {
const num = Number(bytes) || 0;
if (!num) return '-';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let value = num;
let index = 0;
while (value >= 1024 && index < units.length - 1) {
value /= 1024;
index += 1;
}
return `${value.toFixed(index >= 3 ? 2 : 1)} ${units[index]}`;
}
function formatWhatslinkType(payload) {
const raw = String(payload?.file_type || payload?.type || '').toUpperCase();
if (raw.includes('FOLDER')) return '文件夹';
if (raw.includes('FILE')) return '文件';
return '-';
}
function showWhatslinkModal(payload, magnet) {
document.querySelector('.whatslink-overlay')?.remove();
const shots = Array.isArray(payload?.screenshots) ? payload.screenshots.map(item => item?.screenshot).filter(Boolean) : [];
let index = 0;
const resourceName = payload?.name || '未知资源';
const resourceCount = payload?.count ?? '-';
const resourceSize = formatBytes(payload?.size ?? payload?.file_size ?? payload?.fileSize ?? 0);
const overlay = document.createElement('div');
overlay.className = 'whatslink-overlay';
const modal = document.createElement('section');
modal.className = `whatslink-modal${shots.length ? '' : ' no-shots'}`;
modal.innerHTML = `
<div class="whatslink-gallery-scene">
<div class="whatslink-gallery-visual">
<button class="whatslink-gallery-close" type="button" aria-label="关闭">×</button>
<button class="whatslink-gallery-arrow whatslink-gallery-prev" type="button" aria-label="上一张">‹</button>
<img class="whatslink-gallery-hero" alt="截图预览">
<button class="whatslink-gallery-arrow whatslink-gallery-next" type="button" aria-label="下一张">›</button>
<div class="whatslink-gallery-empty">
<div class="whatslink-gallery-empty-icon">?</div>
<div class="whatslink-gallery-empty-title">暂无截图</div>
<p class="whatslink-gallery-empty-text">当前资源没有可展示的截图,可以结合资源名称和文件数量判断。</p>
</div>
</div>
<div class="whatslink-gallery-info">
<span class="whatslink-gallery-name"></span>
<span class="whatslink-gallery-count"></span>
<span class="whatslink-gallery-size"></span>
<span class="whatslink-gallery-index"></span>
</div>
<div class="whatslink-gallery-thumbs"></div>
</div>`;
overlay.appendChild(modal);
document.body.appendChild(overlay);
modal.querySelector('.whatslink-gallery-name').textContent = resourceName;
modal.querySelector('.whatslink-gallery-count').textContent = `${resourceCount} 个文件`;
modal.querySelector('.whatslink-gallery-size').textContent = `大小 ${resourceSize}`;
const visual = modal.querySelector('.whatslink-gallery-visual');
const hero = modal.querySelector('.whatslink-gallery-hero');
const thumbs = modal.querySelector('.whatslink-gallery-thumbs');
const currentIndex = modal.querySelector('.whatslink-gallery-index');
const closeButton = modal.querySelector('.whatslink-gallery-close');
const prevButton = modal.querySelector('.whatslink-gallery-prev');
const nextButton = modal.querySelector('.whatslink-gallery-next');
const sizeGallery = () => {
if (!shots.length || !hero.naturalWidth || !hero.naturalHeight) return;
const infoHeight = modal.querySelector('.whatslink-gallery-info').offsetHeight || 23;
const thumbsHeight = thumbs.offsetHeight || 58;
const maxHeight = Math.max(180, window.innerHeight - 36 - infoHeight - thumbsHeight - 6);
const maxWidth = modal.clientWidth;
const ratio = hero.naturalWidth / hero.naturalHeight;
const height = Math.min(maxHeight, maxWidth / ratio);
const width = height * ratio;
visual.style.width = `${width}px`;
visual.style.height = `${height}px`;
};
const positionControls = () => {
if (!shots.length || !hero.naturalWidth || !hero.naturalHeight) return;
const width = visual.clientWidth;
const height = visual.clientHeight;
const scale = Math.min(width / hero.naturalWidth, height / hero.naturalHeight);
const imageWidth = hero.naturalWidth * scale;
const imageHeight = hero.naturalHeight * scale;
const imageLeft = (width - imageWidth) / 2;
const imageTop = (height - imageHeight) / 2;
const closeSize = closeButton.offsetWidth || 32;
const arrowSize = prevButton.offsetWidth || 34;
const sideGap = 12;
closeButton.style.left = `${imageLeft + imageWidth - closeSize - sideGap}px`;
closeButton.style.right = 'auto';
closeButton.style.top = `${imageTop + sideGap}px`;
prevButton.style.left = `${imageLeft + sideGap}px`;
prevButton.style.right = 'auto';
prevButton.style.top = `${imageTop + (imageHeight - arrowSize) / 2}px`;
nextButton.style.left = 'auto';
nextButton.style.right = `${width - imageLeft - imageWidth + sideGap}px`;
nextButton.style.top = `${imageTop + (imageHeight - arrowSize) / 2}px`;
};
const render = () => {
modal.classList.toggle('has-shots', Boolean(shots.length));
if (!shots.length) {
currentIndex.textContent = 'NO PREVIEW';
return;
}
hero.src = shots[index];
currentIndex.textContent = `${index + 1} / ${shots.length}`;
[...thumbs.children].forEach((btn, i) => btn.classList.toggle('active', i === index));
if (hero.complete) {
sizeGallery();
positionControls();
}
};
shots.forEach((url, i) => {
const btn = document.createElement('button');
btn.type = 'button';
btn.className = 'whatslink-gallery-thumb';
btn.innerHTML = `<img src="${url}" alt="截图${i + 1}">`;
btn.addEventListener('click', () => { index = i; render(); });
thumbs.appendChild(btn);
});
prevButton.addEventListener('click', () => { if (!shots.length) return; index = (index + shots.length - 1) % shots.length; render(); });
nextButton.addEventListener('click', () => { if (!shots.length) return; index = (index + 1) % shots.length; render(); });
const onKeydown = event => {
if (!document.body.contains(overlay)) return;
if (event.key === 'ArrowLeft' && shots.length) { index = (index + shots.length - 1) % shots.length; render(); }
if (event.key === 'ArrowRight' && shots.length) { index = (index + 1) % shots.length; render(); }
if (event.key === 'Escape') close();
};
const onResize = () => { sizeGallery(); positionControls(); };
const close = () => {
overlay.remove();
document.removeEventListener('keydown', onKeydown);
window.removeEventListener('resize', onResize);
};
closeButton.addEventListener('click', close);
overlay.addEventListener('click', e => { if (e.target === overlay) close(); });
overlay.addEventListener('wheel', e => {
e.preventDefault();
}, { passive: false });
visual.addEventListener('wheel', e => {
e.preventDefault();
e.stopPropagation();
if (!shots.length || !e.deltaY) return;
index = (index + (e.deltaY > 0 ? 1 : -1) + shots.length) % shots.length;
render();
}, { passive: false });
hero.addEventListener('load', () => { sizeGallery(); positionControls(); });
window.addEventListener('resize', onResize);
document.addEventListener('keydown', onKeydown);
render();
}
async function handleCheckCar(link, btn) {
highlightBtn(btn);
document.querySelector('.whatslink-overlay')?.remove();
showToast('正在验车...');
const info = await getMagnetInfo(link);
if (!info) {
showToast('验车失败,请稍后重试', false);
return;
}
const shots = Array.isArray(info?.screenshots) ? info.screenshots.filter(item => item?.screenshot) : [];
if (!shots.length) {
showToast(info?.name ? `${info.name} 未找到可显示的截图` : '未找到可显示的截图', false);
return;
}
showWhatslinkModal(info, link);
}
function simplifyMagnetLink(link) {
if (!link.startsWith('magnet:?')) return link;
try {
const paramRegex = /[?&]([^=]+)=([^&]*)/g;
let match;
let xt = null;
let dn = null;
while ((match = paramRegex.exec(link)) !== null) {
const key = match[1];
const value = match[2];
if (key === 'xt') {
xt = value;
} else if (key === 'dn') {
dn = value;
}
}
if (!xt) return link;
let newLink = `magnet:?xt=${xt}`;
if (dn) {
let decodedDn = null;
try {
decodedDn = decodeURIComponent(dn).trim();
} catch (e) {
decodedDn = dn.trim();
}
const code = extractCodeFromText(decodedDn);
if (code) {
newLink += `&dn=${code}`;
} else {
newLink += `&dn=${decodedDn}`;
}
}
return newLink;
} catch (e) {
console.warn('精简磁力链接失败,使用原始链接', e);
return link;
}
}
function createBtnGroup(link) {
link = normalizeSupportedLink(link);
const group = document.createElement('span');
group.className = 'mag-btn-group';
group.dataset.magAssistant = '1';
group.onclick = (e) => { e.preventDefault(); e.stopPropagation(); };
const addBtn = (type, icon, title, action) => {
const btn = document.createElement('div');
btn.className = 'mag-btn';
btn.innerHTML = icon;
btn.title = title;
btn.dataset.origIcon = icon;
btn.onclick = (e) => {
e.stopPropagation();
if (type === 'check') {
action(btn);
} else {
setBtnActive(btn, group);
action();
}
};
group.appendChild(btn);
};
if (config.enableCopy) {
addBtn('copy', ICONS.copy, '复制链接', () => {
const processedLink = simplifyMagnetLink(link);
GM_setClipboard(processedLink, 'text');
if (processedLink !== link) {
showToast('📋 精简链接已复制');
} else {
showToast('📋 链接已复制');
}
});
}
if (config.enableQb) {
addBtn('qb', ICONS.qb, '推送至 qB', () => pushToQb(link));
}
if (config.enableBc) {
addBtn('bc', ICONS.bc, '推送至 BitComet', () => pushToBitComet(link));
}
if (config.enable115) {
addBtn('115', ICONS.u115, '115 离线', () => pushTo115(link));
}
if (config.enableCheck) {
addBtn('check', ICONS.car, '验车', (btn) => handleCheckCar(link, btn));
}
return group;
}
function pushToQb(link) {
GM_xmlhttpRequest({
method: "POST",
url: `${config.qbtHost}/api/v2/auth/login`,
data: `username=${config.qbtUser}&password=${config.qbtPass}`,
headers: { "Content-Type": "application/x-www-form-urlencoded" },
onload: (res) => {
// 登录成功应返回 "Ok."(忽略前后空白)
if (res.status === 200 && res.responseText && res.responseText.trim() === "Ok.") {
GM_xmlhttpRequest({
method: "POST",
url: `${config.qbtHost}/api/v2/torrents/add`,
data: `urls=${encodeURIComponent(link)}`,
headers: { "Content-Type": "application/x-www-form-urlencoded" },
onload: (r) => {
// 添加任务成功返回 "Ok.",失败返回错误信息
if (r.status === 200 && r.responseText && r.responseText.trim() === "Ok.") {
showToast('✅ 已推送到 qB');
} else {
let errorMsg = r.responseText || '未知错误';
if (errorMsg.length > 50) errorMsg = errorMsg.substring(0, 50) + '...';
showToast(`❌ 推送失败: ${errorMsg}`, false);
}
},
onerror: () => showToast('❌ 推送请求失败', false)
});
} else {
showToast('🚫 qB 登录失败,请检查地址或用户名密码', false);
}
},
onerror: () => showToast('❌ 无法连接到 qB,请检查地址', false)
});
}
function get115Cid() {
return (config.u115Cid || config.u115Uid || '').trim();
}
function base64EncodeUtf8(text) {
if (typeof TextEncoder !== 'undefined') {
const bytes = new TextEncoder().encode(text);
let binary = '';
bytes.forEach(byte => { binary += String.fromCharCode(byte); });
return btoa(binary);
}
return btoa(unescape(encodeURIComponent(text)));
}
function getBitCometAuthHeaders(contentType) {
const headers = {};
if (contentType) headers['Content-Type'] = contentType;
const user = (config.bcUser || '').trim();
const pass = config.bcPass || '';
if (user || pass) {
headers.Authorization = `Basic ${base64EncodeUtf8(`${user}:${pass}`)}`;
}
return headers;
}
function normalizeHost(host) {
return String(host || '').trim().replace(/\/+$/, '');
}
function pushToBitComet(link) {
const host = normalizeHost(config.bcHost);
if (!host) {
showToast('❌ BitComet 地址不能为空', false);
return;
}
const savePath = (config.bcSavePath || '').trim();
const data = `url=${encodeURIComponent(link)}${savePath ? `&save_path=${encodeURIComponent(savePath)}` : ''}`;
GM_xmlhttpRequest({
method: "POST",
url: `${host}/panel/task_add_magnet_result`,
data,
headers: getBitCometAuthHeaders('application/x-www-form-urlencoded'),
onload: (res) => {
const text = (res.responseText || '').trim();
const failed = /Add task failed|failed|error|失败|错误/i.test(text);
const success = /Add task succeed|succeeded|success|成功/i.test(text);
if (res.status === 200 && success && !failed) {
showToast('✅ 已推送到 BitComet');
} else {
let errorMsg = text || `HTTP ${res.status}`;
if (errorMsg.length > 50) errorMsg = errorMsg.substring(0, 50) + '...';
showToast(`❌ BitComet 推送失败: ${errorMsg}`, false);
}
},
onerror: () => showToast('❌ 无法连接到 BitComet,请检查地址', false)
});
}
function pushTo115(link) {
GM_xmlhttpRequest({
method: 'GET',
url: 'https://115.com/?ct=offline&ac=space&_=' + Date.now(),
anonymous: false,
headers: {
'Accept': 'application/json, text/plain, */*',
'Origin': 'https://115.com',
'Referer': 'https://115.com/?tab=offline&mode=wangpan'
},
onload: (signResponse) => {
let signInfo = null;
try {
signInfo = JSON.parse(signResponse.responseText);
} catch (_) {}
if (!signInfo || !signInfo.state || !signInfo.sign || !signInfo.time) {
showToast('❌ 115登录失效或签名获取失败', false);
return;
}
const data = new URLSearchParams();
data.set('url', link);
data.set('sign', signInfo.sign);
data.set('time', signInfo.time);
const cid = get115Cid();
if (cid) {
data.set('wp_path_id', cid);
}
GM_xmlhttpRequest({
method: 'POST',
url: 'https://115.com/web/lixian/?ct=lixian&ac=add_task_url',
anonymous: false,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Origin': 'https://115.com',
'Referer': 'https://115.com/?tab=offline&mode=wangpan',
'X-Requested-With': 'XMLHttpRequest'
},
data: data.toString(),
onload: (response) => {
try {
const res = JSON.parse(response.responseText);
if (res.state) {
showToast(cid ? '✅ 已发送到 115 指定目录' : '✅ 已发送到 115');
} else {
showToast('❌ 115错误: ' + (res.error_msg || res.msg || '未知错误'), false);
}
} catch(e) { showToast('❌ 115 响应解析失败', false); }
},
onerror: () => showToast('❌ 115 推送请求失败', false)
});
},
onerror: () => showToast('❌ 115 签名请求失败', false)
});
}
function hideSukebeiNativeLinks(anchor) {
const row = anchor.closest('.torrent-list > tbody > tr');
const cell = anchor.closest('td');
if (!row || !cell) return;
cell.querySelectorAll('a[href^="/download/"], a[href^="magnet:"]').forEach(link => {
link.dataset.magAssistantHiddenNative = '1';
link.style.display = 'none';
});
}
function handleLaosijiTable() {
const table = document.getElementById('jav-nong-table') || document.getElementById('nong-table-new');
if (!table) return;
table.querySelectorAll('.nong-115-head, .nong-115-cell').forEach(el => {
el.style.display = 'none';
});
const rows = table.querySelectorAll('tr[data-maglink], tr.jav-nong-row:not(.nong-head-row)');
rows.forEach(row => {
const cells = row.cells;
if (cells.length < 3) return;
const operationCell = row.querySelector('.nong-op-cell') || cells[2];
if (!operationCell) return;
const magnetLink = row.getAttribute('data-maglink')
|| row.querySelector('td:first-child a[href^="magnet:"]')?.href;
if (!magnetLink) return;
operationCell.querySelectorAll('.nong-copy, .nong-check').forEach(el => el.remove());
if (operationCell.querySelector('.mag-btn-group')) {
operationCell.classList.add('mag-laosiji-ready-cell');
return;
}
const btnGroup = createBtnGroup(magnetLink);
operationCell.appendChild(btnGroup);
operationCell.classList.add('mag-laosiji-ready-cell');
});
}
// These sites expose the same magnet from multiple nested anchors. Mount once per row
// before the generic scanner sees the individual links.
function handleNativeMagnetRows() {
document.querySelectorAll('#magnets-content .item').forEach(row => {
const link = row.querySelector('.magnet-name > a[href^="magnet:"]');
const nameCell = link?.closest('.magnet-name');
if (!link || !nameCell || nameCell.querySelector(':scope > .mag-btn-group')) return;
nameCell.appendChild(createBtnGroup(link.href));
});
document.querySelectorAll('#magnet-table tr').forEach(row => {
const nameCell = row.querySelector(':scope > td:first-child');
const link = nameCell?.querySelector('a[href^="magnet:"]');
if (!link || nameCell.querySelector('.mag-btn-group')) return;
link.after(createBtnGroup(link.href));
});
}
const linkRegexes = {
magnet: /magnet:\?xt=urn:btih:[a-zA-Z0-9]{32,40}[^\s<>"]*/g,
ed2k: /ed2k:\/\/\|file\|[^|]+\|\d+\|[a-fA-F0-9]{32}\|\/?/gi,
ftp: /ftp:\/\/[^\s]+/g
};
function decodeLinkValue(value) {
if (!value) return '';
try {
return decodeURIComponent(value);
} catch (_) {
return value;
}
}
function extractEd2kLink(value) {
const decoded = decodeLinkValue(value || '');
const match = decoded.match(/ed2k:\/\/\|file\|[^|]+\|\d+\|[a-fA-F0-9]{32}\|\/?/i);
return match ? match[0] : null;
}
function normalizeSupportedLink(link) {
if (!link) return link;
if (/^ed2k:/i.test(link)) {
const decoded = decodeLinkValue(link);
return extractEd2kLink(decoded) || decoded;
}
return link;
}
function collectFollowingTextNodes(startNode, maxChars = 4096) {
const chunks = [];
let text = '';
let node = startNode.nextSibling;
while (node && text.length < maxChars) {
if (node.nodeType !== Node.TEXT_NODE) break;
const value = node.nodeValue || '';
chunks.push({ node, value });
text += value;
if (extractEd2kLink(text)) break;
node = node.nextSibling;
}
return { text, chunks };
}
function consumeTextChunks(chunks, count) {
let remaining = count;
for (const chunk of chunks) {
if (remaining <= 0) break;
if (remaining >= chunk.value.length) {
remaining -= chunk.value.length;
chunk.node.remove();
} else {
chunk.node.nodeValue = chunk.value.slice(remaining);
remaining = 0;
}
}
}
function repairSplitEd2kAnchor(anchor) {
const prefixCandidates = [
anchor.textContent,
anchor.getAttribute('href'),
anchor.href
].map(value => decodeLinkValue(value || '').trim()).filter(value => /^ed2k:\/\//i.test(value));
for (const prefix of prefixCandidates) {
const directLink = extractEd2kLink(prefix);
if (directLink) {
anchor.textContent = directLink;
anchor.setAttribute('href', directLink);
anchor.dataset.magRawLink = directLink;
return directLink;
}
const { text, chunks } = collectFollowingTextNodes(anchor);
const fullLink = extractEd2kLink(prefix + text);
if (fullLink && fullLink.startsWith(prefix)) {
anchor.textContent = fullLink;
anchor.setAttribute('href', fullLink);
anchor.dataset.magRawLink = fullLink;
consumeTextChunks(chunks, fullLink.length - prefix.length);
return fullLink;
}
}
return null;
}
function createStyledLink(url, type) {
const a = document.createElement('a');
const normalizedUrl = normalizeSupportedLink(url);
a.setAttribute('href', normalizedUrl);
a.className = `${type}-link`;
a.textContent = normalizedUrl;
a.target = '_blank';
a.rel = 'noopener noreferrer';
a.dataset.magRawLink = normalizedUrl;
return a;
}
function processTextNode(node) {
const parent = node.parentElement;
if (!parent) return null;
const content = node.nodeValue;
const combinedRegex = /(magnet:\?xt=urn:btih:[a-zA-Z0-9]{32,40}[^\s<>"]*|ed2k:\/\/\|file\|[^|]+\|\d+\|[a-fA-F0-9]{32}\|\/?|ftp:\/\/[^\s]+)/gi;
if (!combinedRegex.test(content)) return null;
combinedRegex.lastIndex = 0;
const fragment = document.createDocumentFragment();
let lastIndex = 0;
let match;
while ((match = combinedRegex.exec(content)) !== null) {
if (match.index > lastIndex) {
fragment.appendChild(document.createTextNode(content.slice(lastIndex, match.index)));
}
const url = match[0];
let type = 'http';