aboutsummaryrefslogtreecommitdiff
path: root/assets/js/index.js
blob: d6981275d5ac1531d17bbd734e89ca6e8d83c0d4 (plain)
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
(function() {
    const cookiesDisabled = !navigator.cookieEnabled;
    if (cookiesDisabled) {
        document.cookie = "disabled";
        document.cookie.indexOf("disabled");
        return console.warn("WARNING: Pager disabled due to cookie restrictions");
    }
    let seek;
    let pager = {};
    const key = "config.scroll.pager.urls";
    if (!localStorage[key]) localStorage[key] = JSON.stringify(pager);
    let url = function() {
        return self.location.href.split("#")[0].split("?")[0];
    };
    const scrollHash = function(url) {
        const hash = self.location.hash;
        const fragment = hash.slice(1) && document.getElementById(hash.slice(1));
        const fragmented = hash.length > 0;
        const hashed = fragmented && document.body.contains(fragment);
        if (hashed) {
            self.location.hash = hash;
            self.location.href = hash;
            if ("scroll-margin-top" in document.body.style === false && fragment.textContent !== "") {
                self.scrollBy(0, -6 * parseFloat(getComputedStyle(document.documentElement).fontSize));
            }
        }
        return hashed;
    };
    const scrollRestore = function(url) {
        if (history.scrollRestoration) history.scrollRestoration = "manual";
        if (scrollHash(url)) return;
        pager = JSON.parse(localStorage[key]);
        if (pager[url] > 0) {
            clearInterval(seek);
            self.scrollTo(0, pager[url]);
            let i1 = 0;
            return seek = setInterval(function(position) {
                i1++;
                if (i1 > 100) clearInterval(seek);
                if (document.documentElement.scrollHeight >= position + document.documentElement.clientHeight) {
                    clearInterval(seek);
                    self.scrollTo(0, position);
                }
            }, 4, pager[url]);
        } else self.scrollTo(0, 0);
        pager[url] = self.pageYOffset;
        localStorage[key] = JSON.stringify(pager);
    };
    const scrollTrack = function(url) {
        const currentPosition = self.pageYOffset;
        pager = JSON.parse(localStorage[key]);
        pager[url] = currentPosition;
        localStorage[key] = JSON.stringify(pager);
    };
    const scrollReverse = function(back, up, event) {
        if (document.body.contains(up) && up.contains(event.target)) {
            event.preventDefault();
            window.scrollTo(0, 0);
        }
        if (document.body.contains(back) && back.contains(event.target)) {
            if (history.length < 2) return;
            event.preventDefault();
            history.go(-1);
        }
    };
    [
        "DOMContentLoaded",
        "pageshow",
        "hashchange",
        "URLChangedCustomEvent"
    ].forEach(function(event) {
        self.addEventListener(event, function(event) {
            if (event.type === "pageshow") {
                return event.persisted && self.scrollTo(0, pager[url()]);
            }
            if (event.type === "DOMContentLoaded") {
                self.addEventListener("click", function(event) {
                    const up = document.getElementById("top");
                    const back = document.getElementById("back");
                    scrollReverse(back, up, event);
                });
            }
            scrollRestore(url());
        });
    });
    [
        "click",
        "touchstart",
        "scroll"
    ].forEach(function(event) {
        self.addEventListener(event, function() {
            scrollTrack(url());
        });
    });
})();
(function() {
    const cookiesDisabled = !navigator.cookieEnabled;
    if (cookiesDisabled) {
        document.cookie = "disabled";
        document.cookie.indexOf("disabled");
        return console.warn("WARNING: Update check disabled due to cookie restrictions");
    }
    function fetch(url, method, callback) {
        const http = new XMLHttpRequest();
        http.onreadystatechange = function() {
            if (http.readyState === 4 && http.status === 200) {
                if (callback) callback(http);
            }
        };
        http.open(method, url);
        http.setRequestHeader("Pragma", "no-cache");
        http.setRequestHeader("Cache-Control", "no-cache");
        http.send();
        return http;
    }
    const key = "config.update";
    let stamps = {};
    if (!sessionStorage[key + ".urls"]) sessionStorage[key + ".urls"] = JSON.stringify(stamps);
    function update() {
        const url = self.location.href.split("#")[0].split("?")[0];
        const indicator = document.querySelector("a[data-update]");
        if (indicator === null || indicator.dataset.update === "refresh") return;
        indicator.cloneNode();
        fetch(url, "HEAD", function(request) {
            const local = document.querySelector('meta[name="last-modified"]').content || document.lastModified;
            const remote = request.getResponseHeader("last-modified") || '';
            const modified = Date.parse(remote || local) > Date.parse(local);
            const drift = Date.parse(remote || local) - Date.parse(local);
            if (drift < 10000) return;
            stamps = JSON.parse(sessionStorage[key + ".urls"]);
            if (stamps[url] === remote) return;
            stamps[url] = remote;
            sessionStorage[key + ".urls"] = JSON.stringify(stamps);
            if (remote && modified) {
                fetch(url, "GET", function() {
                    indicator.href = url.replace(/^https:/, "http:");
                    indicator.removeAttribute("id");
                    indicator.dataset.update = "refresh";
                    console.log("INFO: R: " + remote);
                    console.log("INFO: L: " + local);
                    console.log("INFO: D: " + drift);
                    console.log("INFO: M: " + modified);
                });
            }
        });
    }
    let scrolled;
    let delay = 1000;
    let delayed = 0;
    self.addEventListener("scroll", function() {
        if (scrolled) clearTimeout(scrolled);
        scrolled = setTimeout(function() {
            update();
            delay = delay + delayed;
            delayed = delay - delayed;
        }, delay);
    });
    [
        "focus",
        "load",
        "URLChangedCustomEvent"
    ].forEach(function(event) {
        self.addEventListener(event, function() {
            update();
        });
    });
})();
(function() {
    const options = "targetWindow,width=700,height=500,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
    self.addEventListener("keydown", function(event) {
        if (event.repeat && event.key === "d") {
            selection(dictionary);
        }
        if (event.repeat && event.key === "s") {
            selection(search);
        }
        if (event.repeat && event.key === "m") {
            selection(manual);
        }
    });
    function selection(execute) {
        let phrase = "" + window.getSelection();
        phrase = phrase.replace(/[!.:?,;"]/g, "");
        phrase = phrase.replace(/^\s*(\S*?)\s*$/g, "$1");
        if (phrase && phrase > "" && phrase.length > 1) {
            execute(phrase);
        }
    }
    function dictionary(word) {
        window.open("https://www.merriam-webster.com/dictionary/" + encodeURIComponent(word), "Definitions", options);
    }
    function search(phrase) {
        window.open("https://lite.duckduckgo.com/lite/?q=" + encodeURIComponent(phrase), "Search", options);
    }
    function manual(program) {
        window.open("https://man.archlinux.org/search?q=" + encodeURIComponent(program), "Manual", options);
    }
})();
(function() {
    if (typeof Element !== "undefined") {
        if (!Element.prototype.matches) {
            Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
        }
        if (!Element.prototype.closest) {
            Element.prototype.closest = function(s) {
                var el = this;
                do {
                    if (el.matches(s)) return el;
                    el = el.parentElement || el.parentNode;
                }while (el !== null && el.nodeType === 1)
                return null;
            };
        }
    }
    function fetch(url, method, callback) {
        const http = new XMLHttpRequest();
        http.onreadystatechange = function() {
            if (http.readyState === 4 && http.status === 200) {
                if (callback) callback(http);
            }
        };
        http.open(method, url);
        http.send();
        return http;
    }
    self.addEventListener("DOMContentLoaded", function() {
        [
            "mouseout",
            "mousedown",
            "touchstart"
        ].forEach(function(event) {
            self.addEventListener(event, function(event) {
                const url = event.target.closest("a");
                if (preloadable(url) === undefined) return;
                preload(url.href);
            });
        });
        function preloadable(url) {
            switch(true){
                case url === null || url.href === null:
                    return;
                case url.origin !== location.origin:
                    return;
                case [
                    "http:",
                    "https:"
                ].includes(url.protocol) === null:
                    return;
                case url.protocol === "http:" && location.protocol === "https:":
                    return;
                case url.hash && url.pathname + url.search == location.pathname + location.search:
                    return;
                default:
                    return true;
            }
        }
        function preload(url) {
            const prefetcher = document.createElement("link");
            prefetcher.rel = "custom-prefetch";
            prefetcher.href = url;
            const selector = 'link[rel="'.concat(prefetcher.rel, '"][href="').concat(prefetcher.href, '"]');
            const prefetched = document.head.contains(document.querySelector(selector));
            if (prefetched) {
                return;
            }
            document.head.appendChild(prefetcher);
            fetch(url, "GET", function() {});
        }
    });
})();
(function() {
    const hide = function(triggers) {
        for(let i1 = 0; i1 < triggers.length; i1++){
            triggers[i1].checked = false;
        }
    };
    const hideIfClickedOutside = function(menus, triggers, event) {
        for(let i1 = 0; i1 < menus.length; i1++){
            const active = triggers[i1].checked === true;
            const outside = !menus[i1].contains(event.target);
            if (outside && active) hide(triggers);
        }
    };
    self.addEventListener("scroll", function() {
        const triggers = document.querySelectorAll("menu input");
        hide(triggers);
    });
    [
        "click",
        "touchstart"
    ].forEach(function(event) {
        self.addEventListener(event, function(event) {
            const menus = document.querySelectorAll("menu");
            const triggers = document.querySelectorAll("menu input");
            hideIfClickedOutside(menus, triggers, event);
        });
    });
})();
(function() {
    [
        "DOMContentLoaded",
        "URLChangedCustomEvent"
    ].forEach(function(event) {
        self.addEventListener(event, function() {
            const container = document.querySelector("search-box");
            const dropdown = document.querySelector("search-box ul");
            const form = document.querySelector("search-box form");
            const query = document.querySelector("search-box input");
            const submit = document.querySelector("search-box button");
            function first(element) {
                if (element.firstChild.nextElementSibling) {
                    return element.firstChild.nextElementSibling.firstChild.nextElementSibling;
                }
            }
            function last(element) {
                return element.lastElementChild.firstChild.nextElementSibling;
            }
            function next(element) {
                return element.activeElement.parentElement.nextElementSibling.firstChild.nextElementSibling.focus();
            }
            function previous(element) {
                return element.activeElement.parentElement.previousElementSibling.firstChild.nextElementSibling.focus();
            }
            function press(keyname) {
                document.dispatchEvent(new KeyboardEvent("keydown", {
                    "key": keyname
                }));
            }
            let selected;
            if (submit === null) return;
            submit.addEventListener("click", function(event) {
                if (selected) {
                    event.preventDefault();
                    selected.focus();
                    return selected.click();
                }
                first(dropdown).focus();
                press("ArrowDown");
                document.activeElement.click();
            });
            [
                "keyup",
                "click"
            ].forEach(function(event) {
                form.addEventListener(event, function() {
                    if (document.activeElement.nodeName === "A") {
                        return selected = document.activeElement;
                    }
                    selected = undefined;
                });
            });
            form.addEventListener("focusin", function() {
                container.setAttribute("data-focus", "");
                initialize();
            });
            form.addEventListener("submit", function(event) {
                event.preventDefault();
                return false;
            });
            form.addEventListener("keydown", function(event) {
                if (form.contains(event.target)) {
                    if (event.keyCode == 27) {
                        document.activeElement.blur();
                        dropdown.setAttribute("hidden", "");
                        container.removeAttribute("data-focus");
                    }
                }
                if (event.keyCode == 8) {
                    if (document.activeElement != query) {
                        event.preventDefault();
                        query.focus();
                    }
                }
                const head = first(dropdown);
                const tail = last(dropdown);
                if (event.keyCode == 40) {
                    event.preventDefault();
                    if (document.activeElement == query) head.focus();
                    else if (document.activeElement == tail) query.focus();
                    else next(document);
                }
                if (event.keyCode == 38) {
                    event.preventDefault();
                    if (document.activeElement == query) tail.focus();
                    else if (document.activeElement == head) query.focus();
                    else previous(document);
                }
                if (event.keyCode == 13) {
                    if (dropdown && document.activeElement == query) {
                        event.preventDefault();
                        head.focus();
                        head.click();
                    }
                }
            });
            let scrolls = 0;
            self.addEventListener("scroll", function() {
                if (scrolls > 3) {
                    scrolls = 0;
                    document.activeElement.blur();
                    dropdown.setAttribute("hidden", "");
                    container.removeAttribute("data-focus");
                }
                scrolls++;
            });
            self.addEventListener("click", function(event) {
                if (!form.contains(event.target) && !(document.activeElement === query) && !(document.activeElement === submit)) {
                    dropdown.setAttribute("hidden", "");
                    container.removeAttribute("data-focus");
                }
            });
            function fetch(url, callback) {
                const http = new XMLHttpRequest();
                http.onreadystatechange = function() {
                    if (http.readyState === 4 && http.status === 200 && callback) {
                        callback(http);
                    }
                };
                http.open("GET", url);
                http.send();
            }
            function script(url) {
                return new Promise(function(resolve, reject) {
                    const script = document.createElement("script");
                    script.onerror = reject;
                    script.onload = resolve;
                    if (document.currentScript) {
                        document.currentScript.parentNode.insertBefore(script, document.currentScript);
                    } else document.head.appendChild(script);
                    script.src = url;
                });
            }
            let data = {};
            let boot = true;
            const options = {
                key: [
                    "title"
                ]
            };
            function isEmpty(obj) {
                return Object.keys(obj).length === 0;
            }
            function appendItemsTo(local, remote) {
                const paginated = Object.keys(remote).includes("next_url");
                if (isEmpty(local)) {
                    local = remote;
                } else {
                    local.items = local.items.concat(remote.items);
                }
                if (paginated) {
                    fetch(remote.next_url, function(request) {
                        appendItemsTo(local, JSON.parse(request.responseText));
                    });
                } else search(query.value, data.items, options);
                data = local;
            }
            function initialize() {
                if (boot) {
                    script(window.location.origin + "/js/fuzzysort.js").then(function() {
                        fetch("/index.json", function(request) {
                            appendItemsTo({}, JSON.parse(request.responseText));
                            search("", data.items, options);
                            boot = false;
                        });
                        [
                            "keyup",
                            "focusin"
                        ].forEach(function(event) {
                            query.addEventListener(event, function() {
                                if (data.items) search(query.value, data.items, options);
                                else {
                                    boot = true;
                                    initialize();
                                }
                            });
                        });
                    }).catch(function(error) {
                        console.error("ERROR: Failed to load fuzzy search", error);
                    });
                }
            }
            function escape(text) {
                const escaped = document.createElement("textarea");
                escaped.textContent = text;
                return escaped.innerHTML;
            }
            function search(term, data, options) {
                const results = fuzzysort.go(term, data, options);
                let items = "";
                if (results.length === 0 && term.length >= 0) {
                    let separator = "—";
                    if (term.length === 0) separator = "";
                    items = '<li><a tabindex="0">'.concat(escape(term), " ").concat(separator, " No Results Found</a></li>");
                    dropdown.removeAttribute("hidden");
                    container.setAttribute("data-focus", "");
                } else {
                    dropdown.removeAttribute("hidden");
                    for(var string in results.slice(0, 10)){
                        const title = results[string].obj.title;
                        let highlight = fuzzysort.highlight(fuzzysort.single(escape(term), escape(title)), "<span>", "</span>");
                        if (highlight === null) highlight = title;
                        items = items + '\n<li>\n<a href="'.concat(results[string].obj.url, '" tabindex="0">').concat(highlight, "</a>\n</li>\n");
                    }
                }
                dropdown.innerHTML = items;
            }
        });
    });
})();
(function() {
    function viewport(element) {
        const options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
            offset: {
                top: -50,
                left: 0,
                bottom: -50,
                right: 0
            }
        };
        const view = element.getBoundingClientRect();
        return view.top >= -options.offset.top && view.left >= -options.offset.left && view.bottom <= (self.innerHeight || document.documentElement.clientHeight) + options.offset.bottom && view.right <= (self.innerWidth || document.documentElement.clientWidth) + options.offset.right;
    }
    [
        "scroll",
        "DOMContentLoaded"
    ].forEach(function(event) {
        self.addEventListener(event, function() {
            let first = true;
            let videos = document.querySelectorAll("video");
            for(i = 0; i < videos.length; i++){
                videos[i].autoplay = true;
                videos[i].controls = true;
                videos[i].loop = true;
                videos[i].muted = true;
                videos[i].playsinline = true;
                videos[i].setAttribute("autoplay", true);
                videos[i].setAttribute("controls", true);
                videos[i].setAttribute("loop", true);
                videos[i].setAttribute("muted", true);
                videos[i].setAttribute("playsinline", true);
                const onscreen = viewport(videos[i]);
                if (first && onscreen) {
                    videos[i].play();
                    first = false;
                } else {
                    videos[i].pause();
                }
            }
        });
    });
})();
(function() {
    if (typeof Element !== "undefined") {
        if (!Element.prototype.matches) {
            Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
        }
        if (!Element.prototype.closest) {
            Element.prototype.closest = function(s) {
                var el = this;
                do {
                    if (el.matches(s)) return el;
                    el = el.parentElement || el.parentNode;
                }while (el !== null && el.nodeType === 1)
                return null;
            };
        }
    }
    const disabled = "0s";
    function walk(children, callback) {
        for(let i1 = 0; i1 < children.length; i1++){
            callback(children[i1]);
            walk(children[i1].children, callback);
        }
    }
    self.addEventListener("mousemove", function(event) {
        if (typeof event.target.closest !== "function") return;
        tree = event.target.closest("figure") || event.target.closest("article");
        if (tree !== null) {
            walk(tree.children, function(element) {
                const delay = self.getComputedStyle(element).getPropertyValue("transition-delay");
                if (delay !== disabled) {
                    element.style.setProperty("visibility", "hidden");
                }
            });
            walk(tree.children, function(element) {
                const delay = self.getComputedStyle(element).getPropertyValue("transition-delay");
                if (delay !== disabled) {
                    element.style.removeProperty("visibility");
                }
            });
        }
    });
})();
(function() {
    const cookiesDisabled = !navigator.cookieEnabled;
    if (cookiesDisabled) {
        document.cookie = "disabled";
        document.cookie.indexOf("disabled");
        return console.warn("WARNING: Cannot persist form state due to cookie restrictions");
    }
    const storage = document.createEvent("Event");
    storage.initEvent("storage", true, true);
    [
        "pageshow",
        "URLChangedCustomEvent",
        "DOMContentLoaded"
    ].forEach(function(event) {
        self.addEventListener(event, function(event) {
            const input = Array.prototype.slice.call(document.querySelectorAll("form input"));
            const select = Array.prototype.slice.call(document.querySelectorAll("form select"));
            const textarea = Array.prototype.slice.call(document.querySelectorAll("form textarea"));
            const summary = Array.prototype.slice.call(document.querySelectorAll("details summary"));
            const states = input.concat(select).concat(textarea);
            for(var i1 = 0; i1 < states.length; i1++){
                const state = states[i1];
                const sync = i1 === states.length - 1;
                if (localStorage[state.id]) {
                    if (state.type === "radio" || state.type === "checkbox") {
                        if (localStorage[state.id] === "on") state.checked = true;
                    } else state.value = localStorage[state.id];
                }
                if (sync) self.dispatchEvent(storage);
                state.addEventListener("change", function(event) {
                    localStorage[event.target.id] = event.target.value;
                    const group = document.querySelectorAll("input[name='".concat(event.target.name, "']"));
                    for(var j = 0; j < group.length; j++){
                        const member = group[j];
                        if ((member.type === "radio" || member.type === "checkbox") && !member.checked) {
                            localStorage[member.id] = "off";
                        }
                    }
                    self.dispatchEvent(new Event("storage"));
                });
            }
            for(var k = 0; k < summary.length; k++){
                let child = summary[k];
                let details = child.parentElement;
                if (details.id && details.nodeName === "DETAILS") {
                    sessionStorage[details.id] === "false" && details.removeAttribute("open");
                    sessionStorage[details.id] === "true" && details.setAttribute("open", true);
                    child.addEventListener("click", function(event) {
                        let child = event.target.nodeName === "SUMMARY" && event.target || event.target.parentElement;
                        let details = child.parentElement;
                        if (details.id && details.nodeName === "DETAILS") {
                            sessionStorage[details.id] = !details.open;
                        }
                    });
                }
            }
        });
    });
    [
        "storage"
    ].forEach(function(event) {
        self.addEventListener(event, function() {
            let stylesheet;
            stylesheet = document.querySelector('link[href$="default-simple.css"]');
            if (localStorage["config.layout.simple"] === "on") stylesheet.rel = "stylesheet";
            if (localStorage["config.layout.default"] === "on") stylesheet.rel = "alternate stylesheet";
            stylesheet = document.querySelector('link[href$="default-fast.css"]');
            if (localStorage["config.navigation.fast"] === "on") stylesheet.rel = "stylesheet";
            if (localStorage["config.navigation.slow"] === "on") stylesheet.rel = "alternate stylesheet";
            for(var i1 = 0; i1 < document.styleSheets.length; i1++){
                let stylesheet = document.styleSheets[i1];
                for(var k = 0; k < stylesheet.rules.length; k++){
                    let media = stylesheet.rules[k].media;
                    if (media && media.mediaText.includes("prefers-color-scheme")) {
                        if (localStorage["config.theme.light"] === "on") {
                            media.mediaText = "(prefers-color-scheme: dark)";
                            if (getComputedStyle(document.body).getPropertyValue("color-scheme") === "dark") {
                                media.mediaText = "(prefers-color-scheme: light)";
                            }
                        }
                        if (localStorage["config.theme.auto"] === "on") {
                            media.mediaText = "(prefers-color-scheme: dark)";
                        }
                        if (localStorage["config.theme.dark"] === "on") {
                            media.mediaText = "(prefers-color-scheme: light)";
                            if (getComputedStyle(document.body).getPropertyValue("color-scheme") === "light") {
                                media.mediaText = "(prefers-color-scheme: dark)";
                            }
                        }
                    }
                }
            }
        });
    });
    const early = setInterval(persistence, 4);
    function persistence() {
        if (document.styleSheets.length > 0) {
            self.dispatchEvent(storage);
            clearInterval(early);
        }
    }
    self.addEventListener("DOMContentLoaded", function() {
        self.dispatchEvent(storage);
        clearInterval(early);
    });
})();
(function() {
    const timeout = 300;
    const state = "on";
    const key = "config.navigation.fast";
    function fetch(url, method, callback) {
        const http = new XMLHttpRequest();
        http.onreadystatechange = function() {
            if (callback && http.readyState === 4) {
                if (http.status === 200) callback(http);
                else {
                    console.error("ERROR: Unable to navigate", http);
                    self.location.href = url;
                }
            }
        };
        http.open(method, url);
        http.timeout = timeout;
        http.send();
        return http;
    }
    function styles(node) {
        return node.nodeName === "LINK" && node.rel && node.rel.includes("stylesheet");
    }
    function scripts(node) {
        return node.nodeName === "SCRIPT" && node.hasAttribute("src");
    }
    function filter(url, http) {
        let live = document;
        let node = live.head.childNodes.length;
        let next = new DOMParser().parseFromString(http.responseText, "text/html");
        if (next.doctype === null || !http.getResponseHeader("content-type").includes("text/html")) return false;
        while(node--){
            if (styles(live.head.childNodes[node]) || scripts(live.head.childNodes[node])) {} else {
                live.head.removeChild(live.head.childNodes[node]);
            }
        }
        while(next.head.firstChild){
            if (styles(next.head.firstChild) || scripts(next.head.firstChild)) {
                next.head.removeChild(next.head.firstChild);
            } else {
                live.head.appendChild(next.head.firstChild);
            }
        }
        while(live.documentElement.attributes.length > 0){
            live.documentElement.removeAttribute(live.documentElement.attributes[live.documentElement.attributes.length - 1].name);
        }
        while(next.documentElement.attributes.length > 0){
            live.documentElement.setAttribute(next.documentElement.attributes[next.documentElement.attributes.length - 1].name, next.documentElement.attributes[next.documentElement.attributes.length - 1].value);
            next.documentElement.removeAttribute(next.documentElement.attributes[next.documentElement.attributes.length - 1].name);
        }
        live.body.parentElement.replaceChild(next.body, live.body);
    }
    function persist() {
        let persist = document.createElement("link");
        persist.rel = "location";
        persist.target = JSON.stringify(self.location);
        document.head.appendChild(persist);
    }
    self.addEventListener("DOMContentLoaded", function() {
        if (localStorage[key] !== state) return;
        persist();
    });
    self.addEventListener("popstate", function(event) {
        if (localStorage[key] !== state) return;
        const link = JSON.parse(document.querySelector('link[rel="location"]').target);
        const url = event.target.location;
        const hashed = link.pathname === url.pathname;
        if (hashed) return;
        fetch(url, "GET", function(http) {
            if (filter(url, http) === false) return self.location.href = url;
            persist();
            self.document.dispatchEvent(new CustomEvent("URLChangedCustomEvent", {
                bubbles: true
            }));
        });
    });
    self.addEventListener("click", function(event) {
        if (localStorage[key] !== state) return;
        const links = document.querySelectorAll("a");
        for(let i1 = 0; i1 < links.length; i1++){
            const active = links[i1].contains(event.target);
            const change = self.location.href !== links[i1].href;
            const view = links[i1].attributes.hasOwnProperty("download") === false;
            const local = self.location.origin === links[i1].origin && links[i1].target !== "_self";
            const hashed = self.location.pathname === links[i1].pathname && links[i1].href.includes("#");
            if (active && local && change && view && hashed === false) {
                event.preventDefault();
                const url = links[i1].href;
                links[i1].style.cursor = "wait";
                fetch(url, "GET", function(http) {
                    links[i1].removeAttribute("style");
                    if (filter(url, http) === false) return self.location.href = url;
                    history.pushState({}, "", links[i1].href);
                    persist();
                    self.document.dispatchEvent(new CustomEvent("URLChangedCustomEvent", {
                        bubbles: true
                    }));
                });
            }
        }
    });
})();
(function() {
    const relative = new Intl.RelativeTimeFormat("en", {
        localeMatcher: "best fit",
        numeric: "always",
        style: "long"
    });
    function viewport(element) {
        const options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
            offset: 250
        };
        const view = element.getBoundingClientRect();
        return view.top >= -options.offset && view.left >= -options.offset && view.bottom <= (self.innerHeight || document.documentElement.clientHeight) + options.offset && view.right <= (self.innerWidth || document.documentElement.clientWidth) + options.offset;
    }
    const date = function(update) {
        const elements = document.querySelectorAll("time");
        for(let i1 = 0; i1 < elements.length; ++i1){
            const offscreen = !viewport(elements[i1]);
            const hidden = elements[i1].offsetParent === null;
            if (update === "viewport" && (offscreen || hidden)) continue;
            (function(element) {
                try {
                    if (element.dataset.type === "disabled") return;
                    const time = new Date(element.dateTime) || new Date();
                    const interval = (new Date().getTime() - time.getTime()) / 1000;
                    const seconds = Math.round(interval);
                    const minutes = Math.round(seconds / 60);
                    const hours = Math.round(minutes / 60);
                    const days = Math.round(hours / 24);
                    const past = Math.sign(seconds) === 1;
                    const future = Math.sign(seconds) === -1;
                    let tiny = function(string, place) {
                        return string.split(" ").slice(0, place).join(" ") + string.split(" ")[place].charAt(0);
                    };
                    if (element.dataset.type === "default") {
                        tiny = function(string) {
                            return string;
                        };
                    }
                    if (element.dataset.type === "localDate") {
                        return element.textContent = new Intl.DateTimeFormat([], {
                            dateStyle: "medium"
                        }).format(time).replace(",", "");
                    }
                    if (element.dataset.type === "localTime") {
                        return element.textContent = new Intl.DateTimeFormat([], {
                            hour12: false,
                            timeStyle: "short"
                        }).format(time) + " " + new Intl.DateTimeFormat([], {
                            timeZoneName: "short"
                        }).format(time).split(" ")[1];
                    }
                    if (past) {
                        if (seconds <= 60) {
                            return element.textContent = tiny(relative.format(-1 * seconds, "second"), 1);
                        }
                        if (minutes <= 120) {
                            return element.textContent = tiny(relative.format(-1 * minutes, "minute"), 1);
                        }
                        if (hours <= 48) {
                            return element.textContent = tiny(relative.format(-1 * hours, "hour"), 1);
                        }
                        if (days <= 7) {
                            return element.textContent = tiny(relative.format(-1 * days, "day"), 1);
                        }
                    }
                    if (future) {
                        if (-1 * days >= 4) {
                            return element.textContent = tiny(relative.format(-1 * days, "day"), 2);
                        }
                        if (-1 * hours >= 3) {
                            return element.textContent = tiny(relative.format(-1 * hours, "hour"), 2);
                        }
                        if (-1 * minutes >= 2) {
                            return element.textContent = tiny(relative.format(-1 * minutes, "minute"), 2);
                        }
                        if (-1 * seconds >= 1) {
                            return element.textContent = tiny(relative.format(-1 * seconds, "second"), 2);
                        }
                    }
                } catch (error) {
                    console.error("ERROR: Relative time resolution failed", error);
                }
            })(elements[i1]);
        }
    };
    const substitution = setInterval(date, 4);
    [
        "scroll",
        "URLChangedCustomEvent"
    ].forEach(function(event) {
        self.addEventListener(event, function() {
            date("viewport");
        });
    });
    self.addEventListener("DOMContentLoaded", function() {
        setTimeout(function() {
            clearInterval(substitution);
            setInterval(function() {
                date("viewport");
            }, 1000);
        }, 1000);
    });
})();
console.log("INFO: Surface Control Complete");