-
Notifications
You must be signed in to change notification settings - Fork 30
/
memos.js
2386 lines (2289 loc) · 124 KB
/
memos.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
/**
* memos.js 24.7.22
* https://immmmm.com/
*/
var memosData = {
dom:"#memos",
listDom:"#memo-list",
limit:"8"
}
var memosDom = document.querySelector(memosData.dom);
let memoList
var memoDefaultList = [
{
"creatorName": "林木木",
"website": "https://immmmm.com",
"link": "https://me.edui.fun",
"creatorId": "101",
"avatar": "https://gravatar.memobbs.app/avatar/ba83fa02fc4b2ba621514941307e21be?s=80",
"twikoo": "https://metk.edui.fun"
},{
"creatorName": "归臧",
"website": "https://nuoea.com",
"link": "https://memos.nuoea.com",
"creatorId": "101",
"avatar": "https://gravatar.memobbs.app/avatar/020d365ea2596ef6d516143bb0552704?s=80",
"twikoo": "https://twikoo.nuoea.com"
},{
"creatorName": "koobai",
"website": "https://koobai.com",
"link": "https://memos.koobai.com",
"creatorId": "1",
"avatar": "https://gravatar.memobbs.app/avatar/3b3d336a7d389b7ae8531cbe177ae9b7?s=80",
"artalk": "https://c.koobai.com",
"artSite": "空白唠叨"
}
];
var userNow = `
<div class="user-now card-item flex-fill mb-3 row">
<div class="call-memos-editor item-avatar p-3 "><img class="user-now-avatar" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/ style="pointer-events: none;"></div>
<span class="user-now-name"></span>
<div class="row-fill">
<input class="search-memos-input border-b input-text py-2 animate__animated animate__fadeIn animate__fadeInRight d-none" type="text" placeholder="想搜点啥?" id="">
<span class="search-memos-btn button d-md-flex p-2 mr-2">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="11" cy="11" r="8"/><path d="m21 21l-4.3-4.3"/></g></svg>
</span>
<div class="user-button-span row-fill">
<span class="memos-theme-toggle button d-md-flex p-2 mr-2">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8a2.83 2.83 0 0 0 4 4a4 4 0 1 1-4-4m0-6v2m0 16v2M4.9 4.9l1.4 1.4m11.4 11.4l1.4 1.4M2 12h2m16 0h2M6.3 17.7l-1.4 1.4M19.1 4.9l-1.4 1.4"/></svg>
</span>
<span class="my-blog-feeds button d-md-flex p-2 mr-2">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M10 10v.2A3 3 0 0 1 8.9 16v0H5v0h0a3 3 0 0 1-1-5.8V10a3 3 0 0 1 6 0m-3 6v6m6-3v3"/><path d="M12 19h8.3a1 1 0 0 0 .7-1.7L18 14h.3a1 1 0 0 0 .7-1.7L16 9h.2a1 1 0 0 0 .8-1.7L13 3l-1.4 1.5"/></g></svg>
</span>
<span class="userlist-memos button d-md-flex p-2 mr-2">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M22 21v-2a4 4 0 0 0-3-3.87m-3-12a4 4 0 0 1 0 7.75"/></g></svg>
</span>
<span class="randomuser-memos button d-md-flex p-2 mr-2">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v-2.38C4 11.5 2.97 10.5 3 8c.03-2.72 1.49-6 4.5-6C9.37 2 10 3.8 10 5.5c0 3.11-2 5.66-2 8.68V16a2 2 0 1 1-4 0m16 4v-2.38c0-2.12 1.03-3.12 1-5.62c-.03-2.72-1.49-6-4.5-6C14.63 6 14 7.8 14 9.5c0 3.11 2 5.66 2 8.68V20a2 2 0 1 0 4 0m-4-3h4M4 13h4"/></svg>
</span>
<span class="gobbs-memos button d-md-flex p-2 mr-2">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.8 20v-4.1l1.9.2a2.3 2.3 0 0 0 2.164-2.1V8.3A5.37 5.37 0 0 0 2 8.25c0 2.8.656 3.054 1 4.55a5.77 5.77 0 0 1 .029 2.758L2 20m17.8-2.2a7.5 7.5 0 0 0 .003-10.603M17 15a3.5 3.5 0 0 0-.025-4.975"/></svg>
</span>
<span class="gohome-memos button d-md-flex p-2 mr-3">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="m3 9l9-7l9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><path d="M9 22V12h6v10"/></g></svg>
</span>
</div>
</div>
</div>`
memosDom.insertAdjacentHTML('beforebegin', userNow);
var backTop = `<div class="backtop d-none"><svg xmlns="http://www.w3.org/2000/svg" width="1.25rem" height="1.25rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m18 15l-6-6l-6 6"/></svg></div>`
memosDom.insertAdjacentHTML('afterend', backTop);
var getEditor = window.localStorage && window.localStorage.getItem("memos-editor-display");
var getMode = window.localStorage && window.localStorage.getItem("memos-mode");
var memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token");
var memosPath = window.localStorage && window.localStorage.getItem("memos-access-path");
var memosMeID = window.localStorage && window.localStorage.getItem("memos-me-id");
var memosMeNickname = window.localStorage && window.localStorage.getItem("memos-me-nickname");
var memosMeAvatarUrl = window.localStorage && window.localStorage.getItem("memos-me-avatarurl");
var memosMeArtalk = window.localStorage && window.localStorage.getItem("memos-artalk-input");
var memosMeArtalkSite = window.localStorage && window.localStorage.getItem("memos-artalksite-input");
var memosMeTwikoo = window.localStorage && window.localStorage.getItem("memos-twikoo-input");
let cfwkAiUrl = window.localStorage && window.localStorage.getItem("memos-cfwkai-url")
let geminiKey = window.localStorage && window.localStorage.getItem("memos-gemini-key")
let filterName = window.localStorage && window.localStorage.getItem("memos-filter-name")
var memosEditorCont = `
<div class="memos-editor animate__animated animate__fadeIn col-12 d-none">
<div class="memos-editor-body mb-3 p-3">
<div class="memos-editor-inner animate__animated animate__fadeIn d-none">
<div class="memos-editor-content">
<textarea class="memos-editor-textarea text-sm" rows="1" placeholder="任何想法..."></textarea>
</div>
<div class="memos-image-list d-flex flex-fill line-xl flex-wrap"></div>
<div class="memos-editor-tools pt-1">
<div class="d-flex flex-wrap">
<div class="button outline action-btn biao-qing-btn mr-2">
<svg xmlns="http://www.w3.org/2000/svg" width="1.35rem" height="1.35rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M8 14s1.5 2 4 2s4-2 4-2M9 9h.01M15 9h.01"/></g></svg>
</div>
<div class="button outline action-btn tag-btn mr-2">
<svg xmlns="http://www.w3.org/2000/svg" width="1.35rem" height="1.35rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 9h16M4 15h16M10 3L8 21m8-18l-2 18"/></svg>
</div>
<div class="button outline action-btn codeone-btn mr-2">
<svg xmlns="http://www.w3.org/2000/svg" width="1.35rem" height="1.35rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m8 7l-5 5l5 5m8 0l5-5l-5-5"/></svg>
</div>
<div class="button outline action-btn code-btn mr-2">
<svg xmlns="http://www.w3.org/2000/svg" width="1.35rem" height="1.35rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m7 8l-4 4l4 4m10-8l4 4l-4 4M14 4l-4 16"/></svg>
</div>
<div class="button outline action-btn mr-2 link-btn">
<svg xmlns="http://www.w3.org/2000/svg" width="1.35rem" height="1.35rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 17H7A5 5 0 0 1 7 7h2m6 0h2a5 5 0 1 1 0 10h-2m-7-5h8"/></svg>
</div>
<div class="button outline action-btn mr-2 dropdown aitop">
<svg xmlns="http://www.w3.org/2000/svg" width="1.35rem" height="1.35rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7m4 2h6m-3-3v6"/><circle cx="9" cy="9" r="2"/><path d="m21 15l-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></g></svg>
<div class="dropdown-wrapper d-none">
<span class="btn linkpic-btn">外链</span>
<span class="btn image-btn" onclick="this.nextElementSibling.click()">WebP+</span>
<input class="memos-upload-Webp-image-input d-none" type="file" accept="image/*">
<span class="btn image-btn" onclick="this.nextElementSibling.click()">原图+</span>
<input class="memos-upload-image-input d-none" type="file" accept="image/*">
</div>
</div>
${geminiKey != null && geminiKey !== "" ? `
<div class="button outline geminiai-btn action-btn mr-2 dropdown aitop">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m21.64 3.64l-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72M14 7l3 3M5 6v4m14 4v4M10 2v2M7 8H3m18 8h-4M11 3H9"/></svg>
<div class="dropdown-wrapper d-none">
<span class="btn" onclick="geminiAI(this)">语音润色</span>
<span class="btn" onclick="geminiAI(this)">自动标签</span>
<span class="btn" onclick="geminiAI(this)">育儿帮手</span>
<span class="btn" onclick="geminiAI(this)">智囊团队</span>
<span class="btn" onclick="geminiAI(this)">智能问答</span>
</div>
</div>
<div class="button outline geminiai-load-btn d-none noclick action-btn mr-2 ">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>
</div>` : ""}
${cfwkAiUrl != null && cfwkAiUrl !== "" ? `
<div class="button outline action-btn mr-2 cfworkerai-btn">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M12 8V4H8"/><rect width="16" height="12" x="4" y="8" rx="2"/><path d="M2 14h2m16 0h2m-7-1v2m-6-2v2"/></g></svg>
</div>
<div class="button outline action-btn mr-2 cfworkerai-load-btn d-none noclick">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>
</div>` : ""}
</div>
<div class="d-flex flex-fill">
<div class="memos-tag-list d-none mt-2 animate__animated animate__fadeIn"></div>
</div>
</div>
<div class="memos-editor-footer border-t mt-2 pt-2 flex-wrap">
<div class="d-flex">
<div class="button outline switchUser-btn mr-2 p-2">
<svg xmlns="http://www.w3.org/2000/svg" width=".9rem" height=".9rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M20 7h-9m3 10H5"/><circle cx="17" cy="17" r="3"/><circle cx="7" cy="7" r="3"/></g></svg>
</div>
<div class="button outline private-btn mr-2 p-2">
<svg xmlns="http://www.w3.org/2000/svg" width=".9rem" height=".9rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 10h.01M15 10h.01M12 2a8 8 0 0 0-8 8v12l3-3l2.5 2.5L12 19l2.5 2.5L17 19l3 3V10a8 8 0 0 0-8-8"/></svg>
</div>
<div class="button outline random-btn mr-2 p-2">
<svg xmlns="http://www.w3.org/2000/svg" width=".9rem" height=".9rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M2 18h1.4c1.3 0 2.5-.6 3.3-1.7l6.1-8.6c.7-1.1 2-1.7 3.3-1.7H22"/><path d="m18 2l4 4l-4 4M2 6h1.9c1.5 0 2.9.9 3.6 2.2M22 18h-5.9c-1.3 0-2.6-.7-3.3-1.8l-.5-.8"/><path d="m18 14l4 4l-4 4"/></g></svg>
</div>
<div class="button outline oneday-btn d-none p-2">
<svg xmlns="http://www.w3.org/2000/svg" width=".9rem" height=".9rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="18" height="18" x="3" y="4" rx="2" ry="2"/><path d="M16 2v4M8 2v4m-5 4h18M8 14h.01M12 14h.01M16 14h.01M8 18h.01M12 18h.01M16 18h.01"/></g></svg>
</div>
</div>
<div class="editor-submit d-flex flex-fill justify-content-end">
<div class="editor-selector select outline mr-5">
<select class="select-memos-value pl-2 pr-4 py-2">
<option value="PUBLIC">公开</option>
<option value="PRIVATE">私有</option>
</select>
</div>
<div class="edit-memos d-none">
<button class="outline cancel-edit-btn mr-2 px-2 py-2" title="取消">取消</button>
<button class="primary edit-memos-btn px-5 py-2" title="保存">保存</button>
</div>
<button class="primary submit-memos-btn px-5 py-2" title="记下">记下</button>
</div>
</div>
</div>
<div class="memos-editor-option animate__animated animate__fadeIn d-none">
<div class="row flex-fill mr-3 p-2">
<input name="memos-path-url" class="memos-path-input border-b input-text col-6 py-2" type="text" value="${memosPath ? memosPath : ''}" placeholder="Memo 网址">
<input name="memos-token-url" class="memos-token-input border-b input-text col-6 py-2" type="text" value="${memosOpenId ? memosOpenId : ''}" placeholder="Access Tokens">
<input name="artalk-url" class="memos-artalk-input border-b input-text col-6 py-2" type="text" value="${memosMeArtalk ? memosMeArtalk : ''}" placeholder="[可选]Artalk 评论网址">
<input name="artalk-site-name" class="memos-artalksite-input border-b input-text col-6 py-2" type="text" value="${memosMeArtalkSite ? memosMeArtalkSite : ''}" placeholder="[可选] Artalk 站点名称">
<input name="twikoo-path-url" class="memos-twikoo-input border-b input-text col-6 py-2" type="text" value="${memosMeTwikoo ? memosMeTwikoo : ''}" placeholder="[可选]Twikoo 评论网址">
<input name="cfwkai-url" class="cfwkai-url-input border-b input-text col-6 py-2" type="text" value="${cfwkAiUrl ? cfwkAiUrl : ''}" placeholder="[可选]Cloudflare AI 网址">
<input name="gemini-key" class="gemini-key-input border-b input-text col-6 py-2" type="text" value="${geminiKey ? geminiKey : ''}" placeholder="[可选]Gemini Pro Key">
<input name="filter-name" class="filter-name-input border-b input-text col-6 py-2" type="text" value="${filterName ? filterName : ''}" placeholder="[可选]广场过滤名单( , 分隔多个)">
</div>
<button class="primary submit-openapi-btn px-5 py-2">保存</button>
</div>
</div>
<div class="memos-random d-none"></div>
</div>`;
memosDom.insertAdjacentHTML('afterbegin',memosEditorCont);
var themeTogglebtn = document.querySelector(".memos-theme-toggle");
var myFeedsBtn = document.querySelector(".my-blog-feeds");
var memosEditorInner = document.querySelector(".memos-editor-inner");
var memosEditorOption = document.querySelector(".memos-editor-option");
var memosRadomCont = document.querySelector(".memos-random");
var taglistBtn = document.querySelector(".tag-btn");
var codeoneBtn = document.querySelector(".codeone-btn");
var codeBtn = document.querySelector(".code-btn");
var linkBtn = document.querySelector(".link-btn");
var linkPicBtn = document.querySelector(".linkpic-btn");
var cfAiBtn = document.querySelector(".cfworkerai-btn") || "";
var cfAiLoadBtn = document.querySelector(".cfworkerai-load-btn");
var geminiAIBtn = document.querySelector(".geminiai-btn") || "";
var geminiAILoadBtn = document.querySelector(".geminiai-load-btn");
var randomBtn = document.querySelector(".random-btn");
var oneDayBtn = document.querySelector(".oneday-btn");
var userButton = document.querySelector('.user-button-span');
var privateBtn = document.querySelector(".private-btn");
var switchUserBtn = document.querySelector(".switchUser-btn");
var loadEditorBtn = document.querySelector(".call-memos-editor");
var searchBtn = document.querySelector(".search-memos-btn");
var searchInput = document.querySelector(".search-memos-input");
var userlistBtn = document.querySelector(".userlist-memos");
var randomUserBtn = document.querySelector(".randomuser-memos");
var submitApiBtn = document.querySelector(".submit-openapi-btn");
var submitMemoBtn = document.querySelector(".submit-memos-btn");
var memosVisibilitySelect = document.querySelector(".select-memos-value");
var pathInput = document.querySelector(".memos-path-input");
var tokenInput = document.querySelector(".memos-token-input");
var artalkInput = document.querySelector(".memos-artalk-input");
var artalkSiteInput = document.querySelector(".memos-artalksite-input");
var twikooInput = document.querySelector(".memos-twikoo-input");
var cfwkAiUrlInput = document.querySelector(".cfwkai-url-input");
var geminiKeyInput = document.querySelector(".gemini-key-input");
var filterNameInput = document.querySelector(".filter-name-input");
var uploadImageInput = document.querySelector(".memos-upload-image-input");
//Webp格式
var uploadWebpImageInput = document.querySelector(".memos-upload-Webp-image-input");
var memosTextarea = document.querySelector(".memos-editor-textarea");
var editMemoDom = document.querySelector(".edit-memos");
var editMemoBtn = document.querySelector(".edit-memos-btn");
var cancelEditBtn = document.querySelector(".cancel-edit-btn");
var biaoqingBtn = document.querySelector(".biao-qing-btn");
var usernowDom = document.querySelector(".user-now");
var usernowBtnDom = document.querySelectorAll(".user-now .button");
var goHomeBtn = document.querySelector('.gohome-memos')
var goBbsBtn = document.querySelector('.gobbs-memos')
var memoDom = document.querySelector(memosData.listDom);
var skeleton = `<div class="el-loading"><div class="el-skeleton mb-3"></div><div class="el-skeleton mb-3"></div><div class="el-skeleton width-50 mb-3"></div><div class="el-skeleton mb-3"></div><div class="el-skeleton mb-3"></div><div class="el-skeleton width-50 mb-3"></div></div>`;
var load = `<button class="col-12 load-btn button-load d-none flex-fill mb-3 p-3 animate__animated animate__fadeIn">加载更多</button>`;
memoDom.insertAdjacentHTML('afterend', load);
var loadBtn = document.querySelector("button.button-load");
var limit = memosData.limit,page = 1,nums = 0,dataNum = 0,memosContType = 0, memosAccess = 0,randomUser = 0;
var memoData = [],memosStr = [],memoCreatorMap = {},twikooCount = {},artalkCount = {};
let memosMode;
let nowLink;
let nowId;
let nowName;
let nowAvatar;
let nowV1;
let nowTagList = "";
var memoChangeDate = 0;
var getSelectedValue = window.localStorage && window.localStorage.getItem("memos-visibility-select") || "PUBLIC";
document.addEventListener("DOMContentLoaded", () => {
let getTheme = window.localStorage && window.localStorage.getItem("theme");
if (getTheme !== null && getTheme == "dark"){
document.body.classList.add("dark-theme","dark");
}else{
document.body.classList.remove("dark-theme","dark");
}
if (getTheme == null && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add("dark-theme","dark");
}
});
themeTogglebtn.addEventListener('click', function() {
if(!document.body.classList.contains("dark")){
document.body.classList.add("dark-theme","dark");
window.localStorage && window.localStorage.setItem("theme","dark");
}else{
document.body.classList.remove("dark-theme","dark");
window.localStorage && window.localStorage.setItem("theme","light");
}
});
document.addEventListener("DOMContentLoaded", async () => {
// 获取自定义列表
if(typeof memosJson !== 'undefined'){
try {
memoOurList = await getMemoListData(memosJson.url); // 获取自定义列表
} catch (error) {
memoOurList = memoDefaultList
}
}else{
try {
memoOurList = await getMemoListData("https://memobbs.app/memos.json"); // 获取自定义列表
} catch (error) {
memoOurList = memoDefaultList
}
}
if(typeof memosMyList !== 'undefined'){
const mergedArray = [...memosMyList, ...memoOurList];
memoList = mergedArray.filter((item, index) => {
const stringifiedItem = JSON.stringify(item);
return index === mergedArray.findIndex(obj => {
return JSON.stringify(obj) === stringifiedItem;
});
});
}else{
memoList = memoOurList
}
//查询当前页面 window.location.origin 作为主页展示
let memobbsAdmin = []
let memobbsLink = window.location.origin;
let linkIndex = memoList.findIndex(item => (item.website == memobbsLink))
if(linkIndex >= 0){
memobbsAdmin.push(memoList[linkIndex])
const mergedArray2 = [...memobbsAdmin, ...memoList];
memoList = mergedArray2.filter((item, index) => {
const stringifiedItem = JSON.stringify(item);
return index === mergedArray2.findIndex(obj => {
return JSON.stringify(obj) === stringifiedItem;
});
});
}
nowLink = memosPath || memoList[0].link;
if (!nowLink.endsWith('/')) {
nowLink += '/';
}
nowId = memosMeID || memoList[0].creatorId;
nowName = memosMeNickname || memoList[0].creatorName;
nowAvatar = memosMeAvatarUrl || memoList[0].avatar;
nowV1 = memoList[0].v1 || 'memo'
memoFollow(getMode);
getEditIcon();
});
// 获取自定义 memos.json 订阅列表
async function getMemoListData(url) {
const response = await fetch(url);
const data = await response.json();
if(filterName){
let namesToRemove = filterName.replace(/,/g, ",").split(',');
for (let name of namesToRemove) {
let nameIndex = data.myMemoList.findIndex(item => (item.creatorName == name));
if (nameIndex !== -1) {
delete data.myMemoList.splice(nameIndex, 1);
}
};
}
return data.myMemoList
}
function memoFollow(mode) {
//记忆显示模式
usernowBtnDom.forEach((item) => {item.classList.remove('current');})
if(mode == "MEMOSHOME"){
goHomeBtn.classList.add("current")
getUserMemos(nowLink,nowId,nowName,nowAvatar,"","","MEMOSHOME")
}else if(mode == "MEMOSBBS"){
goBbsBtn.classList.add("current")
getMemos();
}else if(mode == "RANDUSER"){
randomUserBtn.classList.add("current")
goRandUser()
}else if(mode == "NOPUBLIC"){
getUserMemos(nowLink,nowId,nowName,nowAvatar,"","",mode)
}else if(mode == "oneday"){
getUserMemos(nowLink,nowId,nowName,nowAvatar,"","",mode)
}else{
goHomeBtn.classList.add("current")
getUserMemos(nowLink,nowId,nowName,nowAvatar)
}
loadBtn.addEventListener("click", function () {
if(page < dataNum) {
page++;
}
updateData(memoData)
cocoMessage.success("加载中");
});
async function getMemoCount(m) {
let twikooData = m.filter(item => item.twikoo);
if (twikooData.length !== 0) {
let twikooRes = {};
for (const { creatorName, twikoo, link, id } of twikooData) {
if (!twikooRes[creatorName]) {
twikooRes[creatorName] = {
creatorName,
envId: twikoo,
urls: []
};
}
twikooRes[creatorName].urls.push(`${link}m/${id}`);
}
let twikooList = Object.values(twikooRes);
let twikooPromise = await Promise.all(
twikooList.map(async (item) => {
try {
let res = await twikoo.getCommentsCount({
envId: item.envId,
urls: item.urls,
includeReply: false
});
return res;
} catch (err) {
console.error(err);
return [];
}
})
);
twikooCount = twikooPromise.flatMap(r => r);
}
let artalkData = m.filter(item => item.artalk);
if (artalkData.length !== 0) {
let artalkRes = {};
for (const { creatorName, artalk, artSite, link, id } of artalkData) {
if (!artalkRes[creatorName]) {
artalkRes[creatorName] = {
creatorName,
envId: artalk,
site_name: artSite,
link,
urls: []
};
}
artalkRes[creatorName].urls.push(`/m/${id}`);
}
let artalkList = Object.values(artalkRes);
let artalkPromise = await Promise.all(
artalkList.map(async (item) => {
try {
let pageKeys = item.urls.join(',');
let siteName = item.site_name;
let response = await fetch(`${item.envId}/api/v2/stats/page_comment?page_keys=${pageKeys}&site_name=${siteName}`);
if (!response.ok) {
throw new Error(`Request failed`);
}
let results = await response.json();
let countList = item.urls.map(url => {
let count = results.data[url] || 0;
return { url: item.link + url, count };
});
return countList;
} catch (err) {
return [];
}
})
)
artalkCount = artalkPromise.flatMap(r => r);
}
for (const item of m) {
let count = 0;
let url = `${item.link}/m/${item.id}`;
if (item.twikoo) {
let memoCount = twikooCount.find((o) => o.url === url);
if (memoCount) {
count = memoCount.count;
}
} else if (item.artalk) {
let memoCount = artalkCount.find((o) => o.url === url);
if (memoCount) {
count = memoCount.count;
}
}
item.count = count;
}
return m;
}
this.getMemoCount = getMemoCount;
function updateData(res) {
let oneDayTag = window.localStorage && window.localStorage.getItem("memos-oneday-tag");
if(oneDayTag !== null){
const firstItem = res.slice(0, 1);
const restItems = res.slice(1);
// 对后面的内容进行排序
restItems.sort((a, b) => b.createdTs - a.createdTs);
// 将两部分合并在一起
const sortedArray = firstItem.concat(restItems);
// 返回排序后的数组
pagination(sortedArray)
dataNum = Math.ceil(sortedArray.length/limit);
nums = dataNum - 1;
if (page > nums) {
loadBtn.classList.add('d-none');
return
};
}else{
res.sort((i,o)=>{
return( o.createdTs - i.createdTs)
})
pagination(res)
dataNum = Math.ceil(res.length/limit);
nums = dataNum - 1;
if (page > nums) {
loadBtn.classList.add('d-none');
return
};
}
}
this.updateData = updateData;
function pagination(data) {
memosStr = [];
var last = page * limit - 1;
last = last >= data.length ? (data.length - 1) : last;
for (var i = (page * limit - limit); i <= last; i++) {
memosStr.push(data[i])
};
updateHtml(memosStr);
}
};
// 插入 html
async function updateHtml(data) {
let oneDayClass = "oneday";
let tagnowHas = document.querySelector(".memos-tagnow")
let memosMode = window.localStorage && window.localStorage.getItem("memos-mode");
let oneDayTag = window.localStorage && window.localStorage.getItem("memos-oneday-tag");
let result = '',itemOption = '',itemContent = '';
let TAG_REG = /#([^#\s!.,;:?"'()]+)(?= )/g,
IMG_REG = /\!\[(.*?)\]\((.*?)\)/g,
LINK_REG = /(?<!!)\[(.*?)\]\((.*?)\)/g,
LINE_REG = /\n/g,
BLOCKQUDTE_REG = /\>.*$/g,
CODE_REG = /\```.*$/g,
DOUDB_LINK_REG = /(https:\/\/(www|movie|book)\.douban\.com\/(game|subject)\/[0-9]+\/).*?/g,
NEODB_LINK_REG = /(https:\/\/neodb\.social\/(game|movie|tv\/season|book)\/[0-9a-zA-Z]+)(?= )/g,
BILIBILI_REG2 = /{ bilibili ([0-9a-zA-Z]+) }/g,
BILIBILI_REG = /<a.*?href="https:\/\/www\.bilibili\.com\/video\/((av[\d]{1,10})|(BV([\w]{10})))\/?".*?>.*<\/a>/g,
NETEASE_MUSIC_REG = /<a.*?href="https:\/\/music\.163\.com\/.*id=([0-9]+)".*?>.*<\/a>/g,
QQMUSIC_REG = /<a.*?href="https\:\/\/y\.qq\.com\/.*(\/[0-9a-zA-Z]+)(\.html)?".*?>.*?<\/a>/g,
QQVIDEO_REG = /<a.*?href="https:\/\/v\.qq\.com\/.*\/([a-z|A-Z|0-9]+)\.html".*?>.*<\/a>/g,
YOUKU_REG = /<a.*?href="https:\/\/v\.youku\.com\/.*\/id_([a-z|A-Z|0-9|==]+)\.html".*?>.*<\/a>/g,
YOUTUBE_REG = /<a.*?href="https:\/\/www\.youtube\.com\/watch\?v\=([a-z|A-Z|0-9]{11})\".*?>.*<\/a>/g;
marked.setOptions({
breaks: true,
smartypants: false,
langPrefix: 'language-'
});
for (var i = 0; i < data.length; i++) {
let memo = data[i];
//console.log(memo)
let link = memo.link;
if (!link.endsWith('/')) {
link += '/';
}
let memoString = JSON.stringify(memo).replace(/"/g, '"');
let avatar = memo.avatar;
let count = memo.count || "";
let website = memo.website;
let creatorId = memo.creatorId;
let creatorName = memo.creatorName;
let createdTs = memo.createdTs;
let in2Week = Math.floor(new Date().getTime()/ 1000) - createdTs <= 1209600 ? "in2week" : "out2week";
let memosId = createdTs+memo.id;
let memosVisibility = memo.visibility
let twikooEnv = memo.twikoo;
let artalkEnv = memo.artalk;
let artSite = `${memo.artSite}`;
let memosLink = link + "m/" + (memo.uid || memo.name || memo.id);
let memosRes = memo.content
.replace(TAG_REG, "")
.replace(IMG_REG, "")
.replace(DOUDB_LINK_REG, "")
.replace(NEODB_LINK_REG, "")
.replace(LINK_REG, `<a class='primary' href='$2' target='_blank'>$1</a>`)
memosRes = marked.parse(memosRes)
.replace(BILIBILI_REG, `<div class='video-wrapper'><iframe src='//www.bilibili.com/blackboard/html5mobileplayer.html?bvid=$1&as_wide=1&high_quality=1&danmaku=0' scrolling='no' border='0' frameborder='no' framespacing='0' allowfullscreen='true'></iframe></div>`)
.replace(BILIBILI_REG2, `<div class='video-wrapper'><iframe src='//www.bilibili.com/blackboard/html5mobileplayer.html?bvid=$1&as_wide=1&high_quality=1&danmaku=0' scrolling='no' border='0' frameborder='no' framespacing='0' allowfullscreen='true'></iframe></div>`)
.replace(NETEASE_MUSIC_REG, `<meting-js auto='https://music.163.com/#/song?id=$1'></meting-js>`)
.replace(QQMUSIC_REG, `<meting-js auto='https://y.qq.com/n/yqq/song$1.html'></meting-js>`)
.replace(QQVIDEO_REG, `<div class='video-wrapper'><iframe src='//v.qq.com/iframe/player.html?vid=$1' allowFullScreen='true' frameborder='no'></iframe></div>`)
.replace(YOUKU_REG, `<div class='video-wrapper'><iframe src='https://player.youku.com/embed/$1' frameborder=0 'allowfullscreen'></iframe></div>`)
.replace(YOUTUBE_REG, `<div class='video-wrapper'><iframe src='https://www.youtube.com/embed/$1' title='YouTube video player' frameborder='0' allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture' allowfullscreen title='YouTube Video'></iframe></div>`)
let transData = memo.content.replace(TAG_REG, "").replace(IMG_REG, "").replace(LINK_REG, "$1").replace(LINE_REG, " ").replace(BLOCKQUDTE_REG, "").replace(CODE_REG, "");
if(transData.length>140){transData = transData.substring(0,140) + '...'};
let memosForm = {creatorName:creatorName,content:transData,url:memosLink};
let memosFormString = JSON.stringify(memosForm).replace(/"/g, '"');
//解析 content 内 md 格式图片
let imgArr = memo.content.match(IMG_REG);
let imgStr = String(imgArr).replace(/[,]/g, '');
if (imgArr) {
let memosImg = imgStr.replace(IMG_REG, `<div class="memo-resource width-100"><img class="lozad" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="$2"></div>`)
memosRes += `<div class="resource-wrapper"><div class="images-wrapper my-2" view-image>${memosImg}</div></div>`
}
// DoubanDB
let doudbArr = memo.content.match(DOUDB_LINK_REG);
let neodbDom = '';
if(doudbArr){
for(let k=0;k < doudbArr.length;k++){
neodbDom += await fetchNeoDB(doudbArr[k],"douban")
}
}
// DoubanDB
let neodbArr = memo.content.match(NEODB_LINK_REG);
if(neodbArr){
for(let l=0;l < neodbArr.length;l++){
neodbDom += await fetchNeoDB(neodbArr[l],"neodb")
}
}
//标签
let tagArr = memo.content.match(TAG_REG);
let memosTag = '';
if (tagArr) {
memosTag = tagArr.map(t=>{
return `<div class="item-tag d-flex align-items-center text-sm line-xl mr-2 px-2" onclick="getTagNow('${link}','${creatorId}','${creatorName}','${avatar}',this)">${String(t).replace(/[#]/, '')}</div>`;
}).join('');
}else{
memosTag = `<div class="item-tag d-flex align-items-center text-sm line-xl mr-2 px-2 no-cursor">动态</div>`;
}
//解析内置资源文件
//console.log(memo)
if (memo.resourceList && memo.resourceList.length > 0) {
let resourceList = memo.resourceList;
let imgUrl = '',resUrl = '',resImgLength = 0;
for (let j = 0; j < resourceList.length; j++) {
let restype = resourceList[j].type.slice(0, 5);
let resexlink = resourceList[j].externalLink;
let imgLink = '', fileId = '';
if (resexlink) {
imgLink = resexlink
} else {
fileId = resourceList[j].id;
if(resourceList[j].uid !== undefined){
fileId = resourceList[j].uid
}else if(resourceList[j].name !== undefined){
fileId = resourceList[j].name+"?thumbnail=1"
}
imgLink = `${link}o/r/${fileId}`;
}
if (restype == 'image') {
imgUrl += `<div class="memo-resource w-100"><img class="lozad" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="${imgLink}"/></div>`;
resImgLength = resImgLength + 1
}
if (restype == 'video') {
resUrl += `<video style="width:100%;max-height:50vh;" crossorigin="anonymous" src="${imgLink}" controls=""></video>`
}
if (restype !== 'video' && restype !== 'image') {
resUrl += `<a class="memos-tag p-1" target="_blank" rel="noreferrer" href="${imgLink}">${resourceList[j].filename}</a>`;
}
}
if (imgUrl) {
memosRes += `<div class="resource-wrapper"><div class="images-wrapper my-2" view-image>${imgUrl}</div></div>`
}
if (resUrl) {
memosRes += `<p class="datasource">${resUrl}</p>`
}
}
let memosOpenId = window.localStorage && window.localStorage.getItem("memos-access-token");
if (memosOpenId != null && memosOpenId !== "" && nowId == creatorId && nowLink == link) {
itemOption = `<div class="item-option mr-1"><div class="d-flex dropdown"><svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></g></svg><div class="dropdown-wrapper d-none"><a class="btn edit-btn" data-form="${memoString}" onclick="editMemo(this)">编辑</a><a class="btn" onclick="archiveMemo('${memo.id}')">归档</a><a class="btn" onclick="deleteMemo('${memo.id}')">删除</a></div></div></div>`;
}else if (memosOpenId != null && memosOpenId !== "") {
itemOption = `<div class="item-option mr-1">
<div class="d-flex dropdown">
<svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></g></svg>
<div class="dropdown-wrapper d-none">
<a class="btn" data-form="${memoString}" onclick="saveMemo(this)">收藏</a>
<a class="btn" data-form="${memoString}" onclick="viaNow(this)">引用</a>
<a class="btn" href="${memosLink}" target="_blank" rel="noopener noreferrer">跳转</a>
</div>
</div>
</div>`;
}else{
itemOption = `<div class="item-option mr-1"><a class="d-flex" href="${memosLink}" target="_blank" rel="noopener noreferrer"><svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6m4-3h6v6m-11 5L21 3"></path></svg></a></div>`;
}
itemContent = `<div class="item-content"><div class="item-inner">${memosRes}</div><div class="item-footer d-flex mt-2"><div class="d-flex">${memosTag}</div>`;
if (twikooEnv && memosVisibility == "PUBLIC") {
itemContent += `<div class="d-flex flex-fill justify-content-end"><div class="item d-flex align-items-center"><a data-id="${memo.id}" data-time="${createdTs}" data-env="${twikooEnv}" data-path="${memosLink}" onclick="loadTwikoo(this)" rel="noopener noreferrer" class="d-flex"><svg xmlns="http://www.w3.org/2000/svg" width="1.25rem" height="1.25rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2zM8 10h.01M12 10h.01M16 10h.01"/></svg></a><span class="ml-1">${count}</span></div></div></div><div id="${memosId}" class="item-comment mt-3 d-none"></div>`;
} else if (artalkEnv && memosVisibility == "PUBLIC") {
itemContent += `<div class="d-flex flex-fill justify-content-end"><div class="item d-flex align-items-center"><a data-id="${memo.id}" data-time="${createdTs}" data-env="${artalkEnv}" data-path="${artSite}" onclick="loadArtalk(this)" rel="noopener noreferrer" class="d-flex"><svg xmlns="http://www.w3.org/2000/svg" width="1.25rem" height="1.25rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2zM8 10h.01M12 10h.01M16 10h.01"/></svg></a><span class="ml-1">${count}</span></div></div></div><div id="${memosId}" class="item-comment mt-3 d-none"></div>`;
} else if(memosVisibility !== "PUBLIC"){
itemContent += `<div class="d-flex flex-fill justify-content-end"><div class="item d-flex align-items-center mr-1" onclick="getUserMemos('${link}','${creatorId}','${creatorName}','${avatar}','','','NOPUBLIC')"><svg xmlns="http://www.w3.org/2000/svg" width="1.15rem" height="1.15rem" viewBox="0 0 14 14"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M1.68 4.206C2.652 6.015 4.67 7.258 7 7.258c2.331 0 4.348-1.243 5.322-3.052M2.75 5.596L.5 7.481m4.916-.415L4.333 9.794m6.917-4.198l2.25 1.885m-4.92-.415l1.083 2.728"/></svg></div></div></div>`;
} else {
itemContent += `<div class="d-flex flex-fill justify-content-end"></div></div>`;
}
itemContent += `</div></div></div>`
result += `<div class="${memosMode == "MEMOSHOME" && tagnowHas == null &&oneDayTag !== null && i == 0 ? oneDayClass : ''} memo-${memosId} d-flex animate__animated mb-3"><div class="card-item flex-fill p-3"><div class="item-header d-flex mb-3"><div class="d-flex flex-fill"><div onclick="getUserMemos('${link}', '${creatorId}','${creatorName}','${avatar}')" class="item-avatar mr-2" style="background-image:url(${avatar})"></div><div class="item-sub d-flex flex-column p-1"><div class="item-creator"><a href="${website}" target="_blank">${creatorName}</a></div><div class="item-mate ${in2Week} mt-2 text-xs">${new Date(createdTs * 1000 - 5 ).toLocaleString()}</div></div></div>${itemOption}</div>${neodbDom+itemContent}</div></div>`;
} // end for
memoDom.insertAdjacentHTML('beforeend', result);
loadBtn.textContent = "加载更多";
function animation() {
var animate = document.getElementsByClassName("animate__animated");
Array.prototype.slice.call(animate,0).forEach(function(i,index){
const top = i.getBoundingClientRect().top; // 目标元素dom距离顶部的高度
if (top <= window.innerHeight) { // 当top小于等于文档显示区域的高时,就进入可视区域了
i.classList.contains('animate__fadeIn"') ? '' : i.classList.add("animate__fadeIn")
}
})
}
animation();
window.addEventListener('scroll', animation);
//图片灯箱
window.ViewImage && ViewImage.init('.images-wrapper img')
//相对时间
window.Lately && Lately.init({
target: '.item-mate.in2week'
});
//延迟加载
let observer = lozad('.lozad');
observer.observe();
//下拉菜单
let dropdowns = document.querySelectorAll(".dropdown");
Array.from(dropdowns).forEach(function(dropdown) {
let lis = Array.from(dropdown.children).slice(1);
dropdown.addEventListener("mouseenter", function() {
lis.forEach(function(item) {
item.classList.remove("d-none");
});
});
dropdown.addEventListener("mouseleave", function() {
lis.forEach(function(item) {
item.classList.add("d-none");
});
});
});
}
function withTimeout(millis, promise) {
let timeout = new Promise((resolve, reject) =>
setTimeout(() => reject(`Timed out after ${millis} ms.`), millis)
);
return Promise.race([promise, timeout]);
};
async function getMemos(search) {
memoData = [], memoCreatorMap = {}, page = 1, nums = 0, dataNum = 0, memosContType = 0, memosAccess = 0;
memoDom.innerHTML = skeleton;
loadBtn.classList.add("d-none");
let results;
if(search && search != "" && search != null ){
results = await Promise.allSettled(memoList.map(u => {
let uLink = u.link
if (!uLink.endsWith('/')) {
uLink += '/';
}
const fetchUrl = `${uLink}api/v1/memo?creatorId=${u.creatorId}&content=${search}&rowStatus=NORMAL&limit=${limit}`;
return withTimeout(2000, fetch(fetchUrl)
.then(response => {
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json();
})
);
}));
}else{
results = await Promise.allSettled(memoList.map(async(u) => {
let matchedMemo = memoList.find(item => item.link === u.link);
let matchedV1 = matchedMemo ? matchedMemo.v1 : undefined;
let fetchUrl;
let uLink = u.link
if (!uLink.endsWith('/')) {
uLink += '/';
}
if (matchedV1) {
const filter = `creator=='users/${matchedMemo.creatorId}'&&visibilities==['PUBLIC']`
fetchUrl = `${uLink}api/v1/memos?pageSize=${limit}&filter=${encodeURIComponent(filter)}`
}else{
fetchUrl = `${uLink}api/v1/memo?creatorId=${u.creatorId}&rowStatus=NORMAL&limit=${limit}`;
}
const response = await withTimeout(2000, fetch(fetchUrl));
if (!response.ok) {
throw new Error(response.statusText);
}
const data = await response.json();
const memosData = matchedV1 ? data.memos : data;
memosData.forEach(item => {
if (matchedV1 && item.createTime) {
item.createdTs = Math.floor(new Date(item.createTime).getTime() / 1000);
}
for (let key in matchedMemo) {
if (matchedMemo.hasOwnProperty(key)) {
item[key] = matchedMemo[key];
}
}
});
return memosData
}));
}
results = results.filter(i => i.status === 'fulfilled');
memoData = results.flatMap(result => result.value);
//memoData = await getMemoCount(memoData);
memoDom.innerHTML = "";
this.updateData(memoData);
setTimeout(function() {
loadBtn.classList.remove('d-none');
}, 1000);
//setTimeout(function() {
window.scrollTo({
top: usernowDom.offsetTop - 30,
behavior: "smooth"
});
//}, 800);
goBbsBtn.classList.remove("noclick")
}
myFeedsBtn.addEventListener('click', function(event) {
loadBtn.classList.add('d-none');
memoDom.innerHTML = skeleton;
usernowBtnDom.forEach((item) => {item.classList.remove('current');})
myFeedsBtn.classList.add("current")
let fetchUrl = "https://cf.edui.fun/all?rule=created&end=20"
fetch(fetchUrl).then(res => res.json()).then(resdata =>{
let myFeedData = resdata.article_data
var myFeedArticle = '';
for (var i = 0;i<myFeedData.length;i++){
var item = myFeedData[i];
myFeedArticle +=`
<div class="card-item flex-fill p-3">
<div class="d-flex flex-fill">
<div class="item-avatar mr-2" style="background-image:url(${item.avatar})"></div>
<div class="item-sub d-flex flex-column p-1">
<div class="item-creator"><a href="${item.link}" target="_blank" rel="noopener nofollow" >${item.title}</a></div>
<span class="myfeeds-floor">${item.floor}</span>
<div class="item-mate mt-2 text-xs">${item.updated}</div>
</div>
</div>
</div>
`;
}
memoDom.innerHTML = `<div class="myfeeds-option row px-2 pb-2">
<div class="myfeeds-xml card-item px-3 py-2 mr-3" data-type="bfind" onclick="myFeedsXML(this)">BlogFinder</div>
<div class="myfeeds-xml card-item px-3 py-2 mr-3" data-type="boyou" onclick="myFeedsXML(this)">博友圈</div>
<div class="myfeeds-xml card-item px-3 py-2 mr-3" data-type="shinian" onclick="myFeedsXML(this)">十年之约</div>
</div>
<div class="myfeeds">${myFeedArticle}</div>`;
window.Lately && Lately.init({
target: '.item-mate'
});
})
});
function myFeedsXML(e){
loadBtn.classList.add('d-none');
let myfeedsDom = document.querySelector(".myfeeds")
document.querySelectorAll('.myfeeds-xml').forEach((item) => {
item.classList.add('noclick');
item.classList.remove('current');
})
e.classList.add("current")
let type = e.getAttribute("data-type")
myfeedsDom.innerHTML = ""
let myFeedArticle = '',entries;
myfeedsDom.innerHTML = skeleton;
if(type=="bfind"){
fetch('https://cors.memobbs.app/https://bf.zzxworld.com/feed.xml').then(response => response.text()).then(str => new window.DOMParser().parseFromString(str, 'text/xml'))
.then(data => {
entries = Array.from(data.querySelectorAll('entry')).map(entry => {
return {
title: entry.querySelector('title').textContent,
link: entry.querySelector('link').getAttribute('href'),
published: entry.querySelector('published').textContent,
creator: entry.querySelector('author name').textContent
};
});
var myFeedArticle = '';
for (var i = 0;i<20;i++){
let item = entries[i];
myFeedArticle +=`
<div class="card-item flex-fill p-3">
<div class="d-flex flex-fill">
<div class="item-avatar mr-2 face" style="background-image:url('https://favicon.memobbs.app?url=${item.link}')"></div>
<div class="item-sub d-flex flex-column p-1">
<div class="item-creator"><a href="${item.link}" target="_blank" rel="noopener nofollow" >${item.title}</a></div>
<span class="myfeeds-floor">${i+1}</span>
<div class="item-mate mt-2 text-xs">${item.published}</div>
</div>
</div>
</div>
`;
myfeedsDom.innerHTML = myFeedArticle
}
document.querySelectorAll('.myfeeds-xml').forEach((item) => {item.classList.remove('noclick');})
window.Lately && Lately.init({target: '.item-mate'});
});
}
if(type=="boyou"){
fetch("https://www.boyouquan.com/feed.xml").then(response => response.text()).then(str => new window.DOMParser().parseFromString(str, 'text/xml'))
.then(data => {
entries = Array.from(data.querySelectorAll('item')).map(entry => {
return {
title: entry.querySelector('title').textContent,
link: decodeURIComponent(entry.querySelector('link').textContent.replace('https://www.boyouquan.com/go?from=feed&link=',"")),
published: entry.getElementsByTagName('dc:date')[0].textContent,
creator: entry.getElementsByTagName('dc:creator')[0].textContent
};
});
for (var i = 0;i<20;i++){
let item = entries[i];
myFeedArticle +=`
<div class="card-item flex-fill p-3">
<div class="d-flex flex-fill">
<div class="item-avatar mr-2 face" style="background-image:url('https://favicon.memobbs.app?url=${item.link}')"></div>
<div class="item-sub d-flex flex-column p-1">
<div class="item-creator"><a href="${item.link}" target="_blank" rel="noopener nofollow" >${item.title}</a></div>
<span class="myfeeds-floor">${i+1}</span>
<div class="item-mate mt-2 text-xs">${item.published}</div>
</div>
</div>
</div>
`;
myfeedsDom.innerHTML = myFeedArticle
}
document.querySelectorAll('.myfeeds-xml').forEach((item) => {item.classList.remove('noclick');})
window.Lately && Lately.init({target: '.item-mate'});
});
}
if(type=="shinian"){
fetch("https://www.foreverblog.cn/api/v1/blog/feeds?page=1").then(res => res.json()).then(resdata =>{
for (var i = 0;i<20;i++){
let item = resdata.data.data[i];
myFeedArticle +=`
<div class="card-item flex-fill p-3">
<div class="d-flex flex-fill">
<div class="item-avatar mr-2" style="background-image:url(https://gravatar.loli.net/avatar/${item.email})"></div>
<div class="item-sub d-flex flex-column p-1">
<div class="item-creator"><a href="${item.link}" target="_blank" rel="noopener nofollow" >${item.title}</a></div>
<span class="myfeeds-floor">${i+1}</span>
<div class="item-mate mt-2 text-xs">${item.created_at}</div>
</div>
</div>
</div>
`;
myfeedsDom.innerHTML = myFeedArticle
}
document.querySelectorAll('.myfeeds-xml').forEach((item) => {item.classList.remove('noclick');})
window.Lately && Lately.init({target: '.item-mate'});
});
}
}
//标签筛选且输入框为空,自动插入标签
memosTextarea.addEventListener('focus', function(event) {
let nowTag = document.querySelector(".memos-tagnow-name")
if(nowTag !== null && memosTextarea.value == ""){
memosTextarea.value = "#"+nowTag.textContent+" ";
}
});
//搜索 Memo
searchBtn.addEventListener("click", function () {
if(searchInput.classList.contains("d-none")){
userButton.classList.add("d-none")
searchInput.classList.remove("d-none")
searchInput.focus();
}else if(!searchInput.classList.contains("d-none") && searchInput.value == ""){
searchInput.classList.add("animate__fadeOutRight")
setTimeout(function() {
userButton.classList.remove("d-none")
searchInput.classList.add("d-none")
searchInput.classList.remove("animate__fadeOutRight")
}, 500);
}else if(searchInput.value !== ""){
searchNow(searchInput.value)
}
searchInput.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
searchNow(searchInput.value)
}
});
});
function searchNow(serchText){
if(serchText !== ""){
let tagnowHas = document.querySelector(".memos-tagnow")
if(tagnowHas) tagnowHas.remove();
let usernowName = document.querySelector(".user-now-name").innerHTML;
let serchDom = `
<div class="memos-tagnow row p-2 mb-2">
<div class="memos-tagnow-title mr-3">当前搜索b:</div>
<div class="memos-tagnow-name card-item pr-2 pl-2" onclick="reloadUser('search')">${serchText}<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-4 h-auto ml-1 opacity-40"><path d="M18 6 6 18"></path><path d="m6 6 12 12"></path></svg></div>
</div>`
memosDom.insertAdjacentHTML('beforebegin', serchDom);
if(usernowName == ""){
getMemos(serchText)
}else{
let userNameIndex = memoList.findIndex(item => (item.creatorName == usernowName));
if(userNameIndex == -1){
getUserMemos(nowLink,nowId,nowName,nowAvatar,"",serchText)
}else{
let userNowData = memoList[userNameIndex]
getUserMemos(userNowData.link,userNowData.creatorId,userNowData.creatorName,userNowData.avatar,"",serchText)
}