forked from royc01/notion-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.js
2213 lines (1879 loc) · 69.5 KB
/
theme.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
window.theme = {};
/**
* 加载样式文件
* @params {string} href 样式地址
* @params {string} id 样式 ID
*/
window.theme.loadStyle = function (href, id = null) {
let style = document.createElement('link');
if (id) style.id = id;
style.type = 'text/css';
style.rel = 'stylesheet';
style.href = href;
document.head.appendChild(style);
}
/**
* 更新样式文件
* @params {string} id 样式文件 ID
* @params {string} href 样式文件地址
*/
window.theme.updateStyle = function (id, href) {
let style = document.getElementById(id);
if (style) {
style.setAttribute('href', href);
}
else {
window.theme.loadStyle(href, id);
}
}
window.theme.ID_COLOR_STYLE = 'theme-color-style';
/**
* 获取主题模式
* @return {string} light 或 dark
*/
window.theme.themeMode = (() => {
/* 根据浏览器主题判断颜色模式 */
// switch (true) {
// case window.matchMedia('(prefers-color-scheme: light)').matches:
// return 'light';
// case window.matchMedia('(prefers-color-scheme: dark)').matches:
// return 'dark';
// default:
// return null;
// }
/* 根据配置选项判断主题 */
switch (window.siyuan.config.appearance.mode) {
case 0:
return 'light';
case 1:
return 'dark';
default:
return null;
}
})();
/**
* 更换主题模式
* @params {string} lightStyle 浅色主题配置文件路径
* @params {string} darkStyle 深色主题配置文件路径
*/
window.theme.changeThemeMode = function (
lightStyle,
darkStyle,
) {
let href_color = null;
switch (window.theme.themeMode) {
case 'light':
href_color = lightStyle;
break;
case 'dark':
default:
href_color = darkStyle;
break;
}
window.theme.updateStyle(window.theme.ID_COLOR_STYLE, href_color);
}
/* 根据当前主题模式加载样式配置文件 */
window.theme.changeThemeMode(
`/appearance/themes/Savor/style/topbar/savor-light.css`,
`/appearance/themes/Savor/style/topbar/savor-dark.css`,
);
/*----------------------------------创建savor主题工具栏区域----------------------------------
function createsavorToolbar() {
var siYuanToolbar = getSiYuanToolbar();
var savorToolbar = getsavorToolbar();
var windowControls = document.getElementById("windowControls");
if (savorToolbar) siYuanToolbar.removeChild(savorToolbar);
savorToolbar = insertCreateBefore(windowControls, "div", "savorToolbar");
savorToolbar.style.marginRight = "14px";
savorToolbar.style.marginLeft = "11px";
}*/
/****************************思源API操作**************************/
async function 设置思源块属性(内容块id, 属性对象) {
let url = '/api/attr/setBlockAttrs'
return 解析响应体(向思源请求数据(url, {
id: 内容块id,
attrs: 属性对象,
}))
}
async function 向思源请求数据(url, data) {
let resData = null
await fetch(url, {
body: JSON.stringify(data),
method: 'POST',
headers: {
Authorization: `Token ''`,
}
}).then(function (response) { resData = response.json() })
return resData
}
async function 解析响应体(response) {
let r = await response
return r.code === 0 ? r.data : null
}
/****UI****/
function ViewSelect(selectid,selecttype){
let button = document.createElement("button")
button.id="viewselect"
button.className="b3-menu__item"
button.innerHTML='<svg class="b3-menu__icon" style="null"><use xlink:href="#iconGlobalGraph"></use></svg><span class="b3-menu__label" style="">视图选择</span><svg class="b3-menu__icon b3-menu__icon--arrow" style="null"><use xlink:href="#iconRight"></use></svg></button>'
button.appendChild(SubMenu(selectid,selecttype))
return button
}
function SubMenu(selectid,selecttype){
let button = document.createElement("button")
button.id="viewselectSub"
button.className="b3-menu__submenu"
button.appendChild(MenuItems(selectid,selecttype))
return button
}
function MenuItems(selectid,selecttype,className = 'b3-menu__items'){
let node = document.createElement('div');
node.className = className;
if(selecttype=="NodeList"){
node.appendChild(GraphView(selectid))
node.appendChild(TableView(selectid))
node.appendChild(kanbanView(selectid))
node.appendChild(progressView(selectid))
node.appendChild(DefaultView(selectid))
}
if(selecttype=="NodeTable"){
node.appendChild(FixWidth(selectid))
node.appendChild(AutoWidth(selectid))
node.appendChild(FullWidth(selectid))
node.appendChild(vHeader(selectid))
node.appendChild(Removeth(selectid))
node.appendChild(Defaultth(selectid))
}
if(selecttype=="NodeBlockquote"){
node.appendChild(quoteError(selectid))
node.appendChild(Warn(selectid))
node.appendChild(Bug(selectid))
node.appendChild(Check(selectid))
node.appendChild(Light(selectid))
node.appendChild(Question(selectid))
node.appendChild(Wrong(selectid))
node.appendChild(Info(selectid))
node.appendChild(Pen(selectid))
node.appendChild(Note(selectid))
node.appendChild(Bell(selectid))
node.appendChild(Defaultbq(selectid))
}
return node;
}
function GraphView(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","f")
button.setAttribute("custom-attr-value","dt")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconFiles"></use></svg><span class="b3-menu__label">转换为导图</span>`
button.onclick=ViewMonitor
return button
}
function TableView(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","f")
button.setAttribute("custom-attr-value","bg")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconTable"></use></svg><span class="b3-menu__label">转换为表格</span>`
button.onclick=ViewMonitor
return button
}
function kanbanView(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","f")
button.setAttribute("custom-attr-value","kb")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconMenu"></use></svg><span class="b3-menu__label">转换为看板</span>`
button.onclick=ViewMonitor
return button
}
function progressView(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","f")
button.setAttribute("custom-attr-value","progress")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconMenu"></use></svg><span class="b3-menu__label">进度条任务</span>`
button.onclick=ViewMonitor
return button
}
function DefaultView(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.onclick=ViewMonitor
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","f")
button.setAttribute("custom-attr-value",'')
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconList"></use></svg><span class="b3-menu__label">恢复为列表</span>`
return button
}
function FixWidth(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.onclick=ViewMonitor
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","f")
button.setAttribute("custom-attr-value","")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconTable"></use></svg><span class="b3-menu__label">自动宽度(换行)</span>`
return button
}
function AutoWidth(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","f")
button.setAttribute("custom-attr-value","auto")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconTable"></use></svg><span class="b3-menu__label">自动宽度(不换行)</span>`
button.onclick=ViewMonitor
return button
}
function FullWidth(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.onclick=ViewMonitor
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","f")
button.setAttribute("custom-attr-value","full")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconTable"></use></svg><span class="b3-menu__label">页面宽度</span>`
return button
}
function vHeader(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.onclick=ViewMonitor
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","t")
button.setAttribute("custom-attr-value","vbiaotou")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconSuper"></use></svg><span class="b3-menu__label">竖向表头样式</span>`
return button
}
function Removeth(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.onclick=ViewMonitor
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","t")
button.setAttribute("custom-attr-value","biaotou")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconSuper"></use></svg><span class="b3-menu__label">空白表头样式</span>`
return button
}
function Defaultth(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","t")
button.setAttribute("custom-attr-value","")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconSuper"></use></svg><span class="b3-menu__label">恢复表头样式</span>`
button.onclick=ViewMonitor
return button
}
function quoteError(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","error")
button.innerHTML=`<span class="b3-menu__label">🚫禁止</span>`
button.onclick=ViewMonitor
return button
}
function Warn(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","warn")
button.innerHTML=`<span class="b3-menu__label">⚠警告</span>`
button.onclick=ViewMonitor
return button
}
function Bug(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","bug")
button.innerHTML=`<span class="b3-menu__label">🐛bug</span>`
button.onclick=ViewMonitor
return button
}
function Check(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","check")
button.innerHTML=`<span class="b3-menu__label">✅正确</span>`
button.onclick=ViewMonitor
return button
}
function Light(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","light")
button.innerHTML=`<span class="b3-menu__label">💡灵感</span>`
button.onclick=ViewMonitor
return button
}
function Question(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","question")
button.innerHTML=`<span class="b3-menu__label">❓问题</span>`
button.onclick=ViewMonitor
return button
}
function Wrong(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","wrong")
button.innerHTML=`<span class="b3-menu__label">❌错误</span>`
button.onclick=ViewMonitor
return button
}
function Info(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","info")
button.innerHTML=`<span class="b3-menu__label">ℹ信息</span>`
button.onclick=ViewMonitor
return button
}
function Pen(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","pen")
button.innerHTML=`<span class="b3-menu__label">🖋记录</span>`
button.onclick=ViewMonitor
return button
}
function Note(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","note")
button.innerHTML=`<span class="b3-menu__label">📓汇总</span>`
button.onclick=ViewMonitor
return button
}
function Bell(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","bell")
button.innerHTML=`<span class="b3-menu__label">🔔提醒</span>`
button.onclick=ViewMonitor
return button
}
function Defaultbq(selectid){
let button = document.createElement("button")
button.className="b3-menu__item"
button.setAttribute("data-node-id",selectid)
button.setAttribute("custom-attr-name","b")
button.setAttribute("custom-attr-value","")
button.innerHTML=`<svg class="b3-menu__icon" style=""><use xlink:href="#iconRefresh"></use></svg><span class="b3-menu__label">恢复默认样式</span>`
button.onclick=ViewMonitor
return button
}
function MenuSeparator(className = 'b3-menu__separator') {
let node = document.createElement('button');
node.className = className;
return node;
}
/* 操作 */
/**
* 获得所选择的块对应的块 ID
* @returns {string} 块 ID
* @returns {
* id: string, // 块 ID
* type: string, // 块类型
* subtype: string, // 块子类型(若没有则为 null)
* }
* @returns {null} 没有找到块 ID */
function getBlockSelected() {
let node_list = document.querySelectorAll('.protyle-wysiwyg--select');
if (node_list.length === 1 && node_list[0].dataset.nodeId != null) return {
id: node_list[0].dataset.nodeId,
type: node_list[0].dataset.type,
subtype: node_list[0].dataset.subtype,
};
return null;
}
function ClickMonitor () {
window.addEventListener('mouseup', MenuShow)
}
function MenuShow() {
setTimeout(() => {
let selectinfo = getBlockSelected()
if(selectinfo){
let selecttype = selectinfo.type
let selectid = selectinfo.id
if(selecttype=="NodeList"||selecttype=="NodeTable"||selecttype=="NodeBlockquote"){
setTimeout(()=>InsertMenuItem(selectid,selecttype), 0)
}
}
}, 0);
}
function InsertMenuItem(selectid,selecttype){
let commonMenu = document.querySelector(".b3-menu__items")
let readonly = commonMenu.querySelector(".b3-menu__item--readonly")
let selectview = commonMenu.querySelector('[id="viewselect"]')
if(readonly){
if(!selectview){
commonMenu.insertBefore(ViewSelect(selectid,selecttype),readonly)
commonMenu.insertBefore(MenuSeparator(),readonly)
}
}
}
function ViewMonitor(event){
let id = event.currentTarget.getAttribute("data-node-id")
let attrName = 'custom-'+event.currentTarget.getAttribute("custom-attr-name")
let attrValue = event.currentTarget.getAttribute("custom-attr-value")
let blocks = document.querySelectorAll(`.protyle-wysiwyg [data-node-id="${id}"]`)
if(blocks){
blocks.forEach(block=>block.setAttribute(attrName,attrValue))
}
let attrs={}
attrs[attrName] =attrValue
设置思源块属性(id,attrs)
}
setTimeout(()=>ClickMonitor(),1000)
/**---------------------------------------------------------主题-------------------------------------------------------------- */
function themeButton() {
savorThemeToolbarAddButton(
"buttonSavor-light",
"toolbar__item b3-tooltips b3-tooltips__sw",
"Light 配色",
'light',
() => {
loadStyle("/appearance/themes/Savor/style/topbar/savor-light.css", "Savor-light").setAttribute("topicfilter", "buttonSavor-light");
qucuFiiter();
},
() => {
document.getElementById("Savor-light").remove();
},
true
);
savorThemeToolbarAddButton(
"buttonsalt",
"toolbar__item b3-tooltips b3-tooltips__sw",
"Salt 配色",
'light',
() => {
loadStyle("/appearance/themes/Savor/style/topbar/salt.css", "salt主题").setAttribute("topicfilter", "buttonsalt");
qucuFiiter();
},
() => {
document.getElementById("salt主题").remove();
},
true
);
savorThemeToolbarAddButton(
"buttonsugar",
"toolbar__item b3-tooltips b3-tooltips__sw",
"Sugar 配色",
'light',
() => {
loadStyle("/appearance/themes/Savor/style/topbar/sugar.css", "sugar主题").setAttribute("topicfilter", "buttonsugar");
qucuFiiter();
},
() => {
document.getElementById("sugar主题").remove();
},
true
);
savorThemeToolbarAddButton(
"buttonSavor-dark",
"toolbar__item b3-tooltips b3-tooltips__sw",
"Dark 配色",
'dark',
() => {
loadStyle("/appearance/themes/Savor/style/topbar/savor-dark.css", "Savor-dark").setAttribute("topicfilter", "buttonSavor-dark");
qucuFiiter();
},
() => {
document.getElementById("Savor-dark").remove();
},
true
);
savorThemeToolbarAddButton(
"buttonvinegar",
"toolbar__item b3-tooltips b3-tooltips__sw",
"Vinegar 配色",
'dark',
() => {
loadStyle("/appearance/themes/Savor/style/topbar/vinegar.css", "vinegar主题").setAttribute("topicfilter", "buttonvinegar");
qucuFiiter();
},
() => {
document.getElementById("vinegar主题").remove();
},
true
);
}
/**---------------------------------------------------------挖空-------------------------------------------------------------- */
function concealMarkButton() {
savorThemeToolplusAddButton(
"conceal",
"toolbar__item b3-tooltips b3-tooltips__sw",
"挖空",
() => {
loadStyle("/appearance/themes/Savor/style/topbar/conceal-mark.css", "conceal挖空").setAttribute("topBarcss", "conceal挖空");
},
() => {
document.getElementById("conceal挖空").remove();
},
true
);
}
/**---------------------------------------------------------垂直-------------------------------------------------------------- */
function tabbarVerticalButton() {
savorThemeToolplusAddButton(
"tabbarVertical",
"toolbar__item b3-tooltips b3-tooltips__sw",
"垂直页签",
() => {
loadStyle("/appearance/themes/Savor/style/topbar/tab-bar-vertical.css", "tabbar垂直").setAttribute("topBarcss", "tabbar垂直");
},
() => {
document.getElementById("tabbar垂直").remove();
},
true
);
}
/**---------------------------------------------------------顶栏-------------------------------------------------------------- */
function topbarfixedButton() {
savorThemeToolplusAddButton(
"topBar",
"toolbar__item b3-tooltips b3-tooltips__sw",
"隐藏顶栏",
() => {
loadStyle("/appearance/themes/Savor/style/topbar/top-fixed.css", "topbar隐藏").setAttribute("topBarcss", "topbar隐藏");
},
() => {
document.getElementById("topbar隐藏").remove();
},
true
);
}
/**---------------------------------------------------------子弹-------------------------------------------------------------- */
function bulletThreading() {
savorThemeToolplusAddButton(
"bulletThreading",
"toolbar__item b3-tooltips b3-tooltips__sw",
"列表子弹线",
() => {
loadStyle("/appearance/themes/Savor/style/topbar/bullet-threading.css", "列表子弹线").setAttribute("bulletThreading", "列表子弹线");
},
() => {
document.getElementById("列表子弹线").remove();
},
true
);
}
//去除主题所有滤镜还原按钮状态
function qucuFiiter() {
var Topicfilters = document.querySelectorAll("head [topicfilter]");
Topicfilters.forEach(element => {
var offNo = getItem(element.getAttribute("topicfilter"));
if (offNo == "1") {
document.getElementById(element.getAttribute("topicfilter")).click();
element.remove();
}
});
}
/**----------------------------------自动展开悬浮窗折叠列表,展开搜索条目折叠列表,聚焦单独列表-----体验优化----------------------------------*/
function autoOpenList() {
setInterval(() => {
//找到所有的悬浮窗
var Preview = document.querySelectorAll("[data-oid]");
//如果发现悬浮窗内首行是折叠列表就展开并打上标记
if (Preview.length != 0) {
for (let index = 0; index < Preview.length; index++) {
const element = Preview[index];
var item = element.children[1].children;
for (let index = 0; index < item.length; index++) {
var obj = item[index].children[1]
if (obj == null) continue;
const element = obj.children[0].children[0];
if (element == null) continue;
if (element.className != "li") continue;//判断是否是列表
if (element.getAttribute("foldTag") != null) continue;//判断是否存在标记
if (element.getAttribute("foid") == 0) continue;//判断是折叠
element.setAttribute("fold", 0);
element.setAttribute("foldTag", true);
}
}
}
var searchPreview = document.querySelector("#searchPreview [data-doc-type='NodeListItem'].protyle-wysiwyg.protyle-wysiwyg--attr>div:nth-child(1)");
if (searchPreview != null && searchPreview.getAttribute("data-type") == "NodeListItem" && searchPreview.getAttribute("fold") == 1) {
if (searchPreview.getAttribute("foldTag") != null) return;//判断是否存在标记
searchPreview.setAttribute("fold", 0);
searchPreview.setAttribute("foldTag", true);
}
var contentLIst = document.querySelectorAll(".layout-tab-container>.fn__flex-1.protyle:not(.fn__none) [data-doc-type='NodeListItem'].protyle-wysiwyg.protyle-wysiwyg--attr>div:nth-child(1)");
for (let index = 0; index < contentLIst.length; index++) {
const element = contentLIst[index];
if (element != null && element.getAttribute("data-type") == "NodeListItem" && element.getAttribute("fold") == 1) {
if (element.getAttribute("foldTag") != null) return;//判断是否存在标记
element.setAttribute("fold", 0);
element.setAttribute("foldTag", true);
}
}
}, 500)
}
/**----------------------------------列表折叠内容预览查看---------------------------------- */
function collapsedListPreview() {
BodyEventRunFun("mouseover", collapsedListPreviewEvent, 3000)
}
function collapsedListPreviewEvent() {
var _turn = [...document.querySelectorAll(".layout-tab-container>.fn__flex-1.protyle:not(.fn__none) [data-node-id].li[fold='1']"),
...document.querySelectorAll("[data-oid] [data-node-id].li[fold='1']"),
...document.querySelectorAll("#searchPreview [data-node-id].li[fold='1']")];//查询页面所有的折叠列表
var turn = [];
for (let index = 0; index < _turn.length; index++) {//找到列表第一列表项(父项)
const element = _turn[index].children[1];
var item = element.className;
if (item == "p" || item == "h1" || item == "h2" || item == "h3" || item == "h4" || item == "h5" || item == "h6") {
turn.push(element.children[0])
}
}
//检查注册事件的折叠列表是否恢复未折叠状态,是清除事件和去除标志属性
var ListPreview = [...document.querySelectorAll(".layout-tab-container>.fn__flex-1.protyle:not(.fn__none) [ListPreview]"),
...document.querySelectorAll("[data-oid] [ListPreview]"),
...document.querySelectorAll("#searchPreview [ListPreview]")];
for (let index = 0; index < ListPreview.length; index++) {
const element = ListPreview[index];
var fold = element.parentElement.getAttribute("fold")
if (fold == null || fold == 0) {
element.removeAttribute("ListPreview");
var item = element.children[0];
myRemoveEvent(item, "mouseenter", LIstIn);//解绑鼠标进入
myRemoveEvent(item.parentElement.parentElement, "mouseleave", LIstout);//解绑鼠标离开
items = Array.from(item.parentElement.parentElement.children);
for (let index = 0; index < items.length; index++) {
const element = items[index];
if (element.getAttribute("triggerBlock") != null) {
element.remove();
}
}
}
}
for (let index = 0; index < turn.length; index++) {//重新注册、筛选未注册鼠标事件折叠列表
const element = turn[index];
var elementPP = element.parentElement.parentElement;
if (element.parentElement.getAttribute("ListPreview") != null) {
myRemoveEvent(element, "mouseenter", LIstIn);//解绑鼠标进入
myRemoveEvent(elementPP, "mouseleave", LIstout);//解绑鼠标离开
AddEvent(element, "mouseenter", LIstIn);//注册鼠标进入
AddEvent(elementPP, "mouseleave", LIstout);//注册鼠标离开
} else {
element.parentElement.setAttribute("ListPreview", true);
AddEvent(element, "mouseenter", LIstIn);//注册鼠标进入
AddEvent(elementPP, "mouseleave", LIstout);//注册鼠标离开
}
}
}
var flag22 = false;
function LIstout(e) {
items = Array.from(e.target.children);
flag22 = false;
for (let index = 0; index < items.length; index++) {
const element = items[index];
if (element.getAttribute("triggerBlock") != null) {
element.remove();
}
}
}
function LIstIns(e) {
var id = setInterval(() => {
if (!flag22) {
clearInterval(id);
return;
}
var obj = e.target;
var timeDiv = addinsertCreateElement(obj, "div");
timeDiv.style.display = "inline-block";
timeDiv.style.width = "0px";
timeDiv.style.height = "16px";
var X = timeDiv.offsetLeft;
var Y = timeDiv.offsetTop;
timeDiv.remove();
var item = obj.parentElement.parentElement;
if (item == null) return;
items = item.children
var itemobj = items[items.length - 1];
if (itemobj != null && itemobj.getAttribute("triggerBlock") != null) {
var items1 = items[items.length - 1];
items1.style.top = (Y + 35) + "px";
items1.style.left = (obj.offsetLeft + 35) + "px";
var items2 = items[items.length - 2];
items2.style.top = (Y + 2) + "px";
items2.style.left = (X + 45) + "px";
return;
}
}, 500);
}
function LIstIn(e) {
flag22 = true;
var obj = e.target;
var timeDiv = addinsertCreateElement(obj, "div");
timeDiv.style.display = "inline-block";
timeDiv.style.width = "0px";
timeDiv.style.height = "16px";
var X = timeDiv.offsetLeft;
var Y = timeDiv.offsetTop;
timeDiv.remove();
var f = obj.parentElement.parentElement;
if (!f) return;
items = f.children;
var itemobj = items[items.length - 1];
if (itemobj != null && itemobj.getAttribute("triggerBlock") != null) return;
var triggerBlock1 = CreatetriggerBlock(e)//创建触发块1
//设置触发块样式,将触发块显示在〔 ··· 〕第二行位置
triggerBlock1.style.top = (Y + 35) + "px";
triggerBlock1.style.left = (obj.offsetLeft + 35) + "px";
AddEvent(triggerBlock1, "mouseenter", () => {
//一秒延时后搜索打开的悬浮窗,将悬浮窗中的列表展开,重复检查三次
setTimeout(Suspended, 1000)
});//注册鼠标进入
var triggerBlock2 = CreatetriggerBlock(e)//创建触发块2
//设置触发块样式,将触发块显示在〔 ··· 〕位置
triggerBlock2.style.top = (Y + 2) + "px";
triggerBlock2.style.left = (X + 45) + "px";
AddEvent(triggerBlock2, "mouseenter", () => {
//一秒延时后搜索打开的悬浮窗,将悬浮窗中的列表展开,重复检查三次
setTimeout(Suspended, 1000)
});//注册鼠标进入
//一秒延时后搜索打开的悬浮窗,将悬浮窗中的列表展开,重复检查三次
var previewID = obj.parentElement.parentElement.getAttribute("data-node-id");
var jisu = 0;
function Suspended() {
jisu++;
var y = false;
if (jisu == 3) return
var Sd = document.querySelectorAll("[data-oid]");
if (Sd.length >= 1) { //如果找到那么就将悬浮窗中列表展开
for (let index = 0; index < Sd.length; index++) {
const element = Sd[index];
var item = element.children[1].children[0].children[1].children[0].children[0];
if (item == null) continue;
if (item.getAttribute("data-node-id") == previewID) {
item.setAttribute("fold", 0);
y = true;
}
}
}
if (!y) { setTimeout(Suspended, 800) }
}
LIstIns(e);
}
function CreatetriggerBlock(e) {
var objParent = e.target.parentElement;
var triggerBlock = addinsertCreateElement(objParent.parentElement, "div");//创建触发块
//设置触发块样式,将触发块显示在〔 ··· 〕位置
triggerBlock.setAttribute("triggerBlock", true);
triggerBlock.style.position = "absolute";
triggerBlock.style.width = "20px";
triggerBlock.style.height = "15px";
//triggerBlock.style.background="red";
triggerBlock.style.display = "flex";
triggerBlock.style.zIndex = "999";
triggerBlock.style.cursor = "pointer";
triggerBlock.style.WebkitUserModify = "read-only";
triggerBlock.setAttribute("contenteditable", "false");
triggerBlock.innerHTML = "​";
//获取折叠列表ID,设置悬浮窗
//protyle-wysiwyg__embed data-id
var previewID = objParent.parentElement.getAttribute("data-node-id");
triggerBlock.setAttribute("class", "protyle-attr");
triggerBlock.style.backgroundColor = "transparent";
//在触发块内创建思源超链接
triggerBlock.innerHTML = "<span data-type='a' class='list-A' data-href=siyuan://blocks/" + previewID + ">####</span>";
//将这个思源连接样式隐藏
var a = triggerBlock.children[0];
a.style.fontSize = "15px";
a.style.lineHeight = "15px";
a.style.color = "transparent";
a.style.textShadow = "none";
a.style.border = "none";
return triggerBlock;
}
/**----------------鼠标中键标题、列表文本折叠/展开----------------*/
function collapseExpand_Head_List() {
var flag45 = false;
AddEvent(document.body, "mouseup", () => {
flag45 = false;
});
AddEvent(document.body, "mousedown", (e) => {
if (e.button == 2) { flag45 = true; return }
if (flag45 || e.shiftKey || e.altKey || e.button != 1) return;
var target = e.target;
if (target.getAttribute("contenteditable") == null) {
isFatherFather(target, (v) => {
if (v.getAttribute("contenteditable") != null) {
target = v;
return true;
}
return false;
}, 10);
}
var targetParentElement = target.parentElement;
if (targetParentElement == null) return;
//是标题吗?
if (targetParentElement != null && targetParentElement.getAttribute("data-type") == "NodeHeading") {
var targetParentElementParentElement = targetParentElement.parentElement;
//标题父元素是列表吗?
if (targetParentElementParentElement != null && targetParentElementParentElement.getAttribute("data-type") == "NodeListItem") {
e.preventDefault();
//列表项实现折叠
_collapseExpand_NodeListItem(target);
} else {
e.preventDefault();
//标题块标项实现折叠
_collapseExpand_NodeHeading(target);
}
} else {//是列表
var targetParentElementParentElement = targetParentElement.parentElement;
if (targetParentElementParentElement != null && targetParentElementParentElement.getAttribute("data-type") == "NodeListItem") {
e.preventDefault();
//列表项实现折叠
_collapseExpand_NodeListItem(target);
}
}
});
//标题,块标实现折叠
function _collapseExpand_NodeHeading(element) {
var i = 0;
while (element.className != "protyle" && element.className != "fn__flex-1 protyle" && element.className != "block__edit fn__flex-1 protyle" && element.className != "fn__flex-1 spread-search__preview protyle") {
if (i == 999) return;
i++;
element = element.parentElement;
}
var ddddd = element.children;
for (let index = ddddd.length - 1; index >= 0; index--) {
const element = ddddd[index];
if (element.className == "protyle-gutters") {
var fold = diguiTooONE_1(element, (v) => { return v.getAttribute("data-type") === "fold"; })
if (fold != null) fold.click();
return;
}
}
}