-
Notifications
You must be signed in to change notification settings - Fork 5
/
renderer.js
2132 lines (1799 loc) · 73.4 KB
/
renderer.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
const BackgroundSaveBtnHtml = `
<div
id="backgroundSave"
class="customBtn"
style="app-region: no-drag; display: flex; height: 24px; justify-content: center; margin-bottom: 16px;margin-left:2px;"
>
<i style="display: inline-flex; justify-content: center; align-items: center; color: var(--icon_primary)">
<svg width="24" height="24" t="1707242102031" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1469" xmlns:xlink="http://www.w3.org/1999/xlink">
<path fill="currentColor" d="M682.752 627.894857L571.904 544.914286a47.725714 47.725714 0 0 0-57.014857 0l-97.572572 73.142857-130.084571-104.082286a47.286857 47.286857 0 0 0-56.246857-2.377143l-131.035429 88.137143V246.345143h696.832v238.738286a31.670857 31.670857 0 0 0 63.341715 0v-241.371429A60.745143 60.745143 0 0 0 799.451429 182.857143H97.28A60.745143 60.745143 0 0 0 36.571429 243.529143V819.2a60.745143 60.745143 0 0 0 60.672 60.672h477.805714a31.670857 31.670857 0 1 0 0-63.341714H99.913143v-140.397715l156.745143-105.398857 159.378285 127.488 127.305143-95.488 101.339429 75.995429a31.670857 31.670857 0 1 0 37.997714-50.688z" p-id="1470">
</path>
<path fill="currentColor" d="M543.378286 404.662857a95.085714 95.085714 0 1 0 95.085714-95.085714 95.085714 95.085714 0 0 0-95.085714 95.085714z m126.72 0a31.670857 31.670857 0 1 1-31.670857-31.670857 31.707429 31.707429 0 0 1 31.670857 31.670857z" p-id="1471">
</path>
<path fill="currentColor" d="M891.245714 829.513143l-21.174857 21.174857v-221.586286a29.257143 29.257143 0 1 0-58.514286 0v221.732572l-21.174857-21.174857a29.257143 29.257143 0 0 0-41.508571 0 29.257143 29.257143 0 0 0 0 41.398857l71.168 71.168 1.097143 1.024c0.182857 0 0.292571 0.292571 0.475428 0.365714a3.949714 3.949714 0 0 0 0.658286 0.548571l0.658286 0.548572c0.182857 0 0.292571 0.292571 0.475428 0.365714l0.731429 0.548572 0.475428 0.292571a3.657143 3.657143 0 0 0 0.841143 0.475429l0.475429 0.292571 0.841143 0.475429 0.475428 0.292571c0.292571 0 0.475429 0.292571 0.731429 0.365714l0.548571 0.292572 0.731429 0.292571 0.658286 0.292572 0.658285 0.292571 0.731429 0.292571 0.548571 0.182858 0.841143 0.292571a0.841143 0.841143 0 0 0 0.475429 0l0.914285 0.292571h0.475429a3.218286 3.218286 0 0 0 0.914286 0.182858h0.475428c0.182857 0 0.658286 0 0.914286 0.182857a1.170286 1.170286 0 0 1 0.548571 0h0.914286a145795831155.78513 145795831155.78513 0 0 1 1.462857 0.182857h2.925715a151002825111.04 151002825111.04 0 0 1 1.462857-0.182857h0.914285a1.170286 1.170286 0 0 0 0.548572 0c0.292571 0 0.658286 0 0.914286-0.182857s0.292571 0 0.475428 0 0.658286 0 0.914286-0.182858h0.475428l0.914286-0.292571h0.475429l0.841143-0.292571 0.548571-0.182858 0.731429-0.292571 0.658285-0.292571 0.658286-0.292572 0.731429-0.292571 0.548571-0.292572c0.292571 0 0.475429-0.292571 0.731429-0.365714l0.475428-0.292571 0.841143-0.475429 0.475429-0.292571a3.657143 3.657143 0 0 1 0.841142-0.475429l0.475429-0.292571 0.731429-0.548572c0.182857 0 0.292571-0.292571 0.475428-0.365714l0.658286-0.548572a3.986286 3.986286 0 0 1 0.658286-0.548571c0.182857 0 0.292571-0.292571 0.475428-0.365714l1.097143-1.024 71.168-71.168a29.257143 29.257143 0 0 0 0-41.508572 29.878857 29.878857 0 0 0-42.386286-0.036571z" p-id="1472">
</path>
</svg>
</i>
</div>
`;
const BackgroundCustomBtnStyle = `
<style id="backgroundBtnStyle">
.customBtn i:hover {
color: var(--brand_standard) !important;
}
</style>
`;
const BackgroundChangeBtnHtml = `
<div
id="backgroundChange"
class="customBtn"
style="app-region: no-drag; display: flex; height: 24px; justify-content: center; margin-bottom: 16px;margin-left:2px;"
>
<i style="display: inline-flex; justify-content: center; align-items: center; color: var(--icon_primary)">
<svg width="24" height="24" t="1707309462760" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6358" xmlns:xlink="http://www.w3.org/1999/xlink">
<path fill="currentColor" d="M224.028444 96.028444A159.971556 159.971556 0 0 0 64 256v447.317333a30.72 30.72 0 0 0 0 1.422223V768a159.971556 159.971556 0 0 0 160.028444 160.028444h351.971556a31.971556 31.971556 0 1 0 0-64H224.028444A95.971556 95.971556 0 0 1 128 768v-45.454222l190.065778-108.600889 207.36 148.081778a31.971556 31.971556 0 1 0 37.148444-52.053334l-98.190222-70.144 241.777778-214.926222 189.838222 135.566222v15.530667a32.028444 32.028444 0 0 0 64 0V256a160.028444 160.028444 0 0 0-160.028444-160.028444H224.028444zM682.666667 360.106667l-271.758223 241.550222-72.362666-51.712a31.971556 31.971556 0 0 0-34.474667-1.706667L128 648.874667V256c0-53.020444 43.008-96.028444 96.028444-96.028444h576c52.963556 0 95.971556 43.008 95.971556 96.028444v225.848889l-173.397333-123.904a32.028444 32.028444 0 0 0-39.822223 2.161778z m-394.695111-40.106667a31.971556 31.971556 0 1 1 64 0 31.971556 31.971556 0 0 1-64 0z m31.971555-96.028444a95.971556 95.971556 0 1 0 0 192 95.971556 95.971556 0 0 0 0-192z" fill="#000000" p-id="6359">
</path>
<path fill="currentColor" d="M703.431111 828.302222h224.711111a26.510222 26.510222 0 0 1 19.114667 45.852445l-46.933333 46.819555a26.339556 26.339556 0 0 1-37.432889 0 26.453333 26.453333 0 0 1 0-37.432889l2.275555-2.332444h-161.735111a26.453333 26.453333 0 1 1 0-52.906667z m232.448 19.797334zM929.28 783.075556h-224.711111a26.510222 26.510222 0 0 1-19.114667-45.852445l46.990222-46.762667a26.339556 26.339556 0 0 1 37.376-0.056888 26.453333 26.453333 0 0 1 0 37.432888l-2.275555 2.332445h161.735111a26.453333 26.453333 0 1 1 0 52.906667z m-232.448-19.797334z" fill="#000000" p-id="6360">
</path>
</svg>
</i>
</div>
`;
export async function onSettingWindowCreated(view) {
var tmpDirSize = getfilesize(await window.background_plugin.getTmpDirSize());
var nowConfig = await window.background_plugin.getNowConfig();
var nowImgDir = nowConfig.imgDir;
var nowImgSaveDir = nowConfig.imgSaveDir;
var nowImgApi = nowConfig.imgApi;
var nowCommonBg = nowConfig.isCommonBg;
var nowEnableBackgroundForMediaViewer =
nowConfig.enableBackgroundForMediaViewer;
var nowApiJsonPath = nowConfig.imgApiJsonPath;
var nowApiType = nowConfig.apiType == null ? "img" : nowConfig.apiType;
var nowImgSource =
nowConfig.imgSource == null ? "folder" : nowConfig.imageSource;
var nowImgFile = nowConfig.imgFile;
var nNowEnableBackgroundForMediaViewer =
nowEnableBackgroundForMediaViewer == null
? true
: nowEnableBackgroundForMediaViewer;
var nNowCommonBg = nowCommonBg == null ? true : nowCommonBg;
var nNowImgApi = nowImgApi == null ? "" : nowImgApi;
var nNowApiJsonPath = nowApiJsonPath == null ? "" : nowApiJsonPath;
var nNowImgFile = nowImgFile == null ? "" : nowImgFile;
let isFrostedGlassStyle =
nowConfig.enableFrostedGlassStyle == null ||
nowConfig.enableFrostedGlassStyle === true;
let isAutoRefresh =
nowConfig.isAutoRefresh == null || nowConfig.isAutoRefresh === true;
let isUseCache = !(
(nowConfig.apiOptions &&
(nowConfig.apiOptions.useCache === false ||
nowConfig.apiOptions.useCache == null)) ||
nowConfig.apiOptions == null
);
const new_navbar_item = `
<body>
<div class="config_view">
<section class="path">
<h1>背景图设置</h1>
<div class="wrap">
<div class="vertical-list-item top-box">
<h2>操作</h2>
<div>
<button id="refreshBgNow" class="q-button q-button--small q-button--secondary">立即更新一次背景</button>
<button id="clearTmpDir" class="q-button q-button--small q-button--secondary">清空网络图片缓存文件夹(${tmpDirSize})</button>
<button id="resetAll" class="q-button q-button--small q-button--secondary">恢复默认设置</button>
</div>
</div>
<hr class="horizontal-dividing-line" />
<div class="vertical-list-item top-box">
<h2>复制当前背景图路径</h2>
<div>
<button id="copyNowApiBg" class="q-button q-button--small q-button--secondary">复制最近一次API背景图URL</button>
<button id="copyNowFolderBg" class="q-button q-button--small q-button--secondary">复制最近一次文件夹背景图路径</button>
</div>
</div>
<hr class="horizontal-dividing-line" />
<div class="vertical-list-item">
<div>
<h2>修改背景来源</h2>
<span class="secondary-text">如果使用网络背景API,请务必选择正确是网络图片还是网络视频</span>
</div>
<div style="width: 25%; pointer-events: auto;">
<section class="list-ctl">
<div class="ops-selects">
<div class="q-pulldown-menu small-size" data-id="image_source">
<div class="q-pulldown-menu-button">
<input class="content" type="text" readonly spellcheck="false">
<svg class="icon" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"
style="
max-width: 20px;
max-height: 20px;
margin-bottom: 5%;
">
<path d="M12 6.0001L8.00004 10L4 6" stroke="currentColor" stroke-linejoin="round"></path>
</svg>
</div>
<div class="q-context-menu hidden" style="z-index:1">
<ul class="q-pulldown-menu-list small-size">
<li class="q-pulldown-menu-list-item" data-value="none">
<span class="content">无背景图</span>
<span class="icon">
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 7L6.00001 11L14 3" stroke="currentColor" stroke-linejoin="round"></path>
</svg>
</span>
</li>
<li class="q-pulldown-menu-list-item" data-value="folder">
<span class="content">目录</span>
<span class="icon">
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 7L6.00001 11L14 3" stroke="currentColor" stroke-linejoin="round"></path>
</svg>
</span>
</li>
<li class="q-pulldown-menu-list-item" data-value="file">
<span class="content">单个文件</span>
<span class="icon">
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 7L6.00001 11L14 3" stroke="currentColor" stroke-linejoin="round"></path>
</svg>
</span>
</li>
<li class="q-pulldown-menu-list-item" data-value="network">
<span class="content">网络图片</span>
<span class="icon">
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 7L6.00001 11L14 3" stroke="currentColor" stroke-linejoin="round"></path>
</svg>
</span>
</li>
<li class="q-pulldown-menu-list-item" data-value="network_video">
<span class="content">网络视频</span>
<span class="icon">
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 7L6.00001 11L14 3" stroke="currentColor" stroke-linejoin="round"></path>
</svg>
</span>
</li>
</ul>
</div>
</div>
</section>
</div>
</div>
<hr class="horizontal-dividing-line" />
<div class="vertical-list-item">
<div>
<h2>网络背景API链接</h2>
<span class="secondary-text">目前仅支持GET请求,请确保直接访问链接能查看到图片/视频且未设置防盗链~如有URL含中文请URL编码。</span>
</div>
<div style="width: 95%;display: flex;align-items: center;flex-direction: row; margin-left:20px; pointer-events: auto;">
<input id="selectImageApi" style="width:70%" class="path-input text_color" type="text" spellcheck="false" placeholder="输入API地址(可选)" value="${nNowImgApi}">
<button id="testNetworkApi" class="q-button q-button--small q-button--secondary">测试获取</button>
</div>
</div>
<div class="vertical-list-item bottom-box">
<div>
<h2>网络背景API JSON路径</h2>
<span class="secondary-text">若API返回的是JSON,请填写图片直链对应的 JSON 路径(会自动判断返回内容是不是JSON)。</span>
</div>
<div style="width: 72%;display: flex;align-items: center;flex-direction: row; margin-left:20px; pointer-events: auto;">
<input id="apiJsonPath" style="width:70%" class="path-input text_color" type="text" spellcheck="false" placeholder="输入 JSON 路径(可选)" value="${nNowApiJsonPath}">
<button id="apiJsonPathHelp" class="q-button q-button--small q-button--secondary">查看帮助</button>
</div>
</div>
<div class="vertical-list-item">
<div>
<h2>保存背景图的路径</h2>
</div>
<div style="width: 55%; display: flex;align-items: center;flex-direction: row;margin-left:40px; pointer-events: auto;">
<input id="selectImageSaveDir" style="width:70%" class="path-input text_color" type="text" spellcheck="false" placeholder="点击保存按钮后保存到哪" readonly="true" value="${nowImgSaveDir}">
<button id="selectImageSaveDirBtn" class="q-button q-button--small q-button--secondary">选择目录</button>
</div>
</div>
<hr class="horizontal-dividing-line" />
<div class="vertical-list-item">
<div>
<h2>本地背景文件夹路径</h2>
</div>
<div style="width: 55%; display: flex;align-items: center;flex-direction: row;margin-left:40px; pointer-events: auto;">
<input id="selectImageDir" style="width:70%" class="path-input text_color" type="text" spellcheck="false" placeholder="本地背景文件夹路径" readonly="true" value="${nowImgDir}">
<button id="selectImageDirBtn" class="q-button q-button--small q-button--secondary">选择目录</button>
</div>
</div>
<div class="vertical-list-item bottom-box">
<div>
<h2>本地背景路径</h2>
</div>
<div style="width: 55%; display: flex;align-items: center;flex-direction: row;margin-left:40px; pointer-events: auto;">
<input id="selectImageFile" style="width:70%" class="path-input text_color" type="text" spellcheck="false" placeholder="本地背景文件路径" readonly="true" value="${nNowImgFile}">
<button id="selectImageFileBtn" class="q-button q-button--small q-button--secondary">选择文件</button>
</div>
</div>
<hr class="horizontal-dividing-line" />
<div class="vertical-list-item">
<div>
<h2>是否对所有窗口共用同一个背景</h2>
<span class="secondary-text">修改将自动保存并立即生效</span>
</div>
<div id="switchCommonBg" class="q-switch">
<span class="q-switch__handle"></span>
</div>
</div>
<hr class="horizontal-dividing-line" />
<div class="vertical-list-item">
<div>
<h2>是否对媒体预览器生效背景</h2>
<span class="secondary-text">修改将自动保存并在新打开的媒体预览器生效</span>
</div>
<div id="switchMediaViewer" class="q-switch">
<span class="q-switch__handle"></span>
</div>
</div>
<hr class="horizontal-dividing-line" />
<div class="vertical-list-item">
<div>
<h2>是否对部分组件启用毛玻璃模糊效果</h2>
<span class="secondary-text">修改将自动保存并立即生效</span>
</div>
<div id="switchFrostedGlassStyle" class="q-switch">
<span class="q-switch__handle"></span>
</div>
</div>
<hr class="horizontal-dividing-line" />
<div class="vertical-list-item">
<div>
<h2>调整主背景图覆盖层透明度</h2>
<span class="secondary-text">修改将自动保存并立即生效(默认中间,也就是不调整)</span>
</div>
<input type="range" value="0" min="-100" max="100" step="1"
class="q-button q-button--small q-button--secondary pick-opacity" style="width: 51%;" />
</div>
</div>
</section>
<section class="path">
<h1>更新设置</h1>
<div class="wrap">
<div class="list">
<div class="vertical-list-item">
<div>
<h2>背景更新间隔</h2>
<span class="secondary-text">修改将自动保存并立即生效;为了最佳体验,请勿设置过短哦~</span>
</div>
<div style="width:105px;pointer-events: auto;">
<input id="refreshTimeInput" min="1" max="99999" maxlength="5" class="text_color path-input" style="width:75px;" type="number" value="${nowConfig.refreshTime}"/>秒
</div>
</div>
<hr class="horizontal-dividing-line" />
<div class="vertical-list-item">
<div>
<h2>是否自动轮播背景</h2>
<span class="secondary-text">修改将自动保存并立即生效</span>
</div>
<div id="switchAutoRoll" class="q-switch">
<span class="q-switch__handle"></span>
</div>
</div>
</div>
</div>
</section>
<section class="path">
<h1>网络请求设置</h1>
<div class="wrap">
<div class="list">
<div class="vertical-list-item">
<div>
<h2>是否启用视频缓存</h2>
<span class="secondary-text">若使用的API每次返回不同视频请关闭缓存,否则每次视频可能因为缓存无法更新;若API仅返回单个视频则可以开启缓存。注意:本选项现在对网络图片无效,网络图片均会自动保存。</span>
</div>
<div style="width:10%; display: flex;align-items: center;flex-direction: row;margin-left:40px; pointer-events: auto;" >
<div id="switchUseCache" class="q-switch">
<span class="q-switch__handle"></span>
</div>
</div>
</div>
</div>
</div>
</section>
<img id="testImage" class="img-hidden" style="width:80%; height:auto; margin-left:10%; border:1px solid;box-shadow: 2px 2px 2px 1px rgba(80,80, 80, 0.6);"></img>
<div id="testVideo" class="img-hidden" style="width:80%; height:auto; margin-left:10%; border:1px solid;box-shadow: 2px 2px 2px 1px rgba(80,80, 80, 0.6);"></div>
<style>
.img-hidden {
display:none;
}
.path-input {
align-self: normal;
flex: 1;
border-radius: 4px;
margin-right: 16px;
transition: all 100ms ease-out;
}
.path-input:focus {
padding-left: 4px;
}
.bq-icon {
height:16px;
width:16px;
}
/* 通用 */
.config_view {
margin: 20px;
}
/* 背景颜色透明度滑条 */
.config_view input[type='range']::-webkit-slider-thumb {
-webkit-appearance: none;
height: 16px;
width: 16px;
border-radius: 8px;
background: aqua;
cursor: pointer;
}
.pick-opacity {
padding: 4px;
}
.config_view h1 {
color: var(--text_primary);
font-weight: var(--font-bold);
font-size: min(var(--font_size_3), 18px);
line-height: min(var(--line_height_3), 24px);
padding: 0px 16px;
margin-bottom: 8px;
}
.config_view .wrap {
/* Linux样式兼容:--fg_white */
background-color: var(--fill_light_primary, var(--fg_white));
border-radius: 8px;
font-size: min(var(--font_size_3), 18px);
line-height: min(var(--line_height_3), 24px);
margin-bottom: 20px;
overflow: hidden;
padding: 0px 16px;
}
.config_view .vertical-list-item {
margin: 12px 0px;
display: flex;
justify-content: space-between;
align-items: center;
}
.config_view .horizontal-dividing-line {
border: unset;
margin: unset;
height: 1px;
background-color: rgba(127, 127, 127, 0.15);
}
.config_view .vertical-dividing-line {
border: unset;
margin: unset;
width: 1px;
background-color: rgba(127, 127, 127, 0.15);
}
.config_view .ops-btns {
display: flex;
}
.config_view .hidden {
display: none !important;
}
.config_view .disabled {
pointer-events: none;
opacity: 0.5;
}
.config_view .secondary-text {
color: var(--text_secondary);
font-size: min(var(--font_size_2), 16px);
line-height: min(var(--line_height_2), 22px);
margin-top: 4px;
}
.config_view .wrap .title {
cursor: pointer;
font-size: min(var(--font_size_3), 18px);
line-height: min(var(--line_height_3), 24px);
}
.config_view .wrap .title svg {
width: 1em;
height: 1em;
transform: rotate(-180deg);
transition-duration: 0.2s;
transition-timing-function: ease;
transition-delay: 0s;
transition-property: transform;
}
.config_view .wrap .title svg.is-fold {
transform: rotate(0deg);
}
/* 模态框 */
.config_view .modal-window {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 999;
background-color: rgba(0, 0, 0, 0.5);
}
.config_view .modal-dialog {
width: 480px;
border-radius: 8px;
/* Linux样式兼容:--fg_white */
background-color: var(--bg_bottom_standard, var(--fg_white));
}
.config_view .modal-dialog header {
font-size: 12px;
height: 30px;
line-height: 30px;
text-align: center;
}
.config_view .modal-dialog main {
padding: 0px 16px;
}
.config_view .modal-dialog main p {
margin: 8px 0px;
}
.config_view .modal-dialog footer {
height: 30px;
display: flex;
justify-content: right;
align-items: center;
}
.config_view .modal-dialog .q-icon {
width: 22px;
height: 22px;
margin: 8px;
}
/* 版本号 */
.config_view .versions .wrap {
display: flex;
justify-content: space-between;
padding: 16px 0px;
}
.config_view .versions .wrap>div {
flex: 1;
margin: 0px 10px;
border-radius: 8px;
text-align: center;
}
/* 数据目录 */
.config_view .path .path-input {
align-self: normal;
flex: 1;
border-radius: 4px;
margin-right: 16px;
transition: all 100ms ease-out;
}
.config_view .path .path-input:focus {
padding-left: 5px;
background-color: rgba(127, 127, 127, 0.1);
}
/* 选择框容器 */
.config_view .list-ctl .ops-selects {
display: flex;
gap: 8px;
}
@media (prefers-color-scheme: light) {
.text_color {
color: black;
}
}
@media (prefers-color-scheme: dark) {
.text_color {
color: white;
}
}
</style>
</div>
</body>
`;
const parser = new DOMParser();
const doc2 = parser.parseFromString(new_navbar_item, "text/html");
const node2 = doc2.querySelector("body > div");
const setPulldownValue = (id, value) => {
const name = node2.querySelector(
`.list-ctl .q-pulldown-menu[data-id="${id}"] [data-value="${value}"] .content`
);
name.parentNode.click();
};
var selectDir = async () => {
var path = await window.background_plugin.showFolderSelect();
if (path == "" || path == null) return;
var realPath = path[0].replaceAll("\\", "/");
node2.querySelector("#selectImageDir").value = realPath;
setPulldownValue("image_source", "folder");
await window.background_plugin.reloadBg();
alert("成功修改路径为目录:" + realPath);
};
var selectImgSaveDir = async () => {
var path = await window.background_plugin.showImgSaveFolderSelect();
if (path == "" || path == null) return;
var realPath = path[0].replaceAll("\\", "/");
node2.querySelector("#selectImageSaveDir").value = realPath;
alert("成功修改保存图片的路径为:" + realPath);
};
var selectFile = async () => {
var path = await window.background_plugin.showFileSelect();
if (path == "" || path == null) return;
var realPath = path[0].replaceAll("\\", "/");
node2.querySelector("#selectImageFile").value = realPath;
setPulldownValue("image_source", "file");
await window.background_plugin.reloadBg();
alert("成功修改路径为单个文件:" + realPath);
};
function isUrl(str) {
var v = new RegExp(
"^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$",
"i"
);
return v.test(str);
}
var selectNetwork = async () => {
var path = node2.querySelector("#selectImageApi").value;
if (path == null || path.trim() == "") return;
if (!isUrl(path)) {
alert("URL不合法,请重新输入!");
return;
}
await window.background_plugin.networkImgConfigApply(path);
};
var apiJsonPathChange = async () => {
var path = node2.querySelector("#apiJsonPath").value;
if (path == null || path.trim() == "") return;
await window.background_plugin.apiJsonPathApply(path);
};
var clearTmpDir = async () => {
await window.background_plugin.clearTmpDir();
var tmpDirSize = getfilesize(
await window.background_plugin.getTmpDirSize()
);
node2.querySelector(
"#clearTmpDir"
).innerText = `清空缓存文件夹(${tmpDirSize})`;
};
var refreshBg = async () => {
await window.background_plugin.reloadBg();
};
var resetAll = async () => {
var result = await window.background_plugin.resetAll();
if (result == true) {
alert("已重置所有设置,请重新打开设置界面");
window.close();
}
};
var testNetworkApi = async () => {
var nowConfig = await window.background_plugin.getNowConfig();
alert("请观察界面最下侧是否能显示,若无任何媒体显示则说明有问题。");
if (nowConfig.apiType == "img") {
node2.querySelector("#testVideo").classList.add("img-hidden");
node2.querySelector("#testImage").classList.remove("img-hidden");
var videoNode = document.getElementById("test-video");
if (videoNode) {
videoNode.parentElement.removeChild(videoNode);
}
var imgUrl = node2.querySelector("#selectImageApi").value;
imgUrl = await window.background_plugin.fetchApi(imgUrl);
if (isLocalFile(imgUrl)) {
//前面加上协议头
imgUrl = `local:///${imgUrl}`;
}
try {
// var url = new URL(imgUrl);
// url.searchParams.append("t", new Date().getTime());
// imgUrl = url.toString();
node2.querySelector("#testImage").src = imgUrl;
} catch {
alert("URL不合法,请重新输入!");
}
} else if (nowConfig.apiType == "video") {
node2.querySelector("#testImage").classList.add("img-hidden");
node2.querySelector("#testVideo").classList.remove("img-hidden");
var imgUrl = node2.querySelector("#selectImageApi").value;
imgUrl = await window.background_plugin.fetchApi(imgUrl);
if (isLocalFile(imgUrl)) {
//前面加上协议头
imgUrl = `local:///${imgUrl}`;
}
try {
// var url = new URL(imgUrl);
// url.searchParams.append("t", new Date().getTime());
// imgUrl = url.toString();
var videoNode = document.getElementById("test-video");
if (videoNode) {
videoNode.parentElement.removeChild(videoNode);
}
var video = document.createElement("video");
video.autoplay = true;
video.muted = true;
video.loop = true;
video.volume = 0;
video.style = "margin-left:10%;margin-right:10%;width:80%";
video.id = "test-video";
video.innerHTML = `<source src="${imgUrl}">`;
document.getElementById("testVideo").appendChild(video);
} catch {
alert("URL不合法,请重新输入!");
}
} else {
alert(
"请先选择背景来源为网络图片或网络视频,再进行测试(否则插件不知道应该渲染图片还是视频)"
);
}
};
var apiJsonPathHelp = async () => {
await window.background_plugin.showApiPathHelp();
};
var copyNowApiBg = async () => {
var nowBg = await window.background_plugin.getNowBg();
if (nowBg == undefined || nowBg == "") {
alert("最近未用到API,结果为空");
return;
}
await navigator.clipboard.writeText(nowBg.api);
};
var copyNowFolderBg = async () => {
var nowBg = await window.background_plugin.getNowBg();
if (nowBg == undefined || nowBg == "") {
alert("最近未用到文件夹背景图,结果为空");
return;
}
await navigator.clipboard.writeText(nowBg.folder);
};
node2.querySelector("#copyNowApiBg").onclick = copyNowApiBg;
node2.querySelector("#copyNowFolderBg").onclick = copyNowFolderBg;
node2.querySelector("#clearTmpDir").onclick = clearTmpDir;
node2.querySelector("#refreshBgNow").onclick = refreshBg;
node2.querySelector("#resetAll").onclick = resetAll;
node2.querySelector("#selectImageSaveDirBtn").onclick = selectImgSaveDir;
node2.querySelector("#selectImageDirBtn").onclick = selectDir;
node2.querySelector("#selectImageFileBtn").onclick = selectFile;
node2.querySelector("#selectImageApi").onblur = selectNetwork;
node2.querySelector("#apiJsonPath").onblur = apiJsonPathChange;
node2.querySelector("#testNetworkApi").onclick = testNetworkApi;
node2.querySelector("#apiJsonPathHelp").onclick = apiJsonPathHelp;
// 全局背景透明度偏移
const backgroundOpacity = nowConfig.globalTransparentOffset;
// 给pick-opacity(input)设置默认值
const pickOpacity = node2.querySelector(".pick-opacity");
pickOpacity.value = parseInt(backgroundOpacity * 100);
// 给pick-opacity(input)添加事件监听
pickOpacity.addEventListener("change", async (event) => {
var realValue = event.target.value / 100;
await window.background_plugin.setBGTransparent(realValue);
});
var q_switch_mediaViewer = node2.querySelector("#switchMediaViewer");
if (nNowEnableBackgroundForMediaViewer == true) {
q_switch_mediaViewer.classList.toggle("is-active");
}
q_switch_mediaViewer.addEventListener("click", async () => {
if (q_switch_mediaViewer.classList.contains("is-active")) {
//取消
window.background_plugin.setEMediaViewer(false);
} else {
//重新设置
window.background_plugin.setEMediaViewer(true);
}
q_switch_mediaViewer.classList.toggle("is-active");
});
var q_switch_commonBg = node2.querySelector("#switchCOmmonBg");
if (nNowCommonBg == true) {
q_switch_commonBg.classList.toggle("is-active");
}
q_switch_commonBg.addEventListener("click", async () => {
if (q_switch_commonBg.classList.contains("is-active")) {
//取消
window.background_plugin.setCommonBg(false);
} else {
//重新设置
window.background_plugin.setCommonBg(true);
}
q_switch_commonBg.classList.toggle("is-active");
});
var q_switch_fglass = node2.querySelector("#switchFrostedGlassStyle");
if (isFrostedGlassStyle) {
q_switch_fglass.classList.toggle("is-active");
}
q_switch_fglass.addEventListener("click", async () => {
if (q_switch_fglass.classList.contains("is-active")) {
//取消
window.background_plugin.setFrostedGlassStyle(false);
} else {
//重新设置
window.background_plugin.setFrostedGlassStyle(true);
}
q_switch_fglass.classList.toggle("is-active");
});
var q_switch_autoroll = node2.querySelector("#switchAutoRoll");
if (isAutoRefresh) {
q_switch_autoroll.classList.toggle("is-active");
}
q_switch_autoroll.addEventListener("click", async () => {
if (q_switch_autoroll.classList.contains("is-active")) {
//取消
window.background_plugin.setAutoRefresh(false);
} else {
//重新设置
window.background_plugin.setAutoRefresh(true);
}
q_switch_autoroll.classList.toggle("is-active");
});
var q_switch_usecache = node2.querySelector("#switchUseCache");
if (isUseCache) {
q_switch_usecache.classList.toggle("is-active");
}
q_switch_usecache.addEventListener("click", async () => {
if (q_switch_usecache.classList.contains("is-active")) {
//取消
window.background_plugin.setUseCache(false);
} else {
//重新设置
window.background_plugin.setUseCache(true);
}
q_switch_usecache.classList.toggle("is-active");
});
node2.querySelector("#refreshTimeInput").onblur = async () => {
var time = parseFloat(node2.querySelector("#refreshTimeInput").value);
if (time <= 0 || time > 99999) {
alert("你的时间设置有误!将不会保存,请重新输入");
return;
}
await window.background_plugin.changeRefreshTime(time);
};
//初始化下拉框
const list_ctl = node2.querySelector(".list-ctl");
const all_pulldown_menu_button = list_ctl.querySelectorAll(
".q-pulldown-menu-button"
);
//显示下拉框列表
for (const pulldown_menu_button of all_pulldown_menu_button) {
pulldown_menu_button.addEventListener("click", (event) => {
const context_menu = event.currentTarget.nextElementSibling;
context_menu.classList.toggle("hidden");
});
}
node2.addEventListener("pointerup", (event) => {
if (event.target.closest(".q-pulldown-menu-button")) {
return;
}
if (!event.target.closest(".q-context-menu")) {
const all_context_menu = list_ctl.querySelectorAll(".q-context-menu");
for (const context_menu of all_context_menu) {
context_menu.classList.add("hidden");
}
}
});
//下拉框选择
const pulldown_menus = list_ctl.querySelectorAll(".q-pulldown-menu");
for (const pulldown_menu of pulldown_menus) {
const content = pulldown_menu.querySelector(
".q-pulldown-menu-button .content"
);
const pulldown_menu_list = pulldown_menu.querySelector(
".q-pulldown-menu-list"
);
const pulldown_menu_list_items = pulldown_menu_list.querySelectorAll(
".q-pulldown-menu-list-item"
);
// 初始化选择框按钮显示内容
const setValueAndAddSelectedClass = (value) => {
if (value == null) value = "folder";
const name = pulldown_menu.querySelector(
`[data-value="${value}"] .content`
);
name.parentNode.classList.add("selected");
content.value = name.textContent;
};
switch (pulldown_menu.dataset.id) {
case "image_source":
{
const value = nowConfig.imgSource;
setValueAndAddSelectedClass(value);
}
break;
}
// 选择框条目点击
pulldown_menu_list.addEventListener("click", async (event) => {
const target = event.target.closest(".q-pulldown-menu-list-item");
if (target == null) return;
const item_value = target.dataset.value;
// 判断是哪个选择框的,单独设置
switch (pulldown_menu.dataset.id) {
case "image_source":
switch (item_value) {
case "folder":
var path = node2.querySelector("#selectImageDir").value;
if (path == null || path.trim() == "") {
alert("请先在下方选择文件夹路径,再选中背景来源为目录");
return;
}
break;
case "file":
var path = node2.querySelector("#selectImageFile").value;
if (path == null || path.trim() == "") {
alert("请先在下方选择文件路径,再选中背景来源为单个文件");
return;
}
break;
case "network":
var path = node2.querySelector("#selectImageApi").value;
if (path == null || path.trim() == "") {
alert("请先在下方输入背景链接地址,再选中背景来源为网络图片");
return;
} else {
window.background_plugin.setApiType("img");
}
break;
case "network_video":
var path = node2.querySelector("#selectImageApi").value;
if (path == null || path.trim() == "") {
alert("请先在下方输入背景链接地址,再选中背景来源为网络视频");
return;
} else {
window.background_plugin.setApiType("video");
}
break;
}
window.background_plugin.setImageSourceType(item_value);
break;
}
if (target && !target.classList.contains("selected")) {
// 移除所有条目的选择状态
for (const pulldown_menu_list_item of pulldown_menu_list_items) {
pulldown_menu_list_item.classList.remove("selected");
}
// 添加选择状态
target.classList.add("selected");
// 获取选中的选项文本
const text_content = target.querySelector(".content").textContent;
content.value = text_content;
const all_context_menu = list_ctl.querySelectorAll(".q-context-menu");
for (const context_menu of all_context_menu) {
context_menu.classList.add("hidden");
}
}
});
}
view.appendChild(node2);
}
function getfilesize(size) {
//把字节转换成正常文件大小
if (!size) return "0B";
var num = 1024.0; //byte
if (size < num) return size + "B";
if (size < Math.pow(num, 2)) return (size / num).toFixed(2) + "KB"; //kb
if (size < Math.pow(num, 3))
return (size / Math.pow(num, 2)).toFixed(2) + "MB"; //M
if (size < Math.pow(num, 4))