-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathu2share_bbcode.user.js
3953 lines (3641 loc) · 210 KB
/
u2share_bbcode.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 U2实时预览BBCODE
// @namespace https://u2.dmhy.org/
// @version 1.1.8
// @description 实时预览BBCODE
// @author kysdm
// @grant GM_xmlhttpRequest
// @connect p.sda1.dev
// @connect sm.ms
// @connect smms.app
// @match *://u2.dmhy.org/*
// @exclude *://u2.dmhy.org/shoutbox.php*
// @icon https://u2.dmhy.org/favicon.ico
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @downloadURL https://github.com/kysdm/u2_share/raw/main/u2share_bbcode.user.js
// @updateURL https://github.com/kysdm/u2_share/raw/main/u2share_bbcode.user.js
// @license Apache-2.0
// ==/UserScript==
/*
本脚本基于 Bamboo Green 界面风格进行修改
为什么会有近似功能的函数呢,问就是历史原因
等不能跑的时候再动祖传代码
/*
/*
GreasyFork 地址
https://greasyfork.org/zh-CN/scripts/426268
*/
/*
更新日志
https://github.com/kysdm/u2_share/commits/main/u2share_bbcode.user.js
*/
'use strict';
(async () => {
// 声明全局变量
// https://api.jquery.com/jQuery.noConflict/
const jq = jQuery.noConflict();
// 网站语言
const lang = new lang_init(jq('#locale_selection').val());;
// CSS
jq('body').append(`<style type="text/css">td.smile-icon { padding: 3px !important; }</style>`);
jq('body').append(`<style type="text/css">.dir_size { color: gray; white-space: nowrap; }</style>`);
// JS
jq('body').append(`<script type="text/javascript">function createTag(name,attribute,content){var components=[];components.push('[');components.push(name);if(attribute!==null){components.push('=');components.push(attribute)}components.push(']');if(content!==null){components.push(content);components.push('[/');components.push(name);components.push(']')}return components.join('')};function replaceText(str,start,end,replacement){return str.substring(0,start)+replacement+str.substring(end)};function addTag(textArea,name,attribute,content,surround){var selStart=textArea.selectionStart;var selEnd=textArea.selectionEnd;if(selStart===null||selEnd===null){selStart=selEnd=textArea.value.length}var selTarget=selStart+name.length+2+(attribute?attribute.length+1:0);if(selStart===selEnd){textArea.value=replaceText(textArea.value,selStart,selEnd,createTag(name,attribute,content))}else{var replacement=null;if(surround){replacement=createTag(name,attribute,textArea.value.substring(selStart,selEnd))}else{replacement=createTag(name,attribute,content)}textArea.value=replaceText(textArea.value,selStart,selEnd,replacement)}textArea.setSelectionRange(selTarget,selTarget)};</script>`);
await loadScript('https://cdnjs.cloudflare.com/ajax/libs/localforage/1.10.0/localforage.min.js')
await loadScript('https://userscript.kysdm.com/js/mediainfo.js?v=1.0')
await loadScript('https://userscript.kysdm.com/js/conversion.js?v=1.0')
// DB
const db = localforage.createInstance({ name: "bbcodejs" });
const attachmap_db = localforage.createInstance({ name: "attachmap" });
const history_db = localforage.createInstance({ name: "history" });
// 现存BBCODE元素
(async () => {
if (jq('.bbcode').length === 0) return; // 判断页面是否存在 bbcode 输入框
new init();
const url = location.href.match(/u2\.dmhy\.org\/(upload|forums|comment|contactstaff|sendmessage|edit)\.php/i);
if (url === null) return;
await syncScroll('#bbcodejs_tbody', url[1], '.bbcode', '#bbcode2');
if (url[1] === 'upload') { await autoSaveUpload(); } else { await autoSaveMessage('#bbcodejs_tbody', '.bbcode', '#qr', url[1], '#compose'); }
jq('.bbcode').parents("tr:eq(1)").after('<tr><td id="preview_bbcode" class="rowhead nowrap" valign="top" style="padding: 3px" align="right">' + lang['preview']
+ '</td><td class="rowfollow"><table width="100%" cellspacing="0" cellpadding="5" border="0" ><tbody><tr><td align="left" colspan="2">'
+ '<div id="bbcode2" style="min-height: 25px; max-height: ' + (jq('.bbcode').height() + 30) + 'px; overflow-x: auto ; overflow-y: auto; white-space: pre-wrap;">'
+ '<div class="child">' + await bbcode2html(jq('.bbcode').val()) + '</div></div></td></tr></tbody></table></td>');
syncWindowChange('.bbcode', '#bbcode2');
jq('.bbcode').bind('input propertychange', async function updateValue() {
let html = await bbcode2html(jq(this).val());
jq('#bbcode2').children('.child').html(html);
});
jq('.codebuttons').click(async function updateValue() {
let html = await bbcode2html(jq('.bbcode').val());
jq('#bbcode2').children('.child').html(html);
});
jq('#compose').find("td.embedded.smile-icon a").each(function () {
jq(this).attr('href', jq(this).attr('href').replace(/javascript: SmileIT\('\[(.+?)\]','[^']+?','[^']+?'\)/gis, function (s, x) { return `javascript:void('${x}');` }));
})
.click(async function () {
onEditorActionBox(jq(this).attr('href'), '.bbcode');
jq('#bbcode2').children('.child').html(await bbcode2html(jq('.bbcode').val()));
});
if (/u2\.dmhy\.org\/upload\.php/i.test(location.href)) {
// 添加中括号
function add_brackets(txt) { if (txt === '') { return ''; } else { return '[' + txt + ']'; } };
// 检查重叠的中括号
function check_title(txt) {
if (/\[{2,}|\]{2,}/g.test(txt)) { return '<font color="red">' + txt + '</font>'; } else { return txt; }
};
var main_title = '<font color="red"><b>' + lang['select_type'] + '</b></font>';
function addMainTitle() {
const custom_title = jq('#custom_title').val();
let type_id = jq('#browsecat').val();
if (custom_title !== '') {
main_title = `<b>${custom_title}</b>`
} else if (type_id === '0') {
main_title = '<font color="red"><b>' + lang['select_type'] + '</b></font>';
} else if (['9', '411', '413', '12', '13', '14', '15', '16', '17', '410', '412'].indexOf(type_id) !== -1) {
main_title = '<b>'
+ add_brackets(jq('#anime_chinese-input').val())
+ add_brackets(jq('#anime_english-input').val())
+ add_brackets(jq('#anime_original-input').val())
+ add_brackets(jq('#anime_source-input').val())
+ add_brackets(jq('#anime_resolution-input').val())
+ add_brackets(jq('#anime_episode-input').val())
+ add_brackets(jq('#anime_container-input').val())
+ add_brackets(jq('#anime_extra-input').val())
+ '</b>';
} else if (['21', '22', '23'].indexOf(type_id) !== -1) {
main_title = '<b>'
+ add_brackets(jq('#manga_title-input').val())
+ add_brackets(jq('#manga_author-input').val())
+ add_brackets(jq('#manga_volume-input').val())
+ add_brackets(jq('#manga_ended').find("select").val())
+ add_brackets(jq('#manga_publisher-input').val())
+ add_brackets(jq('#manga_remark-input').val())
+ '</b>';
} else if (type_id === '30') {
var prefix_1 = jq('#music_prefix').find("select").val();
var prefix_2 = jq('#music_collection').find("select").val();
if (['EAC', 'XLD'].indexOf(prefix_1) !== -1) { var music_quality = false; }
else if (['Hi-Res', 'Web'].indexOf(prefix_1) !== -1) { var music_quality = true; };
switch (prefix_2) {
case "0": // 单张
main_title = '<b>'
+ add_brackets(prefix_1)
+ add_brackets(jq('#music_date-input').val())
+ add_brackets(jq('#music_category-input').val())
+ add_brackets(jq('#music_artist-input').val())
+ add_brackets(jq('#music_title-input').val())
+ add_brackets(jq('#music_serial_number-input').val())
+ add_brackets((() => { if (music_quality) { return jq('#music_quality-input').val(); } else { return ''; } })())
+ add_brackets(jq('#music_format-input').val())
+ '</b>';
break;
case "1": // 合集
main_title = '<b>'
+ add_brackets(prefix_1)
+ add_brackets('合集')
+ add_brackets(jq('#music_category-input').val())
+ add_brackets(jq('#music_title-input').val())
+ add_brackets(jq('#music_quantity-input').val())
+ add_brackets((() => { if (music_quality) { return jq('#music_quality-input').val(); } else { return ''; } })())
+ '</b>';
break;
}
} else if (type_id === '40') {
main_title = '<b>' + jq('#other_title-input').val() + '</b>';
}
jq('#checktitle').html(check_title(main_title));
}
jq("#browsecat").change(() => { new addMainTitle; });
jq(".torrent-info-input").bind('input propertychange', () => { new addMainTitle; });
jq('#other_title').after('<tr><td class="rowhead nowrap" valign="top" align="right">' + lang['main_title'] + '</td>'
+ '<td id="checktitle" class="rowfollow" valign="top" align="left" valign="middle">' + main_title + '</td></tr>'
);
const token = await history_db.getItem('token');
let token_waring = ''
if (token === null || token.length !== 96) {
token_waring = `<span style="color: red">API Token 不存在或无效</span>
<a href="https://greasyfork.org/zh-CN/scripts/428545" style="font-weight: bold; text-decoration: underline; font-style: italic;">鉴权脚本 (安装后打开任意种子页面触发鉴权)</a>`};
jq('#anime_chinese').before(`
<tr>
<td class="rowhead nowrap" valign="top" align="right">引用种子</td>
<td class="rowfollow" valign="top" align="left">
<input type="text" id="copytorrentinfo" size="10">
<button id="copyButton" style="margin-left: 10px; margin-right:10px;">确定</button>
${token_waring}
<br>
输入种子ID,复制该种子的描述信息。
</td>
</tr>
<tr>
<td class="rowhead nowrap" valign="top" align="right">自定义标题</td>
<td class="rowfollow" valign="top" align="left">
<input type="text" id="custom_title" name="custom_title" style="width: 80%;"><br>
除非你确切知道你在做什么,否则请不要在此处输入任何内容。
</td>
</tr>`
)
const browsecat_options = {};
const uid = jq("#info_block a:first").attr("href").match(/id=(\d+)/)[1];
jq("#browsecat option").each(function () {
const text = jq(this).text();
const value = jq(this).val();
browsecat_options[text] = value;
});
jq("#custom_title").bind('input propertychange', () => { new addMainTitle; });
// console.log(browsecat_options);
jq('#copyButton').click(async function (ev) {
ev.preventDefault(); // 阻止表单的提交行为
let tid = jq('#copytorrentinfo').val().trim();;
if (isNaN(tid)) { window.alert('无效种子ID'); return; }
let api = await getApi(token, uid, tid);
if (api.msg !== 'success') { window.alert(`API获取发生错误\n\n${api.msg}`); console.log(api); return; }
let torrents = api.data.history;
if (Object.keys(torrents).length === 0) { window.alert('API没有此种子数据'); return; }
jq("#compose input[id]").map(function () {
// 预先清空所有字段
if (this.id.endsWith("-input") || this.id === 'poster') jq(`#${this.id}`).val('');
jq('#custom_title').val(torrents[0].title)
jq('[name="small_descr"]').val(torrents[0].subtitle);
jq('[name="anidburl"]').val(torrents[0].anidb === null ? '' : `https://anidb.net/anime/${torrents[0].anidb}`);
jq('#browsecat').val(browsecat_options[torrents[0]['category']]);
document.getElementById('browsecat').dispatchEvent(new Event('change')); // 手动触发列表更改事件
jq('.bbcode').val(torrents[0].description_info);
jq('[class^="torrent-info-input"]').trigger("input"); // 手动触发标题更改
jq('.bbcode').trigger("input"); // 手动触发bbcode更改
});
})
// 种子文件
jq('#torrent').parent().html(`
<table style="width: 100%; table-layout:fixed; border: none; cellspacing: none; cellpadding: none;">
<tbody>
<tr>
<td style="width: 430px; border: none;">
<input type="file" accept=".torrent" class="file" style="display: none" id="torrent" name="file">
<input type="file" class="file" style="display: none" id="filechooser">
<input type="file" class="file" style="display: none" id="folderchooser" webkitdirectory>
<input class="codebuttons" id="upload_torrent" style="font-size:11px; margin-right:3px" type="button" value="上传种子" onclick="document.getElementById('torrent').click()">
<input class="codebuttons" id="upload_file" style="font-size:11px; margin-right:3px" type="button" value="单文件制种" onclick="document.getElementById('filechooser').click()" disabled>
<input class="codebuttons" id="upload_folder" style="font-size:11px; margin-right:3px" type="button" value="多文件制种" onclick="document.getElementById('folderchooser').click()" disabled>
<input class="codebuttons" id="torrent_create" style="font-size:11px; margin-right:3px" type="button" value="开始制种" disabled>
<input class="codebuttons" id="torrent_download" style="font-size:11px; margin-right:3px" type="button" value="下载种子" disabled>
<input class="codebuttons" id="torrent_clean" style="font-size:11px; margin-right:3px" type="button" value="清除">
</<td>
<td style="border: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<a id="download_link" style="display: none"></a>
<span id="upload_chooser" style="text-align: left; font-style: italic;"></span>
</<td>
</tr>
</tbody>
</table>
<table style="width: 100%; table-layout:fixed; border: none; cellspacing: none; cellpadding: none;">
<tbody>
<tr>
<td name="progress" style="width: 25%; border: none;">
<div class="progress"><div>
</td>
<td name="progress" style="width: 23%; border: none; text-align: center; font-style: italic;">
<span name="progress-percent"></span>
</td>
<td name="progress" style="width: 8%; border: none; text-align: center; font-style: italic;">
<span name="progress-total"></span>
</td>
<td name="progress" style="border: none; font-style: italic; white-space: nowrap; text-overflow: ellipsis; overflow: hidden;">
<span name="progress-name"></span>
</td>
</tr>
</tbody>
</table>`);
jq('#compose').find("tr:eq(1)").after(`
<tr>
<td class="rowhead nowrap" valign="top" align="right">种子信息</td>
<td class="rowfollow" valign="top" align="left">
<table style="width: 100%; table-layout:fixed; border: none; cellspacing: none; cellpadding: none;">
<tbody>
<tr>
<td style="width: auto; border: none;">
<span id="torrentinfo1" style="text-align: left;">-</span>
<span id="torrentinfo2" style="text-align: left;"></span>
</td>
<td style="width: auto; border: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font id="torrentinfo3" style="color: red; font-weight: bold;"></font>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="rowhead nowrap" valign="top" align="right">种子列表<br>
<span id="expandall" style="font-weight: normal; display: inline;"><a href="javascript: expandall(true)">[全部展开]</a></span>
<span id="closeall" style="font-weight: normal; display: none;"><a href="javascript: expandall(false)">[全部关闭]</a></span>
</td>
<td id="file_tree" class="rowfollow" align="left">
<span id="filelist" style="display: block;">-</span>
</td>
</tr>
`);
await loadScript('https://userscript.kysdm.com/js/torrent-creator.js?v=1.1')
jq('.progress').css({
'width': '99%',
'height': '8px',
'border': '1px solid #ccc',
'border-radius': '5px', // 圆角
'margin': '8px 2px',
'overflow': 'hidden',
});
jq('.progress > div').css({
'width': '0px',
'height': '100%',
'background-color': '#8db8ff',
'transition': 'all 300ms ease'
}); // 设置进度条颜色
jq('[name="progress"]').hide(); // 隐藏进度条
// 显示上传的文件名 & 去除其余上传框内的值
jq('#torrent').change(async function () {
const response = await fetch(URL.createObjectURL(this.files[0]));
const torrent_blob = await response.blob();
console.log(torrent_blob);
await db.setItem(`upload_autoSaveMessageTorrentBlob`, torrent_blob);
await db.setItem(`upload_autoSaveMessageTorrentName`, this.files[0].name);
jq('#upload_chooser').text(this.files[0].name);
jq('#upload_chooser').prop('title', this.files[0].name);
jq('#filechooser').val('');
jq('#folderchooser').val('');
jq('#qr').attr('disabled', false); // 解除上传按钮限制
jq('#torrent_download').attr('disabled', false); // 解除按钮禁用
jq('#upload_torrent,#upload_file,#upload_folder,#torrent_create').attr('disabled', true); // 禁止其余种子处理按钮
await pageTorrentInfo();
});
jq('#filechooser').change(function () {
const encoder = new TextEncoder();
const maxPathName = this.files[0].name;
const maxPathUtf8Bytes = encoder.encode(maxPathName).length;
if (maxPathUtf8Bytes > 230 && !confirm(`文件路径超长,是否继续?\n\n${maxPathUtf8Bytes}\n\n${maxPathName}`)) return;
jq('#upload_chooser').text(this.files[0].name);
jq('#upload_chooser').prop('title', this.files[0].name);
jq('#torrent').val('');
jq('#folderchooser').val('');
});
jq('#folderchooser').change(function () {
const encoder = new TextEncoder();
let maxPathUtf8Bytes = 0;
let maxPathName = new Array();
for (const file of this.files) {
const currentPath = file.webkitRelativePath;
const currentPathUtf8Bytes = encoder.encode(currentPath).length;
if (maxPathUtf8Bytes < currentPathUtf8Bytes) {
maxPathUtf8Bytes = currentPathUtf8Bytes;
maxPathName = [currentPath];
} else if (maxPathUtf8Bytes === currentPathUtf8Bytes) {
maxPathName.push(currentPath);
};
};
if (maxPathUtf8Bytes > 230 && !confirm(`文件路径超长,是否继续?\n\n${maxPathUtf8Bytes}\n\n${maxPathName.join('\n')}`)) return;
jq('#upload_chooser').text((this.files[0].webkitRelativePath).split("/")[0]);
jq('#upload_chooser').prop('title', (this.files[0].webkitRelativePath).split("/")[0]);
jq('#torrent').val('');
jq('#filechooser').val('');
});
jq('#qr').attr('disabled', true); // 未上传种子前,禁止上传按钮
// 种子创建按钮
jq('#torrent_create').click(async function () {
let file = jq('#filechooser')[0].files;
let folder = jq('#folderchooser')[0].files;
if (file.length !== 0) {
torrent_start();
await CreateTorrentFile(file);
await pageTorrentInfo();
} else if (folder.length !== 0) {
torrent_start();
await CreateTorrentFolder(folder);
await pageTorrentInfo();
} else {
window.alert('没有选择任何文件');
return;
};
});
// 清空
jq('#torrent_clean').click(async function () {
jq('#torrent').val('');
jq('#filechooser').val('');
jq('#folderchooser').val('');
jq('#upload_chooser').text('');
jq('#upload_chooser').prop('title', '');
jq('[name="progress"]').hide(); // 隐藏进度条
jq('#upload_torrent,#upload_file,#upload_folder,#torrent_create').attr('disabled', false);
jq('#torrent_download,#qr').attr('disabled', true); // 禁用按钮
jq('.progress > div').css('width', "0%");
jq('[name="progress-total"],[name="progress-name"],[name="progress-percent"]').text('');
jq('#download_link').attr('href', 'javascript:void(0)').attr('download', ''); // 删除下载按钮的URL
await db.removeItem(`upload_autoSaveMessageTorrentBlob`);
await db.removeItem(`upload_autoSaveMessageTorrentName`);
jq('#torrentinfo1').html('-');
jq('#torrentinfo2').html('');
jq('#torrentinfo3').html('');
jq('#file_tree').html('-');
});
var downloadUrl;
jq('#torrent_download').click(async function () {
let a_1 = document.getElementById("download_link");
const blob = await db.getItem(`upload_autoSaveMessageTorrentBlob`);
const filename = await db.getItem(`upload_autoSaveMessageTorrentName`);
window.URL.revokeObjectURL(downloadUrl);
downloadUrl = window.URL.createObjectURL(blob);
a_1.href = downloadUrl;
a_1.download = filename;
a_1.click();
});
const torrent_start = () => {
jq('#upload_torrent,#upload_file,#upload_folder,#torrent_create,#torrent_download,#torrent_clean').attr('disabled', true);
jq('[name="progress"]').show();
};
// 拖拽
jq('#compose > table > tbody > tr:lt(5)').on({
dragenter: function (e) {
e.preventDefault();
e.stopPropagation();
},
dragover: function (e) {
e.preventDefault();
e.stopPropagation();
},
drop: async function (e) {
e.preventDefault();
e.stopPropagation();
// 递归扫描文件夹
const filesList = new Array();
const encoder = new TextEncoder();
const scanFiles = (entry) => {
return new Promise(async (resolve, reject) => {
if (entry.isDirectory) {
const directoryReader = entry.createReader()
const read = () => {
return new Promise((resolve, reject) => {
directoryReader.readEntries(
async (entries) => {
for (let i = 0; i <= entries.length - 1; i++) await scanFiles(entries[i]);
resolve(entries);
},
(e) => {
reject(e)
}
);
});
};
const entries = await read();
if (entries.length > 0) await read();
// console.log('完成读取当前文件夹');
resolve();
} else {
entry.file(
async (file) => {
const path = entry.fullPath.substring(1);
const newFile = Object.defineProperty(file, 'webkitRelativePath', { value: path, });
filesList.push(newFile)
resolve();
},
(e) => {
reject(e)
}
);
};
});
};
let f = e.originalEvent.dataTransfer.files; // 获取文件对象
if (f.length === 0) return false;
if (f.length !== 1) { window.alert('只允许单个文件/文件夹'); return false; };
let items = e.originalEvent.dataTransfer.items;
for (let i = 0; i <= items.length - 1; i++) {
// 实际这个循环只会运行一次 <不允许多文件夹上传>
let item = items[i];
if (item.kind === "file") {
let entry = item.webkitGetAsEntry();
await scanFiles(entry);
};
};
if (filesList.length === 1) {
// 可能是单文件也可能是文件夹内只有一个文件
if (filesList[0].webkitRelativePath === filesList[0].name) {
if (filesList[0].name.toLowerCase().match(/.+\.torrent$/)) {
// console.log('是种子文件');
const response = await fetch(URL.createObjectURL(filesList[0]));
const torrent_blob = await response.blob();
await db.setItem(`upload_autoSaveMessageTorrentBlob`, torrent_blob);
await db.setItem(`upload_autoSaveMessageTorrentName`, filesList[0].name);
jq('#upload_chooser').text(filesList[0].name);
jq('#upload_chooser').prop('title', filesList[0].name);
jq('#qr').attr('disabled', false); // 解除上传按钮锁定
jq('#torrent_download').attr('disabled', false); // 解除按钮禁用
jq('#upload_torrent,#upload_file,#upload_folder,#torrent_create').attr('disabled', true); // 禁止其余种子处理按钮
await pageTorrentInfo();
} else {
// console.log('是普通单文件');
const maxPathName = filesList[0].name;
const maxPathUtf8Bytes = encoder.encode(maxPathName).length;
if (maxPathUtf8Bytes > 230 && !confirm(`文件路径超长,是否继续?\n\n${maxPathUtf8Bytes}\n\n${maxPathName}`)) return;
jq('#upload_chooser').text(filesList[0].name);
jq('#upload_chooser').prop('title', filesList[0].name);
torrent_start();
await CreateTorrentFile(filesList);
jq('#qr').attr('disabled', false);
jq('#torrent_download').attr('disabled', false);
await pageTorrentInfo();
};
} else {
// console.log('文件夹内有一个文件');
const maxPathName = filesList[0].webkitRelativePath
const maxPathUtf8Bytes = encoder.encode(maxPathName).length;
if (maxPathUtf8Bytes > 230 && !confirm(`文件路径超长,是否继续?\n\n${maxPathUtf8Bytes}\n\n${maxPathName}`)) return;
jq('#upload_chooser').text((filesList[0].webkitRelativePath).split("/")[0]);
jq('#upload_chooser').prop('title', (filesList[0].webkitRelativePath).split("/")[0]);
torrent_start();
await CreateTorrentFolder(filesList);
jq('#qr').attr('disabled', false);
jq('#torrent_download').attr('disabled', false);
await pageTorrentInfo();
};
} else {
// console.log('文件夹内有多个文件');
let maxPathUtf8Bytes = 0;
let maxPathName = new Array();
for (const file of filesList) {
const currentPath = file.webkitRelativePath;
const currentPathUtf8Bytes = encoder.encode(currentPath).length;
if (maxPathUtf8Bytes < currentPathUtf8Bytes) {
maxPathUtf8Bytes = currentPathUtf8Bytes;
maxPathName = [currentPath];
} else if (maxPathUtf8Bytes === currentPathUtf8Bytes) {
maxPathName.push(currentPath);
};
};
if (maxPathUtf8Bytes > 230 && !confirm(`文件路径超长,是否继续?\n\n${maxPathUtf8Bytes}\n\n${maxPathName.join('\n')}`)) return;
jq('#upload_chooser').text((filesList[0].webkitRelativePath).split("/")[0]);
jq('#upload_chooser').prop('title', (filesList[0].webkitRelativePath).split("/")[0]);
torrent_start();
await CreateTorrentFolder(filesList);
jq('#qr').attr('disabled', false);
jq('#torrent_download').attr('disabled', false);
await pageTorrentInfo();
};
}
});
jq('#qr').click(async function (e) {
e.preventDefault();
this.disabled = true; // 禁止按钮重复点击
const torrentBlob = await db.getItem(`upload_autoSaveMessageTorrentBlob`);
if (torrentBlob === null || typeof torrentBlob === 'undefined') {
window.alert('种子文件不存在,在其他页面点击清除按钮了?');
return;
}
console.log(new File([torrentBlob], "a.torrent", { type: "application/octet-stream" }));
const p = () => {
return new Promise(function (resolve, reject) {
// https://developer.mozilla.org/zh-CN/docs/Web/API/FormData
let formdata = new FormData(document.getElementById('compose'));
// 处理自定义标题的结构
let customTitle = formdata.get("custom_title");
if (!isWhitespace(customTitle)) {
// 自定义标题中有数据时
const category = formdata.get("type");
customTitle = customTitle.replace(/^\[|\]$/g, ''); // 去除自定义标题两边的括号,提交后系统会自动补全
if (['9', '411', '413', '12', '13', '14', '15', '16', '17', '410', '412'].includes(category)) {
for (let pair of formdata.entries()) if (pair[0].startsWith('anime_')) formdata.set(pair[0], '');
formdata.set("anime_chinese", customTitle);
} else if (['21', '22', '23'].includes(category)) {
for (let pair of formdata.entries()) if (pair[0].startsWith('manga_')) formdata.set(pair[0], '');
formdata.set("manga_title", customTitle);
} else if (category === '30') {
for (let pair of formdata.entries()) if (pair[0].startsWith('music_')) formdata.set(pair[0], '');
formdata.set("music_title", customTitle);
} else if (category === '40') {
formdata.set("other_title", customTitle);
}
}
if (torrentBlob) formdata.set("file", new File([torrentBlob], "a.torrent", { type: "application/octet-stream" }));
const request = new XMLHttpRequest();
request.open("POST", "takeupload.php");
request.timeout = 5000; // 超时时间 单位毫秒
request.onload = function () {
if (request.status >= 200 && request.status < 300) {
resolve({
status: request.status,
response: request.response,
responseURL: request.responseURL
});
} else {
reject({
status: request.status,
statusText: request.statusText
});
};
};
request.onerror = function () {
reject({
status: request.status,
statusText: request.statusText
});
};
request.ontimeout = function () {
reject({
status: 408,
statusText: "Request timed out"
});
};
request.send(formdata);
});
};
p().then(async r => {
if (!r.responseURL.includes("takeupload.php")) {
// 成功上传
// console.log('成功上传');
clearInterval(jq(`#upload_auto_save_text`).attr('title')); // 停止自动保存
await db.removeItem(`upload_autoSaveMessageTime`);
await db.removeItem(`upload_autoSaveMessageBbcode`);
await db.removeItem(`upload_autoSaveMessageSmallDescr`);
await db.removeItem(`upload_autoSaveMessagePoster`);
await db.removeItem(`upload_autoSaveMessageAnidbUrl`);
await db.removeItem(`upload_autoSaveMessageInfo`);
await db.removeItem(`upload_autoSaveMessageTorrentBlob`);
await db.removeItem(`upload_autoSaveMessageTorrentName`);
// console.log(`upload-已清空保存的记录`);
window.open(r.responseURL, '_self');
return;
};
const h = document.createElement('div');
h.innerHTML = r.response;
let warn = jq(h).find('#outer').text();
warn = warn ? warn.trim() : warn;
window.alert(warn)
console.log(warn);
this.disabled = false; // 解除按钮禁止点击
}).catch(e => {
console.error(e);
window.alert('上传发生错误\n' + e)
this.disabled = false; // 解除按钮禁止点击
});
});
};
function init() {
const type = 'original';
let h1 = jq('.codebuttons').eq(6).parent().html();
let h2 = jq('.codebuttons').eq(7).parent().html();
let h3 = jq('.codebuttons').eq(8).parent().html();
jq('.codebuttons').eq(8).parent().remove();
jq('.codebuttons').eq(7).parent().remove();
jq('.codebuttons').eq(6).parent().remove();
jq('input[value="URL"]').parent().remove();
jq('input[value="IMG"]').parent()
.before(`<td class="embedded"><input class="codebuttons" style="text-decoration: line-through; margin-right:3px" type="button" value="S" name="${type}_bbcode_button"></td>`)
.before(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="URL*" name="${type}_bbcode_button"></td>`)
.after(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="CODE" name="${type}_bbcode_button"></td>`)
.after(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="PRE" name="${type}_bbcode_button"></td>`)
.after(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="LIST" name="${type}_bbcode_button"></td>`)
.after(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="RT*" name="${type}_bbcode_button"></td>`)
.after(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="IMGINK" name="${type}_bbcode_button"></td>`);
jq('input[value="QUOTE"]').parent()
.after(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="SPOILER*" name="${type}_bbcode_button"></td>`)
.after(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="SPOILER" name="${type}_bbcode_button"></td>`)
.after(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="MEDIAINFO" name="${type}_bbcode_button"></td>`)
.after(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="INFO" name="${type}_bbcode_button"></td>`)
.after(`<td class="embedded"><input class="codebuttons" style="font-size:11px;margin-right:3px" type="button" value="QUOTE*" name="${type}_bbcode_button"></td>`);
jq('.codebuttons').parents('table').eq(0).after('<div id="bbcodejs_tbody" style="position:relative; margin-top: 4px"></div>');
jq('#bbcodejs_tbody').append('<div id="bbcodejs_select" style="position: absolute; margin-top:2px; margin-bottom:2px; float: left;">' + h1 + h2 + h3 + '</div>');
const margin = jq('.codebuttons').parents('tbody').eq(0).width() - jq("#bbcodejs_select").width() - 2.6;
jq("#bbcodejs_select").css("margin-left", margin + "px");
jq(`[name="${type}_bbcode_button"]`).click(function () { onEditorActionBox(this.value, `.bbcode`); });
}
})();
async function bbcode2html(bbcodestr) {
var tempCode = new Array();
var tempCodeCount = 0;
let lost_tags = new Array();
function addTempCode(value) {
tempCode[tempCodeCount] = value;
let returnstr = "<tempCode_" + tempCodeCount + ">";
tempCodeCount++;
return returnstr;
};
const escape_reg = new RegExp("[&\"\'<>]", "g");
bbcodestr = bbcodestr.replace(escape_reg, function (s, x) {
switch (s) {
case '&':
return '&';
case '"':
return '"';
case "'":
return ''';
case '<':
return '<';
case '>':
return '>';
default:
return s;
};
});
bbcodestr = bbcodestr.replace(/\r\n/g, () => { return '<br>' });
bbcodestr = bbcodestr.replace(/\n/g, () => { return '<br>' });
bbcodestr = bbcodestr.replace(/\r/g, () => { return '<br>' });
bbcodestr = bbcodestr.replace(/ /g, ' ');
let br_end = ''; // 对结尾的换行符进行计数
let br;
if (br = bbcodestr.match(/(?:<br>)+$/)) {
br_end = br[0];
const regex = new RegExp(`${br_end}$`, "");
bbcodestr = bbcodestr.replace(regex, '');
};
const checkLostTags = (value, r_tag_start, r_tag_end) => {
let state = false;
let r_tag_start_exec = r_tag_start.exec(value);
let index_start = r_tag_start_exec ? (r_tag_start_exec.index + r_tag_start_exec[0].length) : 0;
let r_tag_end_exec = r_tag_end.exec(value.slice(index_start));
if (r_tag_start_exec && !r_tag_end_exec) {
let tag_start_val = r_tag_start_exec.groups.tag;;
console.log('检测到丢失的标签 => ' + `[/${tag_start_val}]`);
lost_tags.push(`[/${tag_start_val}]`);
state = true;
};
return { "state": state };
};
const url = (val, textarea) => {
if (val === '=' || val === '="' || val === '=""') { textarea = textarea.replace(/\[url=.(?:"){0,2}\]/i, function (s) { return '[url]'; }); }
if (val) {
const lost = checkLostTags(textarea, /\[(?<tag>url)=[^\[]*?/i, /\[\/(?<tag>url)\]/i);
if (lost.state) { return textarea.replace(/\[url=[^\[]*?/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[url=(.+?)\](.*?)\[\/url\]/i, function (all, url, text) {
if (url.match(/\s|\[/)) return addTempCode(all);
let tmp = url.replace(/^(?:")?(.*?)(?:")?$/, "$1");
if (!tmp.match(/"/)) url = tmp;
else { if (url.match(/"/g).length === 1) url = url.replace('"', ''); }
return addTempCode('<a class="faqlink" rel="nofollow noopener noreferer" href="' + url.replace(/"/g, '"') + '">' + text + '</a>');
});
} else {
const lost = checkLostTags(textarea, /\[(?<tag>url)\]/i, /\[\/(?<tag>url)\]/i);
if (lost.state) { return textarea.replace(/\[url\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[url\](.+?)\[\/url\]/i, function (s, x) {
if (x.match(/\s|\[/i)) return addTempCode(s);
return addTempCode('<a class="faqlink" rel="nofollow noopener noreferer" href="' + x + '">' + x + '</a>');
});
};
};
// 注释
const rt = (val, textarea) => {
if (val === '=' || val === '="' || val === '=""') { return textarea.replace(/\[rt=.*?\]/i, function (s) { return addTempCode(s); }); }
else if (!val) { return textarea.replace('[rt]', function (s) { return addTempCode(s); }) }
else {
const lost = checkLostTags(textarea, /\[(?<tag>rt)=[^\[]*?/i, /\[\/(?<tag>rt)\]/i);
if (lost.state) { return textarea.replace(/\[rt=[^\[]*?/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[rt=(.+?)\](.*?)\[\/rt\]/i, function (all, tval, text) {
if (tval.match(/\[/i)) return addTempCode(all);
let tmp = tval.replace(/^(?:")?(.*?)(?:")?$/, "$1");
if (!tmp.match(/"/)) tval = tmp;
return addTempCode('<ruby>' + text + '<rp>(</rp><rt>' + tval + '</rt><rp>)</rp></ruby>');
});
};
};
// 字体
const font = (val, textarea) => {
if (val === '=' || val === '="' || val === '=""') { return textarea.replace(/\[font=.*?]/i, function (s) { return addTempCode(s); }); }
else if (!val) { return textarea.replace('[font]', function (s) { return addTempCode(s); }) }
else {
const lost = checkLostTags(textarea, /\[(?<tag>font)=[^\[]*?\]/i, /\[\/(?<tag>font)\]/i);
if (lost.state) { return textarea.replace(/\[font=[^\[]*?/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[font=(.+?)\](.*?)\[\/font\]/i, function (all, tval, text) {
if (tval.match(/\[/i)) return '[' + addTempCode(`font=`) + `${tval}]${text}`;
let tmp = tval.replace(/^(?:")?(.*?)(?:")?$/, "$1");
if (!/"/.test(tmp)) { tval = tmp; }
else { if (tval.match(/"/g).length === 1) tval = tval.replace('"', ''); };
return '<span style="font-family: ' + tval + '">' + text + '</span>';
});
};
};
// 颜色
const color = (val, textarea) => {
if (val === '=' || val === '="' || val === '=""') { return textarea.replace(/\[color=.*?\]/i, function (s) { return addTempCode(s); }); }
else if (!val) { return textarea.replace('[color]', function (s) { return addTempCode(s); }) }
else {
const lost = checkLostTags(textarea, /\[(?<tag>color)=[^\[]*?\]/i, /\[\/(?<tag>color)\]/i);
if (lost.state) { return textarea.replace(/\[color=[^\[]*?\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[color=(.+?)\](.*?)\[\/color\]/i, function (all, tval, text) {
if (tval.match(/\[/i)) return addTempCode(all);;
let tmp = tval.replace(/^(?:")?(.*?)(?:")?$/, "$1");
if (!/"/.test(tmp)) { tval = tmp; }
else { if (tval.match(/"/g).length === 1) tval = tval.replace('"', ''); };
return '<span style="color: ' + tval + '">' + text + '</span>';
});
};
};
// 文字大小
const size = (val, textarea) => {
if (val === '=' || val === '="' || val === '=""') { return textarea.replace(/\[size=.*?\]/i, function (s) { return addTempCode(s); }); }
else if (!val) { return textarea.replace('[size]', function (s) { return addTempCode(s); }) }
else {
const lost = checkLostTags(textarea, /\[(?<tag>size)=[^\[]*?\]/i, /\[\/(?<tag>size)\]/i);
if (lost.state) { return textarea.replace(/\[size=[^\[]*?\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[size=(.+?)\](.*?)\[\/size\]/i, function (all, tval, text) {
// size只允许1-9的数字
if (!tval.match(/^(?:")?[0-9](?:")?$/)) return addTempCode(all);
let tmp = tval.replace(/^(?:")?(.*?)(?:")?$/, "$1");
if (!/"/.test(tmp)) { tval = tmp; }
else { if (tval.match(/"/g).length === 1) tval = tval.replace('"', ''); };
return '<font size="' + tval + '">' + text + '</font>';
});
};
};
const pre = (val, textarea) => {
if (val) { return textarea.replace(/\[pre=(.*?)\]/i, function (s, v) { return addTempCode('[pre=') + v + ']'; }); };
const lost = checkLostTags(textarea, /\[(?<tag>pre)\]/i, /\[\/(?<tag>pre)\]/i);
if (lost.state) { return textarea.replace(/\[pre\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[pre\](.*?)\[\/pre\]/i, function (all, text) { return '<pre>' + text + '</pre>'; });
};
const b = (val, textarea) => {
if (val) { return textarea.replace(/\[b=(.*?)\]/i, function (s, v) { return addTempCode('[b=') + v + ']'; }); };
const lost = checkLostTags(textarea, /\[(?<tag>b)\]/i, /\[\/(?<tag>b)\]/i);
if (lost.state) { return textarea.replace(/\[b\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[b\](.*?)\[\/b\]/i, function (all, text) { return '<b>' + text + '</b>'; });
};
const i = (val, textarea) => {
if (val) { return textarea.replace(/\[i=(.*?)\]/i, function (s, v) { return addTempCode('[i=') + v + ']'; }); };
const lost = checkLostTags(textarea, /\[(?<tag>i)\]/i, /\[\/(?<tag>i)\]/i);
if (lost.state) { return textarea.replace(/\[i\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[i\](.*?)\[\/i\]/i, function (all, text) { return '<em>' + text + '</em>'; });
};
const u = (val, textarea) => {
if (val) { return textarea.replace(/\[u=(.*?)\]/i, function (s, v) { return addTempCode('[u=') + v + ']'; }); };
const lost = checkLostTags(textarea, /\[(?<tag>u)\]/i, /\[\/(?<tag>u)\]/i);
if (lost.state) { return textarea.replace(/\[u\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[u\](.*?)\[\/u\]/i, function (all, text) { return '<u>' + text + '</u>'; });
};
const s = (val, textarea) => {
if (val) { return textarea.replace(/\[s=(.*?)\]/i, function (s, v) { return addTempCode('[s=') + v + ']'; }); };
const lost = checkLostTags(textarea, /\[(?<tag>s)\]/i, /\[\/(?<tag>s)\]/i);
if (lost.state) { return textarea.replace(/\[s\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[s\](.*?)\[\/s\]/i, function (all, text) { return '<s>' + text + '</s>'; });
};
const img = (val, textarea) => {
if (val === '=' || val === '="' || val === '=""') { return textarea.replace(/\[img=.*?\]/i, function (s) { return addTempCode(s); }); }
else if (val) {
return textarea.replace(/\[img=(.*?)\]/i, function (all, url) {
// [img=http://u2.dmhy.org/pic/logo.png]
url = url.replace('&', '&');
if (/^((?!"|'|>|<|;|#).)+\.(?:png|jpg|jpeg|gif|svg|bmp|webp)$/i.test(url)) {
// url 以 .png 之类结尾
return addTempCode('<img alt="image" src="' + url + '" style="height: auto; width: auto; max-width: 100%;">');
} else {
return addTempCode(all);
};
});
} else {
// [img]http://u2.dmhy.org/pic/logo.png[/img]
const lost = checkLostTags(textarea, /\[(?<tag>img)\]/i, /\[\/(?<tag>img)\]/i);
if (lost.state) { return textarea.replace(/\[img\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[img\](.*?)\[\/img\]/i, function (all, url) {
url = url.replace('&', '&');
if (/^((?!"|'|>|<|;|#).)+\.(?:png|jpg|jpeg|gif|svg|bmp|webp)$/i.test(url)) {
// url 以 .png 之类结尾
return addTempCode('<img alt="image" src="' + url + '" style="height: auto; width: auto; max-width: 100%;">');
} else {
return addTempCode(all);
};
});
};
};
const imglnk = (val, textarea) => {
if (val === '=' || val === '="' || val === '=""') { return textarea.replace(/\[imglnk=.*?\]/i, function (s) { return addTempCode(s); }); }
else if (val) {
return textarea.replace(/\[imglnk=(.*?)\]/i, function (all, url) { return addTempCode('[imglnk=') + url + ']'; });
} else {
// [img]http://u2.dmhy.org/pic/logo.png[/img]
const lost = checkLostTags(textarea, /\[(?<tag>imglnk)\]/i, /\[\/(?<tag>imglnk)\]/i);
if (lost.state) { return textarea.replace(/\[imglnk\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[imglnk\](.*?)\[\/imglnk\]/i, function (all, url) {
url = url.replace('&', '&');
if (/^((?!"|'|>|<|;|\[|\]|#).)+\.(?:png|jpg|jpeg|gif|svg|bmp|webp)$/i.test(url)) {
// url 以 .png 之类结尾
return addTempCode(`<a class="faqlink" rel="nofollow noopener noreferer" href="' + y + '"><img alt="image" src="${url}" style="height: auto; width: auto; max-width: 100%;"></a>`);
} else {
return addTempCode(all);
};
});
};
};
const code = (val, textarea) => {
if (val === '=' || val === '="' || val === '=""') { textarea = textarea.replace(/\[code=(?:"){0,2}/, '[code]'); };
if (val) { textarea = textarea.replace(/\[code=(.*?)\]/i, function (s, v) { return addTempCode('[code=') + v + ']'; }); };
const lost = checkLostTags(textarea, /\[(?<tag>code)\]/i, /\[\/(?<tag>code)\]/i);
if (lost.state) { return textarea.replace(/\[code\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[code\](.*?)\[\/code\]/i, function (all, text) {
return addTempCode(`<br><div class="codetop">${lang['code']}</div><div class="codemain">${text.replace(/ /g, ' ')}</div><br />`);
});
};
const info = (val, textarea) => {
if (val === '=' || val === '="' || val === '=""') { textarea = textarea.replace(/\[info=(?:"){0,2}/, '[info]'); };
if (val) { textarea = textarea.replace(/\[info=(.*?)\]/i, function (s, v) { return addTempCode('[info=') + v + ']'; }); };
const lost = checkLostTags(textarea, /\[(?<tag>info)\]/i, /\[\/(?<tag>info)\]/i);
if (lost.state) { return textarea.replace(/\[info\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[info\](.*?)\[\/info\]/i, function (all, text) {
return addTempCode(`<fieldset class="pre"><legend><b><span style="color: blue">${lang['info']}</span></b></legend>${text.replace(/ /g, ' ')}</fieldset>`);
});
};
const mediainfo = (val, textarea) => {
if (val === '=' || val === '="' || val === '=""') { textarea = textarea.replace(/\[mediainfo=(?:"){0,2}/, '[mediainfo]'); };
if (val) { textarea = textarea.replace(/\[mediainfo=(.*?)\]/i, function (s, v) { return addTempCode('[mediainfo=') + v + ']'; }); };
const lost = checkLostTags(textarea, /\[(?<tag>mediainfo)\]/i, /\[\/(?<tag>mediainfo)\]/i);
if (lost.state) { return textarea.replace(/\[mediainfo\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[mediainfo\](.*?)\[\/mediainfo\]/i, function (all, text) {
return addTempCode(`<fieldset class="pre"><legend><b><span style="color: red">${lang['mediainfo']}</span></b></legend>${text.replace(/ /g, ' ')}</fieldset>`);
});
};
const quote = (val, textarea) => {
if (!val) {
// [quote]我爱U2分享園@動漫花園。[/quote]
const lost = checkLostTags(textarea, /\[(?<tag>quote)]/i, /\[\/(?<tag>quote)\]/i);
if (lost.state) { return textarea.replace(/\[quote\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[quote\](.*?)\[\/quote\]/i, function (s, x) {
return '<fieldset><legend>' + lang['quote'] + '</legend>' + x.replace(/(<br>)*$/, '') + '</fieldset>';
});
} else if (val === '=' || val === '="' || val === '=""') {
// [quote=""]我爱U2分享園@動漫花園。[/quote]
const lost = checkLostTags(textarea, /\[(?<tag>quote)=[^\[]*?\]/i, /\[\/(?<tag>quote)\]/i);
if (lost.state) { return textarea.replace(/\[quote=[^\[]*?\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[quote=[^\[]*?\](.*?)\[\/quote\]/i, function (s, x) {
return '<fieldset><legend>' + lang['quote'] + '</legend>' + x.replace(/(<br>)*$/, '') + '</fieldset>';
});
} else {
// [quote="ABC"]我爱U2分享園@動漫花園。[/quote]
const lost = checkLostTags(textarea, /\[(?<tag>quote)=[^\[]*?\]/i, /\[\/(?<tag>quote)\]/i);
if (lost.state) { return textarea.replace(/\[quote=[^\[]*?\]/i, function (s) { return addTempCode(s); }); };
return textarea.replace(/\[quote=([^\[]*?)\](.*?)\[\/quote\]/i, function (all, tval, text) {