-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_management.js
More file actions
1134 lines (971 loc) · 33.1 KB
/
Copy pathclient_management.js
File metadata and controls
1134 lines (971 loc) · 33.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import Networking from "/lib/networking.mjs";
window.Netowrking = new Networking();
function LSGI(id = undefined) {
if (id = undefined) {
throw new Error("LSGI, id is undefined");
}
return localStorage.getItem(id)
}
function GEBI(id = undefined) {
if (id = undefined) {
throw new Error("GEBI, id is undefined");
}
return localStorage.getItem(id)
}
//##########################################################
// imports
//############################################################ imports {{{1
console.info("url:", document.location.href);
//`import { Navbar } from './elements/navbar.js';
// http://127.0.0.1:9999/tests/styles_proper
//import AuthHandler from "/lib/auth_handler.mjs";
//const Authish = new AuthHandler();
//############################################################
// var(s)
//############################################################ global_vars {{{1
let timeout = 0;
//############################################################
// funciton(s)
//############################################################ functions {{{1
function CE(args = { //returns HTML element
"class": undefined,
"id": undefined,
"innerHTML": undefined,
"innerText": undefined,
"style": undefined,
"type": undefined,
"onClick": undefined,
}) {
try {
if (args.type == undefined) args.type == "div";
let elem = document.createElement(args.type);
if (args.class != undefined) elem.className = args.class;
if (args.id != undefined) elem.id = args.id;
if (args.innerHTML != undefined) elem.innerHTML = args.innerHTML;
if (args.innerText != undefined) elem.innerText = args.innerText;
if (args.style != undefined) elem.style = args.style;
if (args.onClick != undefined) {
//if (typeof args.onConfirm == 'function') {
elem.addEventListener(
"click",
args.onClick
)
//}
//else {
//console.warn("onclick is NOT a function, cannot bind!");;
//}
}
return (elem);
}
catch (err) {
console.warn(err);
}
};
async function ErrPopUp(txt = "there was an error!", err = "hey dipshit, your site is broken") {
try {
let myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
let errPopUp = document.createElement('div');
errPopUp.innerText = txt;
//position && styling
errPopUp.style.width = "20em";
errPopUp.style.height = "auto";
errPopUp.style.position = "absolute";
errPopUp.style.left = ((window.innerWidth - errPopUp.getBoundingClientRect().width) / 2 + "px");
resolve('')
}, 10000);
reject();
}).then((msg) => {
console.log(msg);
})
}
catch (err) {
console.warn(err);
}
}
//{{{2 Navbar
function Navbar() {
if (document.getElementsByClassName('navbar').length >= 1) {
console.log('no navbar yet');
return;
}
console.warn("navbar detected, not adding");
try {
console.log("adding navbar styling");
let head = document.getElementsByTagName("head");
let navbar_style = document.createElement("link");
navbar_style.rel = "stylesheet";
navbar_style.href = "/elements/navbar.css"
head[0].appendChild(navbar_style);
console.log("added navbar.css");
}
catch (err) {
console.warn("error adding navbar_style: ", err);
}
try {
console.log("adding spacer");
let spacer = document.createElement('div');
spacer.id = "spacer"
spacer.style.height = '0px';
let spacer_height_target = "120px";
let spacer_height_increment = 10;
document.body.prepend(document.createElement('br'));
document.body.prepend(document.createElement('br'));
document.body.prepend(document.createElement('br'));
document.body.prepend(document.createElement('br'));
document.body.prepend(document.createElement('br'));
// TODO: finish me
}
catch (err) {
}
try {
window.addEventListener('load', function() { })
//navbar Element
let navbar = document.createElement('navbar');
//navbar.textContent = "⑤navbar navbar navbar";
navbar.classList += "navbar";
let icon_container = document.createElement('div');;
icon_container.id = 'navbar_icon_container';
let home_anchor = document.createElement('a');
home_anchor.id = "home_anchor";
home_anchor.href = "/";
home_anchor.target = "";
icon_container.appendChild(home_anchor);
navbar.appendChild(icon_container);
let home_logo_div = document.createElement('div');;
let home_logo = document.createElement('img');
home_logo.id = "home_logo";
home_logo.height = "256";
home_logo.width = "256";
home_logo.style.margin = 'auto';
//the link here is relivant to the html file or the project core, NOT this file
//console.log("navbar ROOT_DIR: ", localStorage.getItem("ROOT_DIR"));
if (String(window.location).includes('vulbyte.com')) {
home_logo.src = `https://raw.githubusercontent.com/vulbyte/vulbyteDotCom/0b0fcb64b46a2665d622ce094517332ab6b6cb7f/assets/icon.svg`;
}
else if (String(window.location).includes('pages.dev')) {
home_logo.src = `https://raw.githubusercontent.com/vulbyte/vulbyteDotCom/209022ef5f7b1dd9f61e0892cd3555a1a27f47a3/assets/preview_icon.svg`;
}
else {
console.log('non-pub environment detected');
home_logo.src = `https://raw.githubusercontent.com/vulbyte/vulbyteDotCom/0b0fcb64b46a2665d622ce094517332ab6b6cb7f/assets/dev_icon.svg`;
}
home_logo_div.style.margin = 'auto';
home_logo_div.style.alignContent = 'center';
home_logo_div.style.alignItems = 'center';
home_logo_div.style.textAlign = 'center';
home_logo_div.appendChild(home_logo);
home_anchor.appendChild(home_logo_div);
let random_strings = [
'fuck you, you got an rng of 0', //make something special
'hey, joey salads here',
`what you lookin' at?`,
'yip yap yop',
'peanut jelly',
'made you look',
':3',
'you look nice today :)',
`this isn't a minecraft reference`,
'¡¿por que maria?!',
'sushi!',
'tacos!',
'hashbrowns!',
`>vulbyte_was_here<`,
`rush 2049`,
`i didn't slap you`,
`sonic for hire`,
`dead men tell some tales`,
`~wiggle wiggle~`,
`*shits pants*`,
`gotta go fast!`,
`now blasingly fast!`,
`no longer using hamsters!`,
"dont buy spotify premium",
"linus said the hard R",
"shout out to @bubbshalub",
"subscribe to youtube",
"incredibles 2 sucked",
"192.168.0.1",
"sonadow",
"markiplier's #1 fan",
"drink milk",
"jesus loves tacos",
"its called twitter",
"mike tyson won",
"dont refresh the page",
"DONT LOOK BEHIND YOU",
"i shid pant",
`your ip is: 192.169.0.9`,
`console.log('installing virus')`,
`9+10=21`,
`4x4=12`,
`while(1<2)`,
'some_title',
`random_website_title`,
'now with 100% more ai! (100% more of 0 is 0)',
`shutup i'm listening to cheerleeder`,
`eat the soap :3 (don't)`,
`currently chasing a dog down the road`,
`macbook in da carr`,
`The Boy Bands Have Won, and All the Copyists and the Tribute Bands and the TV Talent Show Producers Have Won, If We Allow Our Culture to Be Shaped by Mimicry, Whether from Lack of Ideas or from Exaggerated Respect. You Should Never Try to Freeze Culture. What You Can Do Is Recycle That Culture. Take Your Older Brother's Hand - Me - Down Jacket and Re - Style It, Re - Fashion It to the Point Where It Becomes Your Own.But Don't Just Regurgitate Creative History, or Hold Art and Music and Literature as Fixed, Untouchable and Kept Under Glass. The People Who Try to 'Guard' Any Particular Form of Music Are, Like the Copyists and Manufactured Bands, Doing It the Worst Disservice, Because the Only Thing That You Can Do to Music That Will Damage It Is Not Change It, Not Make It Your Own. Because Then It Dies, Then It's Over, Then It's Done, and the Boy Bands Have Won`,
]
let home_string = document.createElement('span');
home_string.id = "home_string";
home_string.innerText = random_strings[Math.floor(Math.random() * random_strings.length)];
home_string.style.display = 'block';
home_string.style.margin = 'auto';
home_string.style.padding = '0px';
// below is for testing the worst case scenerio
//home_string.innerText = random_strings[random_strings.length - 1];
let len = home_string.innerText.length;
//console.log("🏠:", len);
let default_font_size = 16;
home_string.style.fontSize = ((Math.abs((len / 900) - 1)) * 12) + 4 + "px";
home_anchor.appendChild(home_string);
let support_link = document.createElement('a');
support_link.innerText = 'support me :3';
support_link.href = '/support.html'
support_link.style.margin = 'auto';
support_link.style.color = 'var(--color_tertiary)';
support_link.style.cursor = 'pointer';
// TODO:: fix this when done
// icon_container.appendChild(support_link);
// TODO:ADD LOGIC FOR HOMETEXT WITH MOBILE SCREENS
//let home_text = document.createElement('p');
//home_text.innerText = "VULBYTE"
//navbar.appendChild(home_text);gt
//home_anchor.appendChild(home_text);
// TODO: add: HOME, LINKS, PROJECTS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
let locations = {
"content": '/content.html',
"links": '/links.html',
"account": '/account.html',
};
Object.keys(locations).forEach((l) => {
let newElem = document.createElement('a');
newElem.id = `navbar_dropdown_link_${l}`;
newElem.style.textAlign = 'center';
newElem.style.verticalAlign = 'center';
newElem.style.display = 'flex';
newElem.style.justifyContent = 'center';
newElem.style.alignItems = 'center';
newElem.innerText = l;
newElem.href = "/" + l + ".html";
// switch for different specalties
switch (l) {
case ("content"):
console.log("creating content dropdown");
let content_dropdown = document.createElement("ul");
content_dropdown.id = "content_dropdown";
let content_dirs = [
"code_stuff",
"game_rankings",
"video_scripts",
];
content_dirs.forEach((i) => {
console.log(`creating dropdown item: ${i}`);
let dd_item = document.createElement("li");
let dd_link = document.createElement("a");
dd_link.innerText = `${i}`;
if (i = "game_rankings") {
dd_link.href = `/${i}.html`;
}
else {
dd_link.href = `/content/${i}/${i}.html`;
}
dd_item.appendChild(dd_link);
content_dropdown.appendChild(dd_item);
});
newElem.appendChild(content_dropdown);
break;
case ("account"):
//document.getElementById('')
let u_i = document.createElement('img');
//TODO: check local storage for login creds then use icon here
u_i.src = '/assets/unknown_user.png';
u_i.style.width = '3em';
u_i.style.height = '3em';
/*document
.getElementById(`navbar_dropdown_link_${l}`)
.appendChild(u_i)*/
newElem.appendChild(u_i);
default:
break;
}
navbar.appendChild(newElem);
});
//let navbar.appendChild4gt
//add it all to the document
document.body.insertBefore(navbar, document.body.firstChild);
//setTimeout((() => {
//}), 500);
console.log("navbar height: ", navbar.getBoundingClientRect().height);
let spacer;
try {
spacer = document.getElementById("spacer");
if (spacer == null) { throw new Error("spacer is null") }
}
catch (err) {
console.warn(err);
spacer = document.createElement("div");
}
spacer.style += `height: ${navbar.getBoundingClientRect().height * 0.3}px`;
console.log("navbar added");
}
catch (err) {
console.error('cannot add navbar:', err);
}
}
//}}}2
//{{{2 footer
function Footer() {
try {
console.log('adding footer');
if (
document.getElementById('footer') >= 1 &&
document.getElementsByTagName('footer') <= 0
) {
console.log('footer already added, ignoring');
}
///{{{3 CreateFooterContainer
function CreateFooterContainer() {
let f = document.createElement('footer');
f.style.backgroundColor = 'var(--color_secondary)';
//f.style.bottom = '0px';
f.style.display = 'grid';
f.style.gridTemplateColumns = 'repeat(auto-fit, minmax(256px, 1fr))';
f.style.height = 'auto';
//f.style.left = '0px';
f.style.paddingTop = '1.5em';
f.style.margin = 'auto';
//f.style.position = 'fixed';
f.style.width = '100%';
//f.style.border = "var(--border-default)";
/*
let hr = document.createElement("hr");
hr.style.width = "100%";
hr.style.height = "0px";
f.appendChild(hr);
*/
return f;
}
///}}}3
let f = CreateFooterContainer();
///{{{3 CreateFooterTitle()
function CreateFooterTitle() {
let f_h = document.createElement('h6');
f_h.innerText = 'Footer';
return f_h;
}
//f.appendChild(CreateFooterTitle());
///}}}3
function CreateImportantLinks() {
let f_c = document.createElement("div");
let title = document.createElement("h6");
title.innerText = "important links";
f_c.appendChild(title);
let list = [
'/policies/privacy',
'terms_of_service',
'gift_art',
];
let ol = document.createElement('ol');
let li, a;
for (let i = 0; i < list.length; ++i) {
switch(list[i]){
case("/policies/privacy"):
li = document.createElement('li');
a = document.createElement('a');
a.innerText = list[i];
a.href = (list[i] + '.html');
li.appendChild(a);
f_c.appendChild(li);
return f_c;
default:
li = document.createElement('li');
a = document.createElement('a');
a.innerText = list[i];
a.href = (list[i] + '.html');
li.appendChild(a);
f_c.appendChild(li);
return f_c;
}
}
return f_c;
};
f.appendChild(CreateImportantLinks());
///{{{3 CreateAbout()
function CreateAbout() {
let about = document.createElement('div');
//about.innerText = 'about';
let a_h = document.createElement('h6');
//a_h.style.backgroundColor = 'transparent';
//a_h.style.color = 'var(--color_text_primary)';
a_h.innerText = 'about';
about.appendChild(a_h);
let a_text = document.createElement('p');
a_text.innerText = 'this is a website made by vulbyte to show off projects, network things, and offer some forms of transparency and what not. hope you enjoy :3'
about.appendChild(a_text);
return about;
}
///}}}3
f.appendChild(CreateAbout());
///{{{3 CreateNavigation()
function CreateNavigation() {
let n = document.createElement('div');
//n.innerText = 'navigation';
let n_h = document.createElement('h6');
n_h.innerText = 'navigation';
n.appendChild(n_h);
let n_l = document.createElement('ul');
let footer_links = {
'content': '/content/content.html',
'links': '/links/links.html',
'policies': '/policies.html',
'useful_links': '/useful_resources.html',
};
try {
console.log('adding nav items for footer');
for (let i = 0; i < Object.keys(footer_links).length; ++i) {
console.log('loop');
let a = document.createElement('a');
a.style.display = 'block';
a.innerText = Object.keys(footer_links)[i];
a.href = Object.values(footer_links)[i];
a.target = '_blank';
n_l.appendChild(a);
}
console.log('added nav items for footer');
n.appendChild(n_l);
}
catch (err) {
console.log('error adding nav items to footer: ', err);
}
return n;
}
///}}}3
f.appendChild(CreateNavigation());
//{{{3
function CreateTerms() {
let f_c = document.createElement("div");
let title = document.createElement("h6");
title.innerText = "terms and privacy";
f_c.appendChild(title);
let list = [
'privacy_policy',
'terms_of_service',
];
let ol = document.createElement('ol');
for (let i = 0; i < list.length; ++i) {
let li = document.createElement('li');
let a = document.createElement('a');
a.innerText = list[i];
a.href = (list[i] + '.html');
li.appendChild(a);
f_c.appendChild(li);
}
return f_c;
}
f.appendChild(CreateTerms());
//}}}3
//{{{3 create support
function CreateSupport() {
let support = document.createElement("div");
let s_e = document.createElement("h6");
s_e.innerText = ("need support?:");
support.appendChild(s_e);
let a = document.createElement("a");
a.href = "mailto:support@vulbyte.com";
a.innerText = "support@vulbyte.com";
a.targer = "_blank";
support.appendChild(a);;
return support;
}
//}}}3 create support
f.appendChild(CreateSupport());
let hr = document.createElement("hr");
hr.style.marginTop = "10em";
//document.body.insertAdjacentHTML('beforeend', hr.outerHTML);
//document.body.insertAdjacentHTML('beforeend', f.outerHTML);
document.body.insertAdjacentHTML('afterend', hr.outerHTML);
document.body.insertAdjacentHTML('afterend', f.outerHTML);
console.log('🦶 footer added');
}
catch (err) {
console.error('error add)ing footer', err);
}
}
//}}}2
//############################################################
// runtime
//############################################################ runtime {{{1
//declare self as module
//const self = document.getElementsByTagNameNS('script');
//self.type = "module";
console.log("client_management loaded");
//{{{2 root dir for file mgmt and access
var ROOT_DIR;
try {
//let loc = document.location.href;
//loc = loc.slice(0, loc.lastIndexOf("/"));
ROOT_DIR = localStorage.getItem("ROOT_DIR");
if (ROOT_DIR == null) {
throw ("ROOT_DIR is null");
}
console.log("ROOT_DIR = ", ROOT_DIR);
}
catch (err) {
console.warn(err);
// TODO: this
let loc = document.location.href;
let start, end;
// TODO: change this to match against instead of hardcoded
if (loc.indexOf('com') != -1) {
end = loc.indexOf('com');
start = loc.lastIndexOf('/', end - 1);
ROOT_DIR = loc.slice(start, end);
}
else if (loc.indexOf(":", 5) != -1) {
end = loc.indexOf('/', loc.indexOf(':', 5));
start = loc.lastIndexOf('/', end - 1);
ROOT_DIR = loc.slice(start, end);
}
else {
console.error("unable to determine local dir");
}
localStorage.setItem("ROOT_DIR", ROOT_DIR);
console.log("ROOT_DIR = ", ROOT_DIR);
}
//}}}2
//{{{2 style
try {
var global_style = document.createElement('link');
global_style.rel = `stylesheet`;
global_style.href = `/themes/modern_dark.css`;
if (global_style.href.includes("modern_dark.css")) {
let buttons = document.getElementsByTagName("button");
let og;
let style;
let new_style;
let og_rect;
for (let i = 0; i < buttons.length; ++i) {
og = buttons[i];
og_rect = buttons[i].getBoundingClientRect();
style = getComputedStyle(og);
async function ComputeNewStyle() {
let new_style;
new_style += "mix-blend-mode:multiply;"
new_style += `border-radius:${style.borderRadius
} `;
new_style += "box-shadow: inset 0 0 1em" + `${style.background}; `
new_style += "position: absolute;";
new_style += "height:" + `${og_rect.height}px;`;
new_style += "width:" + `${og_rect.width}px;`;
return (new_style);
}
new_style = await ComputeNewStyle();
//let highLight = CE({ type: "div", style: new_style });
//og.insertAdjacentElement('beforebegin', highLight)
/*
let lowLight = CE({ style: og.style });
let shadow = CE({ style: og.style });
let bounceLight = CE({ style: og.style });
*/
}
}
document.getElementsByTagName('head')[0].appendChild(global_style);
console.log('style added');
}
catch (err) {
console.warn(err);
// WARN: do not remove make a module dummy
await ErrPopUp("error adding styling!", err);
}
//}}}2
//{{{2 add navbar
try {
//navbar if no navbar present
console.log("trying to load navbar");
Navbar();
}
catch (err) {
console.error(err);
await ErrPopUp("error adding navbar", err);
}
//}}}2
//{{{2
try {
console.log('trying to add footer');
Footer();
}
catch (err) {
console.log('error adding footer');
}
//}}}2
//{{{2 add dark reader disable
try {
console.log('darkreader disabled');
//<meta name="darkreader-lock">
let dr_dis = document.createElement('meta');
dr_dis.name = 'darkreader-lock';
document.getElementsByTagName('head')[0].appendChild(dr_dis);
}
catch {
}
//}}}2
//{{{2 see if images in storage, if not then load
const favicon_names = [
'icon.svg', 'icon_blue.svg', 'icon_cyan.svg', 'icon_green.svg',
'icon_magenta.svg', 'icon_red.svg', 'icon_yellow.svg'
];
const storageKey = 'vulbyte_favicon_cache';
let blobURLs = []; // We will store the "memory addresses" here
let favicon = document.getElementById('favicon') || document.querySelector("link[rel*='icon']");
if (!favicon) {
favicon = document.createElement('link');
favicon.id = 'favicon';
favicon.rel = 'icon';
document.head.appendChild(favicon);
}
(async () => {
try {
let base64Strings = JSON.parse(localStorage.getItem(storageKey));
if (!base64Strings) {
base64Strings = await downloadAndStoreIcons();
}
// Convert Base64 back to Blobs, then to Object URLs
blobURLs = base64Strings.map(base64 => {
const byteString = atob(base64.split(',')[1]);
const mimeString = base64.split(',')[0].split(':')[1].split(';')[0];
const ab = new ArrayBuffer(byteString.length);
const ia = new Uint8Array(ab);
for (let i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
const blob = new Blob([ab], {type: mimeString});
return URL.createObjectURL(blob); // This creates a 'blob:...' address
});
startAnimation();
} catch (err) {
console.warn("Animation failed:", err);
}
})();
function startAnimation() {
let index = 0;
setInterval(() => {
if (blobURLs.length === 0) return;
// Swapping these 'blob:' addresses is "silent" in most Network tabs
favicon.href = blobURLs[index];
index = (index + 1) % blobURLs.length;
}, 300);
}
// WARN: THIS NEEDS TO BE BEFORE THE MARQUEE ELEMENT OR WEBSITE WILL HANG
let Ps = document.getElementsByTagName("p");
window.addEventListener('scroll', () => {
let p
for (let i = 0; i < Ps.length; ++i) {
p = Ps[i];
const rect = p.getBoundingClientRect();
const isVisible = (
rect.top < window.innerHeight &&
rect.bottom > 0
);
/*
if (isVisible) {
console.log("element is now visible");
p.classList.add("visible");
} else {
console.log("element not visible");
p.classList.remove("visible");
}
*/
}
});
//}}}2
//{{{2 header marqee
/**
* Creates a marquee effect for any HTML element while preserving the original element type
* @param {HTMLElement} element - The element to transform into a marquee
* @param {Object} options - Optional configuration
* @param {number} options.speed - Animation speed in pixels per second (default: 100)
* @param {number} options.bufferMultiplier - How many times to repeat the content (default: 3)
* @param {string} options.direction - Direction of movement: 'left' or 'right' (default: 'left')
* @returns {HTMLElement} - The original element with marquee functionality
*/
function makeMarquee(element, options = {}) {
// Safety check - prevent processing null elements or already processed elements
if (!element || element.classList.contains('marquee-processed')) {
console.warn('Invalid element or already processed element provided to makeMarquee');
return element;
}
console.log("Starting marquee creation for", element);
// Default options with safer merging
const settings = {
speed: options.speed !== undefined ? options.speed : 100,
bufferMultiplier: options.bufferMultiplier !== undefined ? options.bufferMultiplier : 3,
direction: options.direction === 'right' ? 'right' : 'left'
};
// Save the original element's content and attributes
const originalContent = element.innerHTML;
const originalTagName = element.tagName.toLowerCase();
const originalId = element.id;
const originalClasses = element.className;
// Store original attributes safely (excluding id and class which we handle separately)
const originalAttributes = {};
Array.from(element.attributes).forEach(attr => {
if (attr.name !== 'id' && attr.name !== 'class') {
originalAttributes[attr.name] = attr.value;
}
});
// Mark the element as processed to prevent multiple processing
element.classList.add('marquee-processed', 'marquee-container');
// Set up the marquee container
element.style.overflow = 'hidden';
element.style.whiteSpace = 'nowrap';
element.style.position = 'relative';
element.style.display = 'block';
element.style.width = '100%';
element.style.lineHeight = '1';
element.style.padding = '0';
element.style.margin = '0';
// Create the inner container for animation
const marqueeInner = document.createElement('div');
marqueeInner.classList.add('marquee-inner');
marqueeInner.style.display = 'inline-block';
marqueeInner.style.whiteSpace = 'nowrap';
marqueeInner.style.position = 'relative';
// Clear original content and add the inner container
element.innerHTML = '';
element.appendChild(marqueeInner);
// Generate a unique ID for this marquee instance
const instanceId = Math.random().toString(36).substring(2, 11);
element.dataset.marqueeId = instanceId;
// Counter for unique item IDs
let itemCounter = 0;
// Function to create a single item with the original content
function createItem() {
// Create a wrapper span for inline display
const item = document.createElement('span');
item.classList.add('marquee-item-wrapper');
item.dataset.itemIndex = itemCounter++;
item.style.display = 'inline-block';
item.style.verticalAlign = 'top';
item.style.padding = '0';
item.style.margin = '0';
item.style.marginRight = '2em'; // Space between items
// Create the original element type to maintain proper rendering
const originalTypeElement = document.createElement(originalTagName);
originalTypeElement.classList.add('marquee-content');
// Set original ID and classes on the first item only
if (marqueeInner.children.length === 0) {
if (originalId) originalTypeElement.id = originalId + '-content';
if (originalClasses) {
originalClasses.split(' ').forEach(cls => {
if (cls.trim() && cls.trim() !== 'marquee') {
originalTypeElement.classList.add(cls.trim());
}
});
}
originalTypeElement.classList.add('marquee-content-primary');
} else {
originalTypeElement.classList.add('marquee-content-clone');
originalTypeElement.dataset.cloneIndex = marqueeInner.children.length;
}
// Apply original attributes
for (const [name, value] of Object.entries(originalAttributes)) {
try {
originalTypeElement.setAttribute(name, value);
} catch (e) {
console.warn(`Failed to set attribute ${name}:`, e);
}
}
// Set content
originalTypeElement.innerHTML = originalContent;
// Reset specific styles
originalTypeElement.style.margin = '0';
originalTypeElement.style.padding = '0';
originalTypeElement.style.display = 'inline-block';
originalTypeElement.style.verticalAlign = 'top';
// Add to the wrapper
item.appendChild(originalTypeElement);
return item;
}
// Function to calculate and setup the marquee animation
function setupAnimation(contentWidth) {
// Prevent division by zero
if (!contentWidth || contentWidth <= 0) {
console.warn('Invalid content width detected:', contentWidth);
contentWidth = 200; // Fallback to a reasonable default
}
// Animation duration based on content width and speed
const animationDuration = contentWidth / settings.speed;
// Clean up any existing animation styles for this instance
const existingStyle = document.getElementById(`marquee-style-${instanceId}`);
if (existingStyle) {
existingStyle.remove();
}
// Create and inject keyframe animation
const styleSheet = document.createElement('style');
styleSheet.id = `marquee-style-${instanceId}`;
styleSheet.classList.add('marquee-animation-style');
styleSheet.textContent = `
@keyframes marquee-${instanceId} {
0% { transform: translateX(0); }
100% { transform: translateX(${settings.direction === 'right' ? '' : '-'}${contentWidth}px); }
}
`;
document.head.appendChild(styleSheet);
// Apply animation to the inner container
marqueeInner.style.animation = `marquee-${instanceId} ${animationDuration}s linear infinite`;
// Store animation info on the element for potential updates
element.dataset.animationName = `marquee-${instanceId}`;
element.dataset.animationDuration = animationDuration;
element.dataset.contentWidth = contentWidth;
console.log(`Animation setup complete with width: ${contentWidth}px, duration: ${animationDuration}s`);
}
// Function to ensure we have enough content for continuous scrolling
function ensureFullWidth() {
console.log("Starting ensureFullWidth");
// Reset counter for new creation cycle
itemCounter = 0;
// Clear any existing content
marqueeInner.innerHTML = '';
// Add first item to measure width
const firstItem = createItem();
marqueeInner.appendChild(firstItem);
// Function to get width safely and continue setup
function getWidthAndContinue() {
// Get the width of one item (with safety checks)
let contentWidth = firstItem.offsetWidth;
// Safety check - if width is 0, element might not be rendered yet
if (contentWidth <= 0) {
// Try to get width from children
const children = firstItem.getElementsByTagName('*');
for (let i = 0; i < children.length; i++) {
const childWidth = children[i].offsetWidth;
if (childWidth > 0) {
contentWidth = childWidth;
break;
}
}
// If still 0, use a default width
if (contentWidth <= 0) {
console.warn('Could not detect element width, using default');
contentWidth = 200;
}
}
console.log(`Measured content width: ${contentWidth}px`);
// Calculate how many repetitions we need
const viewportWidth = window.innerWidth || document.documentElement.clientWidth;
const minRequired = Math.max(2, Math.ceil((viewportWidth * 2) / contentWidth));