PageSourceSearch

https://faisaln.com/scripts.js?c=1790371364724

js faisaln.com collected 2026-09-25 21:22:53 UTC 61,806 bytes, 1,177 lines download raw bytes

1var asideWidth = document.querySelector('aside').offsetWidth + 18;
2
3function documentReady() {
4    document.querySelector('title').innerHTML = document.querySelector('page-title').innerHTML;
5
6    selectedLayout = localStorage.getItem("layout");
7    if (selectedLayout) document.body.classList = selectedLayout;
8    layoutSelectors = document.querySelectorAll('#layout-select');
9    if (layoutSelectors.length && selectedLayout) layoutSelectors.forEach(a => a.value = selectedLayout);
10
11    asideWidth = document.querySelector('aside').offsetWidth + 18;
12
13    if (window.screen.width <= 950) hideSidebar();
14
15    document.querySelectorAll(".chip").forEach(chip => {
16        if (chip.getAttribute('href')) return;
17        chip.title = `Click to learn about ${chip.innerText}`;
18        const openLink = () => {
19            window.open(`https://duckduckgo.com/?q=${chip.innerText}`, '_blank');
20        };
21        chip.addEventListener("click", openLink);
22        chip.addEventListener("touchend", (event) => {
23            event.preventDefault();
24            openLink();
25        });
26        chip.addEventListener("mousemove", (event) => {
27            const tooltip = document.getElementById('chipTooltip');
28            if (tooltip.innerText != `Click to learn about ${chip.innerText}`) tooltip.innerText = `Click to learn about ${chip.innerText}`;
29        });
30        chip.addEventListener("touchmove", (event) => {
31            const tooltip = document.getElementById('chipTooltip');
32            if (tooltip.innerText != `Click to learn about ${chip.innerText}`) tooltip.innerText = `Click to learn about ${chip.innerText}`;
33        });
34    });
35
36    /* if (document.querySelector(".chips")) {
37        document.querySelector(".chips").addEventListener("mousemove", (event) => {
38            const tooltip = document.getElementById('chipTooltip');
39            const rect = document.querySelector(".chips").getBoundingClientRect();
40            if (window.innerHeight > tooltip.offsetHeight + event.clientY) tooltip.style.top = `${event.clientY - rect.top}px`;
41            tooltip.style.left = `${event.clientX - rect.left}px`;
42        });
43    }; */
44
45    var tooltipNum = 0;
46
47    document.querySelectorAll("[tooltip]").forEach(element => {
48        var tooltip = document.createElement("div");
49        tooltip.id = `tooltip${tooltipNum}`;
50        tooltip.className = "tooltip";
51        tooltip.role = "tooltip";
52        tooltip.innerText = element.getAttribute('tooltip');
53        if (element.attributes.parent3) {
54            element.parentElement.parentElement.parentElement.appendChild(tooltip);
55            element.parentElement.parentElement.parentElement.style.position = 'relative';
56        } else if (element.attributes.parent2) {
57            element.parentElement.parentElement.appendChild(tooltip);
58            element.parentElement.parentElement.style.position = 'relative';
59        } else if (element.attributes.parent) {
60            element.parentElement.appendChild(tooltip);
61            element.parentElement.style.position = 'relative';
62        } else {
63            element.appendChild(tooltip);
64            element.style.position = 'relative';
65        };
66        var tN = `tooltip${tooltipNum}`;
67        element.addEventListener("mouseover", () => {
68            document.getElementById(tN).style.opacity = "1";
69        });
70        element.addEventListener("mouseout", () => {
71            document.getElementById(tN).style.opacity = "0";
72        });
73        element.addEventListener("mousemove", (event) => {
74            const tooltip = document.getElementById(tN);
75            const rect = element.attributes.parent3 ? element.parentElement.parentElement.parentElement.getBoundingClientRect() : element.attributes.parent2 ? element.parentElement.parentElement.getBoundingClientRect() : element.attributes.parent ? element.parentElement.getBoundingClientRect() : element.getBoundingClientRect();
76            if (window.innerHeight > tooltip.offsetHeight + event.clientY) tooltip.style.top = `${event.clientY - rect.top}px`;
77            if ((event.clientX + tooltip.offsetWidth) > window.innerWidth) {
78                tooltip.style.left = `${event.clientX - rect.left - tooltip.offsetWidth}px`;
79            } else {
80                tooltip.style.left = `${event.clientX - rect.left}px`;
81            };
82        });
83        tooltipNum++;
84    });
85
86    const imagesContainer = document.querySelector('.siteImages');
87    if (imagesContainer) {
88        let isDown = false;
89        let startX;
90        let scrollLeft;
91        imagesContainer.addEventListener('mousedown', (e) => {
92            isDown = true;
93            imagesContainer.classList.add('active');
94            startX = e.pageX - imagesContainer.offsetLeft;
95            scrollLeft = imagesContainer.scrollLeft;
96        });
97        imagesContainer.addEventListener('mouseleave', () => {
98            isDown = false;
99            imagesContainer.classList.remove('active');
100        });
101        imagesContainer.addEventListener('mouseup', () => {
102            isDown = false;
103            imagesContainer.classList.remove('active');
104        });
105        imagesContainer.addEventListener('mousemove', (e) => {
106            if (!isDown) return;
107            e.preventDefault();
108            const x = e.pageX - imagesContainer.offsetLeft;
109            const walk = (x - startX) * 3;
110            imagesContainer.scrollLeft = scrollLeft - walk;
111        });
112        document.querySelectorAll('.siteImages div').forEach(element => {
113            element.addEventListener('click', function (event) {
114                const rect = this.getBoundingClientRect();
115                const clickX = event.clientX - rect.left;
116                const clickY = event.clientY - rect.top;
117                const afterXStart = rect.width - 50;
118                const afterYStart = rect.height - 50;
119                if (clickX >= afterXStart && clickY >= afterYStart) window.open(element.children[0].src, '_blank').focus();;
120            });
121        });
122    };
123
124    notes = document.querySelector('.notes');
125    if (notes) {
126        sortable(notes, function (item) { });
127
128        newNote = document.querySelector('form.newNote');
129        editing = false;
130
131        if (newNote) {
132            newNote.addEventListener('submit', async function (event) {
133                event.preventDefault();
134                var attachments = [];
135                document.querySelectorAll('input.attachment').forEach(attachment => {
136                    if (attachment.value != '') attachments.push(attachment.value);
137                });
138                if (!document.querySelector('input[name="title"]').value || !document.querySelector('textarea[name="content"]').value) return false;
139                await fetch('/apps/notes', {
140                    method: 'POST',
141                    headers: {
142                        'Content-Type': 'application/json'
143                    },
144                    body: JSON.stringify({
145                        title: document.querySelector('input[name="title"]').value,
146                        content: document.querySelector('textarea[name="content"]').value,
147                        private: document.querySelector('input[name="private"]').value,
148                        attachments,
149                        id: (editing === false) ? null : editing,
150                        action: (editing === false) ? null : 'edit',
151                    })
152                })
153                    .then(response => response.json())
154                    .then(response => {
155                        if (!response.length === 0) {
156                            console.log(response);
157                            return alert('Error adding note.');
158                        };
159                        syncNotes(response);
160                        cancelEdit();
161                    })
162                    .catch(err => {
163                        console.log(err);
164                        alert('Error adding note.');
165                    });
166            });
167        };
168
169        setInterval(async function () {
170            await fetch('/apps/notes', {
171                method: 'POST',
172                headers: {
173                    'Content-Type': 'application/json'
174                },
175            })
176                .then(response => response.json())
177                .then(response => {
178                    if (!response.length === 0) return;
179                    syncNotes(response);
180                })
181                .catch(err => {
182                    console.log(err);
183                });
184        }, 300000);
185
186        snapToLayout();
187
188        document.addEventListener('click', handleNoteInteraction);
189        document.addEventListener('touchstart', handleNoteInteraction);
190
191        function handleNoteInteraction(event) {
192            const clickedNote = event.target.closest('.note');
193            openedNotes = document.querySelectorAll('.note.full');
194            if (openedNotes.length > 0) {
195                openedNote = null;
196                openedNotes.forEach(n => {
197                    n.classList.remove('full');
198                    openedNote = n;
199                });
200                if (openedNote && (window.screen.width > 950) && (editing === false)) document.querySelector('.content').scrollTo({ top: openedNote.getBoundingClientRect().top + document.querySelector('.content').scrollTop - 50, behavior: 'smooth' });
201            };
202            openedNote = null;
203            if (clickedNote && !clickedNote.classList.contains('full')) clickedNote.classList.add('full');
204            if (clickedNote && (window.screen.width > 950) && (editing === false)) document.querySelector('.content').scrollTo({ top: clickedNote.getBoundingClientRect().top + document.querySelector('.content').scrollTop - 50, behavior: 'smooth' });
205        };
206    };
207
208    logs = document.querySelector('.logs');
209    if (logs) {
210        newLog = document.querySelector('form.newLog');
211        editing = false;
212
213        if (newLog) {
214            newLog.addEventListener('submit', async function (event) {
215                event.preventDefault();
216                if (!document.querySelector('textarea[name="content"]').value) return false;
217                await fetch('/apps/visitors', {
218                    method: 'POST',
219                    headers: {
220                        'Content-Type': 'application/json'
221                    },
222                    body: JSON.stringify({
223                        content: document.querySelector('textarea[name="content"]').value,
224                        id: (editing === false) ? null : editing,
225                        action: (editing === false) ? null : 'edit',
226                    })
227                })
228                    .then(response => response.json())
229                    .then(response => {
230                        if (!response.length === 0) {
231                            console.log(response);
232                            return alert('Error adding log.');
233                        };
234                        syncLogs(response);
235                        cancelEdit();
236                    })
237                    .catch(err => {
238                        console.log(err);
239                        alert('Error adding log.');
240                    });
241            });
242        };
243
244        setInterval(async function () {
245            await fetch('/apps/visitors', {
246                method: 'POST',
247                headers: {
248                    'Content-Type': 'application/json'
249                },
250            })
251                .then(response => response.json())
252                .then(response => {
253                    if (!response.length === 0) return;
254                    syncLogs(response);
255                })
256                .catch(err => {
257                    console.log(err);
258                });
259        }, 300000);
260
261        snapToLayout();
262
263        document.addEventListener('click', handleLogInteraction);
264        document.addEventListener('touchstart', handleLogInteraction);
265
266        function handleLogInteraction(event) {
267            const clickedLog = event.target.closest('.log');
268            openedLogs = document.querySelectorAll('.log.full');
269            if (openedLogs.length > 0) {
270                openedLog = null;
271                openedLogs.forEach(n => {
272                    n.classList.remove('full');
273                    openedLog = n;
274                });
275            };
276            openedLog = null;
277            if (clickedLog && !clickedLog.classList.contains('full')) clickedLog.classList.add('full');
278        };
279    };
280
281    if (document.querySelector('.puzzle')) adp('init');
282
283    if (typeof topbar !== 'undefined') topbar.hide();
284
285    if (window.history.length > 2) {
286        document.querySelectorAll('.history .back').forEach(a => a.classList.add('active'));
287        document.querySelectorAll('.history .forward').forEach(a => a.classList.add('active'));
288    };
289
290    document.querySelectorAll('.refresh').forEach(refresh => {
291        refresh.addEventListener('click', function () {
292            var style = getComputedStyle(refresh.querySelector('svg'));
293            refresh.querySelector('svg').style.rotate = `${Number(style.rotate.split('deg')[0]) + 360}deg`;
294        });
295    });
296
297    var icon = document.querySelector('.intro h1 .icon');
298    var zenMode = false;
299    if (icon) {
300        document.querySelector('.history').classList.add('trans');
301        icon.addEventListener('click', function () {
302            if (document.querySelector('.history .active')) document.querySelector('.history').style.opacity = document.querySelector('.history').style.opacity ? ((document.querySelector('.history').style.opacity == 1) ? 0 : 1) : 0;
303            document.querySelector('.intro h1').classList.toggle('off');
304            document.querySelector('.intro h5').classList.toggle('off');
305            if (zenMode) {
306                showSidebar();
307                document.querySelectorAll('.extra').forEach(extra => {
308                    extra.style.opacity = '';
309                    extra.style.pointerEvents = '';
310                });
311                document.querySelector('footer').style.marginTop = '';
312                document.querySelector('footer').style.opacity = '';
313                document.querySelector('footer').style.pointerEvents = '';
314                document.querySelector('#bmc-wbtn').style.opacity = '';
315                document.querySelector('#bmc-wbtn').style.pointerEvents = '';
316                if (document.querySelector('div:has(> iframe[title="ticker tape TradingView widget"])')) document.querySelector('div:has(> iframe[title="ticker tape TradingView widget"])').style.marginTop = '';
317                document.querySelector('aside.not-simple').style.marginLeft = '';
318                document.querySelector('aside.not-simple').style.opacity = '';
319                document.querySelector('aside.not-simple').style.pointerEvents = '';
320                document.querySelector('.sidebar.simple').style.marginTop = '';
321                document.querySelector('.sidebar.simple').style.marginLeft = '';
322                document.querySelector('.sidebar.simple').style.opacity = '';
323                document.querySelector('.sidebar.simple').style.pointerEvents = '';
324                document.querySelector('.banner').style.marginTop = '';
325                document.querySelector('.banner').style.opacity = '';
326                document.querySelector('.banner').style.pointerEvents = '';
327                document.querySelector('aside.simple').style.marginTop = '';
328                document.querySelector('aside.simple').style.opacity = '';
329                document.querySelector('aside.simple').style.pointerEvents = '';
330                document.querySelector('.main').style.minHeight = '';
331                document.querySelector('.split-content').style.paddingTop = '';
332            } else {
333                hideSidebar();
334                document.querySelectorAll('.extra').forEach(extra => {
335                    extra.style.opacity = '0';
336                    extra.style.pointerEvents = 'none';
337                });
338                document.querySelector('footer').style.marginTop = `-${document.querySelector('footer').offsetHeight}px`;
339                document.querySelector('footer').style.opacity = '0';
340                document.querySelector('footer').style.pointerEvents = 'none';
341                document.querySelector('#bmc-wbtn').style.opacity = '0';
342                document.querySelector('#bmc-wbtn').style.pointerEvents = 'none';
343                if (document.querySelector('div:has(> iframe[title="ticker tape TradingView widget"])')) document.querySelector('div:has(> iframe[title="ticker tape TradingView widget"])').style.marginTop = `-${document.querySelector('div:has(> iframe[title="ticker tape TradingView widget"])').clientHeight}px`;
344                document.querySelector('aside.not-simple').style.marginLeft = `-${document.querySelector('.sidebar').offsetWidth}px`;
345                document.querySelector('aside.not-simple').style.opacity = 0;
346                document.querySelector('aside.not-simple').style.pointerEvents = 'none';
347                document.querySelector('.sidebar.simple').style.marginTop = `-${document.querySelector('.sidebar.simple').offsetHeight}px`;
348                document.querySelector('.sidebar.simple').style.marginLeft = `-${document.querySelector('.sidebar.simple').offsetWidth}px`;
349                document.querySelector('.sidebar.simple').style.opacity = 0;
350                document.querySelector('.sidebar.simple').style.pointerEvents = 'none';
351                document.querySelector('.banner').style.marginTop = `-${document.querySelector('.banner').offsetHeight}px`;
352                document.querySelector('.banner').style.opacity = 0;
353                document.querySelector('.banner').style.pointerEvents = 'none';
354                document.querySelector('aside.simple').style.marginTop = `-${document.querySelector('aside.simple').offsetHeight}px`;
355                document.querySelector('aside.simple').style.opacity = 0;
356                document.querySelector('aside.simple').style.pointerEvents = 'none';
357                document.querySelector('.main').style.minHeight = 0;
358                document.querySelector('.split-content').style.paddingTop = 0;
359            };
360            zenMode = (zenMode) ? false : true;
361        });
362    } else {
363        document.querySelector('.history').classList.remove('trans');
364    };
365
366    document.querySelectorAll('.collapsed').forEach(collapsed => {
367        collapsed.addEventListener('click', function (event) {
368            if (event.target === collapsed || event.target.parentNode === collapsed) {
369                var opened = collapsed.classList.contains('active');
370                document.querySelectorAll('.collapsed').forEach(collapsed => {
371                    collapsed.classList.remove('active');
372                    collapsed.scrollTo({ top: 0, behavior: 'smooth' });
373                });
374                if (!opened) collapsed.classList.add('active');
375            };
376        });
377    });
378
379    recruiter = localStorage.getItem("recruiter");
380    if (recruiter && (recruiter === 'true')) document.body.classList.add('recruiter');
381
382    xp = document.querySelector('.xp');
383    if (xp && !xp.innerText.includes(xp.getAttribute('xp'))) {
384        count = Number(xp.getAttribute('xp'));
385        const totalDigits = count.toString().length;
386        (function countXp(i) {
387            setTimeout(function () {
388                if (!xp) return;
389                xp.innerText = `~${i.toString().padStart(totalDigits, '0')} days`;
390                if (i < count) countXp(i + 1);
391            }, 5);
392        })(0);
393    };
394
395    tts = document.querySelector('.tts');
396    if (tts) {
397        tts.classList.add('ready');
398        tts.setAttribute('onclick', `document.querySelector('audio')?.play()`);
399    };
400
401    selectedTheme = localStorage.getItem("theme") || document.body.getAttribute('theme');
402    document.body.setAttribute('theme', selectedTheme);
403    themeSelectors = document.querySelectorAll('#theme-select');
404    if (themeSelectors.length && selectedTheme) themeSelectors.forEac
404h(a => a.value = selectedTheme);
405    if (selectedTheme === 'light') {
406        document.head.querySelector('link[rel="icon"]').href = window.location.origin + '/favicon-dark.png';
407    } else {
408        document.head.querySelector('link[rel="icon"]').href = window.location.origin + '/favicon.png';
409    };
410
411    if (document.body.classList.toString().includes('simple')) setTimeout(() => {
412        document.querySelector('.logoSpinner')?.classList.add('active');
413    }, 1000);
414};
415
416function toggleSidebar() {
417    if (document.body.getAttribute('theme') && (document.body.getAttribute('theme') === 'synthwave') && (window.innerWidth > 950)) {
418        document.querySelector('aside').style.maxWidth = (document.querySelector('aside .toggle').classList.contains('active')) ? '51.25px' : '100vw';
419        document.querySelector('aside .toggle').classList.toggle('active');
420    } else {
421        asideWidth = document.querySelector('aside').offsetWidth + 18;
422        document.querySelector('aside').style.marginLeft = (document.querySelector('aside .toggle').classList.contains('active')) ? `-${asideWidth}px` : '0px';
423        document.querySelector('aside').style.maxWidth = 'unset';
424        document.querySelector('aside .toggle').classList.toggle('active');
425    };
426};
427
428function hideSidebar() {
429    if (document.querySelector('aside .toggle').classList.contains('active')) {
430        if (document.body.getAttribute('theme') && (document.body.getAttribute('theme') === 'synthwave') && (window.innerWidth > 950)) {
431            document.querySelector('aside').style.maxWidth = '51.25px';
432            document.querySelector('aside .toggle').classList.remove('active');
433        } else {
434            asideWidth = document.querySelector('aside').offsetWidth + 18;
435            document.querySelector('aside').style.marginLeft = `-${asideWidth}px`;
436            document.querySelector('aside').style.maxWidth = 'unset';
437            document.querySelector('aside .toggle').classList.remove('active');
438        };
439    };
440};
441
442function showSidebar() {
443    if (!document.querySelector('aside .toggle').classList.contains('active')) {
444        if (document.body.getAttribute('theme') && (document.body.getAttribute('theme') === 'synthwave') && (window.innerWidth > 950)) {
445            document.querySelector('aside').style.maxWidth = '100vw';
446            document.querySelector('aside .toggle').classList.add('active');
447        } else {
448            document.querySelector('aside').style.marginLeft = `0px`;
449            document.querySelector('aside').style.maxWidth = 'unset';
450            document.querySelector('aside .toggle').classList.add('active');
451        };
452    };
453};
454
455function copyEmail(event) {
456    const tempTextArea = document.createElement('textarea');
457    tempTextArea.value = '[email protected]';
458    tempTextArea.style.position = 'absolute';
459    tempTextArea.style.left = '-9999px';
460    document.body.appendChild(tempTextArea);
461    tempTextArea.select();
462    document.execCommand('copy');
463    document.body.removeChild(tempTextArea);
464    const targetElement = event.target;
465    var beforeHTML = targetElement.innerHTML;
466    targetElement.innerHTML = 'Copied!';
467    targetElement.classList.add('success');
468    setTimeout(() => {
469        targetElement.innerHTML = beforeHTML;
470        targetElement.classList.remove('success');
471    }, 3000);
472};
473
474var pjax;
475
476document.addEventListener("pjax:send", function () {
477    if (typeof topbar !== 'undefined') {
478        topbar.config({
479            barThickness: 3,
480            barColors: {
481                '0': (document.body.getAttribute('theme') === 'synthwave') ? '#659af3' : '#FF00EE',
482                '1.0': '#00FFF6'
483            },
484        });
485        topbar.show();
486    };
487    if (window.screen.width <= 950) hideSidebar();
488    if (!document.body.classList.toString().includes('simple')) document.querySelector('.content').scrollTop = 0;
489    document.querySelectorAll('.back').forEach(a => a.classList.remove('active'));
490    document.querySelectorAll('.forward').forEach(a => a.classList.remove('active'));
491});
492
493document.addEventListener('pjax:complete', function () {
494    documentReady();
495    document.querySelectorAll('.count img').forEach(img => img.src = img.src + '?');
496    document.querySelectorAll('.commits img').forEach(img => img.src = img.src + '?');
497    document.querySelectorAll('.marquee img').forEach(img => img.src = img.src + '?');
498    document.querySelectorAll('table img').forEach(img => img.src = img.src + '?');
499    document.querySelectorAll('.commitment img').forEach(img => img.src = img.src + '?');
500    if (!document.body.classList.toString().includes('simple') && document.querySelector('main .subgroup:has(.tradingview-widget-container)')) document.querySelector('main .subgroup:has(.tradingview-widget-container)').remove();
501});
502
503document.addEventListener("DOMContentLoaded", function () {
504    documentReady();
505    pjax = new Pjax({
506        selectors: ["aside .links", "aside .profile", "main", "footer .status"],
507        switches: {
508            "aside .links": Pjax.switches.outerHTML,
509            "aside .profile": Pjax.switches.outerHTML,
510            "main": document.body.classList.toString().includes('simple') ? Pjax.switches.outerHTML : Pjax.switches.sideBySide,
511            "footer .status": Pjax.switches.outerHTML
512        },
513        switchesOptions: {
514            "main": {
515                classNames: {
516                    remove: "Animated Animated--reverse Animate--fast Animate--noDelay",
517                    add: "Animated",
518                    backward: "Animate--slideInDown",
519                    forward: "Animate--slideInUp"
520                },
521                callbacks: {
522                    removeElement: function (el) {
523                        el.style.marginLeft = "-" + (el.getBoundingClientRect().width / 2) + "px"
524                    }
525                },
526            },
527        },
528        cacheBust: true,
529        scrollTo: document.body.classList.toString().includes('simple') ? ((window.screen.width <= 950) ? (document.querySelector('.sidebar').scrollHeight + document.querySelector('.banner').scrollHeight) : document.querySelector('.banner').scrollHeight) : 0,
530    });
531    document.querySelectorAll('.history .back').forEach(a => a.addEventListener('click', () => window.history.back()));
532    document.querySelectorAll('.history .forward').forEach(a => a.addEventListener('click', () => window.history.forward()));
533});
534
535function sortable(section, onUpdate) {
536    var dragEl, nextEl, newPos, dragGhost;
537
538    let oldPos = [...section.children].map(item => {
539        item.draggable = true
540        let pos = document.getElementById(item.id).getBoundingClientRect();
541        return pos;
542    });
543
544    function _onDragOver(e) {
545        e.preventDefault();
546        e.dataTransfer.dropEffect = 'move';
547        var target = e.target.closest('.note');
548        if (target && target !== dragEl) {
549            var targetPos = target.getBoundingClientRect();
550            var next = (e.clientY - targetPos.top) / (targetPos.bottom - targetPos.top) > .5;
551            if (next && target.nextSibling) {
552                section.insertBefore(dragEl, target.nextSibling);
553            } else {
554                section.insertBefore(dragEl, target);
555            };
556        };
557    };
558
559    sync = true;
560
561    function _onDragEnd(evt) {
562        evt.preventDefault();
563        newPos = [...section.children].map(child => {
564            let pos = document.getElementById(child.id).getBoundingClientRect();
565            return pos;
566        });
567        dragEl.classList.remove('ghost');
568        section.removeEventListener('dragover', _onDragOver, false);
569        section.removeEventListener('dragend', _onDragEnd, false);
570        nextEl !== dragEl.nextSibling ? onUpdate(dragEl) : false;
571        layout = [];
572        position = 0;
573        document.querySelectorAll('.note').forEach(note => {
574            layout.push({ id: note.id, position });
575            position++;
576        });
577        setTimeout(() => {
578            if (sync) {
579                sync = false;
580                fetch('/apps/notes', {
581                    method: 'POST',
582                    headers: {
583                        'Content-Type': 'application/json'
584                    },
585                    body: JSON.stringify({
586                        layout
587                    }),
588                });
589                setTimeout(() => {
590                    sync = true;
591                    document.querySelector('.refresh').innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 23 23" fill="none">
592                            <path d="M18.5949 5.16663C16.8618 3.32009 14.3989 2.16663 11.6666 2.16663C6.41992 2.16663 2.16663 6.41992 2.16663 11.6666C2.16663 16.9133 6.41992 21.1666 11.6666 21.1666C14.3989 21.1666 16.8618 20.0132 18.5949 18.1666M17.3236 7.98035L20.9804 7.98035L20.9804 4.3235" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" />
593                        </svg> Last Updated ${new Intl.DateTimeFormat('en-US', { hour: 'numeric', minute: '2-digit', hour12: true }).format(new Date())}`;
594                }, 5000);
595            };
596        }, 1000);
597    };
598
599    section.addEventListener('dragstart', function (e) {
600        var target = e.target.closest('.note');
601        if (target) {
602            dragEl = target;
603            nextEl = dragEl.nextSibling;
604            e.dataTransfer.effectAllowed = 'move';
605            e.dataTransfer.setData('Text', dragEl.textContent);
606            section.addEventListener('dragover', _onDragOver, false);
607            section.addEventListener('dragend', _onDragEnd, false);
608            setTimeout(function () {
609                dragEl.classList.add('ghost');
610            }, 0);
611        } else {
612            e.preventDefault();
613        };
614    });
615};
616
617function togglePrivateNote() {
618    document.querySelector('input[name="private"]').value = (document.querySelector('input[name="private"]').checked === true) ? 'off' : 'on';
619    document.querySelector('input[name="private"]').classList = (document.querySelector('input[name="private"]').checked === true) ? '' : 'active';
620};
621
622function addNoteAttachment() {
623    attachments = document.querySelector('.attachments');
624    attachments.innerHTML += `<input type="url" class="attachment" placeholder="${window.location.origin}/share/..." onchange="checkAttachmentRemove(event)">`;
625};
626
627function checkAttachmentRemove(event) {
628    if (event.target.value === '') event.target.remove();
629};
630
631function syncNotes(notesList) {
632    document.querySelectorAll('.note').forEach(note => note.classList.add('hidden'));
633    setTimeout(() => {
634        document.querySelectorAll('.note').forEach(note => note.remove());
635        notesList.sort((a, b) => (new Date(b.created)) - (new Date(a.created))).forEach(response => {
636            const note = document.createElement('div');
637            note.id = response.id;
638            note.classList = `note ${(response.content.length > 100) ? 'long' : ''} hidden`;
639            if (JSON.parse(response.attachments).length > 0) {
640                attachments = document.createElement('div');
641                attachments.classList = `attachments ${(JSON.parse(response.attachments).length > 1) ? 'many' : ''}`;
642                JSON.parse(response.attachments).forEach(attachment => {
643                    img = document.createElement((attachment.includes('.mp4') || attachment.includes('.mov')) ? 'video' : 'img');
644                    img.src = attachment;
645                    if ((attachment.includes('.mp4') || attachment.includes('.mov'))) img.setAttribute('autoplay', 'true');
646                    if ((attachment.includes('.mp4') || attachment.includes('.mov'))) img.setAttribute('loop', 'true');
647                    if ((attachment.includes('.mp4') || attachment.includes('.mov'))) img.setAttribute('muted', 'true');
648                    img.alt = 'Attachment';
649                    attachments.appendChild(img);
650                });
651                note.appendChild(attachments);
652            };
653            details = document.createElement('div');
654            details.classList = 'details';
655            info = document.createElement('div');
656            info.classList = 'info';
657            info.innerHTML = `<h5>${response.title}</h5><p>${response.content.replaceAll('\n', '<br>')}</p>`;
658            details.appendChild(info);
659            pills = document.createElement('div');
660            pills.classList = 'pills';
661            time = document.createElement('div');
662            time.classList = 'time';
663            time.setAttribute('time', new Date());
664            date = new Date(response.created);
665            now = new Date();
666            diff = now - date;
667            time.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewB
667ox="0 0 11 11" fill="none"><path d="M5.5 2.34211V4.97368C5.5 5.26436 5.73564 5.5 6.02632 5.5L8.6579 5.5M5.5 10.5C2.73858 10.5 0.5 8.26142 0.5 5.5C0.5 2.73858 2.73858 0.5 5.5 0.5C8.26142 0.5 10.5 2.73858 10.5 5.5C10.5 8.26142 8.26142 10.5 5.5 10.5Z" stroke-linecap="round" stroke-linejoin="round" /></svg>${(diff < 60000) ? "Just now" : (diff < 3600000) ? "Less than an hour ago" : (diff < 43200000 && date.getDate() === now.getDate()) ? `${Math.floor(diff / 3600000)} ${Math.floor(diff / 3600000) === 1 ? "hour" : "hours"} ago` : (diff < 86400000 && now.getDate() - date.getDate() === 1) ? "Yesterday" : `${Math.floor(diff / 86400000)} ${Math.floor(diff / 86400000) === 1 ? "day" : "days"} ago`}`;
668            pills.appendChild(time);
669            owner = document.createElement('div');
670            owner.classList = 'time';
671            date = new Date(response.created);
672            now = new Date();
673            diff = now - date;
674            owner.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 11 11" fill="none"><path d="M5.5 2.34211V4.97368C5.5 5.26436 5.73564 5.5 6.02632 5.5L8.6579 5.5M5.5 10.5C2.73858 10.5 0.5 8.26142 0.5 5.5C0.5 2.73858 2.73858 0.5 5.5 0.5C8.26142 0.5 10.5 2.73858 10.5 5.5C10.5 8.26142 8.26142 10.5 5.5 10.5Z" stroke-linecap="round" stroke-linejoin="round" /></svg>${response.owner}`;
675            pills.appendChild(owner);
676            if (response.private == 1) {
677                hidden = document.createElement('div');
678                hidden.classList = 'time';
679                hidden.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="21" height="17" viewBox="0 0 21 17" fill="none"><path d="M2.8993 16.2015L18.1008 1M18.1007 5.62242C18.817 6.37969 19.3561 7.11668 19.718 7.6681C20.093 8.23955 20.0945 8.95949 19.7195 9.53102C18.5386 11.3312 15.4654 15.1156 10.4999 15.1156C9.90787 15.1156 9.34269 15.0618 8.80442 14.964M12.2937 2.25588C11.7261 2.1464 11.1282 2.08583 10.4999 2.08583C5.53453 2.08583 2.46133 5.87028 1.28037 7.67046C0.905432 8.24199 0.907069 8.96227 1.28214 9.53371C1.65212 10.0974 2.20722 10.8549 2.94744 11.6298" stroke-linecap="round" stroke-linejoin="round" /></svg>Hidden`;
680                pills.appendChild(hidden);
681            };
682            details.appendChild(pills);
683            actions = document.createElement('div');
684            actions.classList = 'pills actions';
685            actions.innerHTML = `<div class="pills actions"><div class="time" onclick="cloneNote(${response.id})"><svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 17 17" fill="none"><path d="M10.9999 13.4999V14.3333C10.9999 15.2538 10.2537 16 9.33328 16H2.66666C1.74619 16 1 15.2538 1 14.3333V7.66666C1 6.74621 1.74615 6.00004 2.66659 6L3.49998 5.99997M10.9999 6.00007V3.91675M10.9999 6.00007V8.08339M10.9999 6.00007H8.91661M10.9999 6.00007H13.0833M7.66662 1H14.3332C15.2537 1 15.9999 1.74619 15.9999 2.66666V9.33328C15.9999 10.2537 15.2537 10.9999 14.3332 10.9999H7.66662C6.74615 10.9999 5.99997 10.2537 5.99997 9.33328V2.66666C5.99997 1.74619 6.74615 1 7.66662 1Z" stroke-linecap="round" stroke-linejoin="round" /></svg>Clone</div><div class="time" onclick="editNote(${response.id})"><svg xmlns="http://www.w3.org/2000/svg" width="21" height="21" viewBox="0 0 21 21" fill="none"><path d="M2.25912 19.864H20.2947M18.9143 1.18768L19.8423 2.11571C20.6961 2.96947 20.6961 4.35368 19.8423 5.20744L7.56055 17.4892C7.32057 17.7292 7.028 17.91 6.70602 18.0173L2.20299 19.5183C1.77572 19.6608 1.36924 19.2543 1.51166 18.827L3.01267 14.324C3.11999 14.002 3.30081 13.7094 3.5408 13.4694L15.8226 1.18768C16.6764 0.333923 18.0606 0.333925 18.9143 1.18768Z" stroke-linecap="round" stroke-linejoin="round"/></svg>Edit</div>${(response.private == 1) ? `<div class="time" onclick="publicNote(${response.id})"><svg xmlns="http://www.w3.org/2000/svg" width="21" height="15" viewBox="0 0 21 15" fill="none"><path d="M20.1353 6.58417C20.5102 7.15565 20.5102 7.8731 20.1353 8.44458C18.9544 10.2446 15.8815 14.0288 10.9164 14.0288C5.95143 14.0288 2.87849 10.2446 1.69762 8.44458C1.32272 7.8731 1.32272 7.15565 1.69762 6.58417C2.87849 4.78415 5.95143 1 10.9164 1C1
6855.8815 1 18.9544 4.78415 20.1353 6.58417Z" stroke-linecap="round" stroke-linejoin="round" /><path d="M14.1736 7.51437C14.1736 9.31327 12.7153 10.7716 10.9164 10.7716C9.11754 10.7716 7.65925 9.31327 7.65925 7.51437C7.65925 5.71548 9.11754 4.25719 10.9164 4.25719C12.7153 4.25719 14.1736 5.71548 14.1736 7.51437Z" stroke-linecap="round" stroke-linejoin="round" /></svg>Publicize</div>` : `<div class="time" onclick="hideNote(${response.id})"><svg xmlns="http://www.w3.org/2000/svg" width="21" height="17" viewBox="0 0 21 17" fill="none"><path d="M2.8993 16.2015L18.1008 1M18.1007 5.62242C18.817 6.37969 19.3561 7.11668 19.718 7.6681C20.093 8.23955 20.0945 8.95949 19.7195 9.53102C18.5386 11.3312 15.4654 15.1156 10.4999 15.1156C9.90787 15.1156 9.34269 15.0618 8.80442 14.964M12.2937 2.25588C11.7261 2.1464 11.1282 2.08583 10.4999 2.08583C5.53453 2.08583 2.46133 5.87028 1.28037 7.67046C0.905432 8.24199 0.907069 8.96227 1.28214 9.53371C1.65212 10.0974 2.20722 10.8549 2.94744 11.6298" stroke-linecap="round" stroke-linejoin="round" /></svg>Hide</div>`}<div class="time" onclick="deleteNote(${response.id})"><svg xmlns="http://www.w3.org/2000/svg" width="21" height="21" viewBox="0 0 21 21" fill="none"><path d="M16.8332 4.16667H19.9999M16.8332 4.16667V17.8889C16.8332 19.0548 15.888 20 14.7221 20H6.27766C5.11172 20 4.16654 19.0548 4.16654 17.8889V4.16667M16.8332 4.16667H4.16654M0.999878 4.16667H4.16654M8.38877 7.86111V16.3056M12.611 7.86111V16.3056M6.80543 1H14.1943" stroke-linecap="round" stroke-linejoin="round" /></svg>Delete</div></div>`
686            details.appendChild(actions);
687            note.appendChild(details);
688            document.querySelector('.notes').appendChild(note);
689        });
690        snapToLayout();
691        document.querySelectorAll('.note').forEach(note => note.classList.remove('hidden'));
692    }, 250);
693    document.querySelector('.refresh').innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 23 23" fill="none">
694            <path d="M18.5949 5.16663C16.8618 3.32009 14.3989 2.16663 11.6666 2.16663C6.41992 2.16663 2.16663 6.41992 2.16663 11.6666C2.16663 16.9133 6.41992 21.1666 11.6666 21.1666C14.3989 21.1666 16.8618 20.0132 18.5949 18.1666M17.3236 7.98035L20.9804 7.98035L20.9804 4.3235" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" />
695        </svg> Last Updated ${new Intl.DateTimeFormat('en-US', { hour: 'numeric', minute: '2-digit', hour12: true }).format(new Date())}`;
696};
697
698function snapToLayout() {
699    notMoved = [];
700    moved = [];
701    document.querySelectorAll('.note').forEach(note => {
702        const id = note.id;
703        const e = notesLayout.find(noteLayout => noteLayout.id === id);
704        if (e) {
705            moved.push(e);
706        } else {
707            notMoved.push({ id });
708        };
709    });
710    allNotes = [...notMoved, ...moved];
711    const notesContainer = document.querySelector('.notes');
712    allNotes.sort((a, b) => a.position - b.position).forEach(noteLayout => {
713        const noteElement = document.getElementById(noteLayout.id);
714        if (noteElement) notesContainer.appendChild(noteElement);
715    });
716};
717
718async function publicNote(id) {
719    await fetch('/apps/notes', {
720        method: 'POST',
721        headers: {
722            'Content-Type': 'application/json'
723        },
724        body: JSON.stringify({
725            id,
726            action: "public",
727        }),
728    })
729        .then(response => response.json())
730        .then(response => {
731            if (!response.length === 0) return;
732            syncNotes(response);
733        })
734        .catch(err => {
735            console.log(err);
736        });
737};
738
739async function hideNote(id) {
740    await fetch('/apps/notes', {
741        method: 'POST',
742        headers: {
743            'Content-Type': 'application/json'
744        },
745        body: JSON.stringify({
746            id,
747            action: "private",
748        }),
749    })
750        .then(response => response.json())
751        .then(response => {
752            if (!response.length === 0) return;
753            syncNotes(response);
754        })
755        .catch(err => {
756            console.log(err);
757        });
758};
759
760async function deleteNote(id) {
761    await fetch('/apps/notes', {
762        method: 'POST',
763        headers: {
764            'Content-Type': 'application/json'
765        },
766        body: JSON.stringify({
767            id,
768            action: "delete",
769        }),
770    })
771        .then(response => response.json())
772        .then(response => {
773            if (!response.length === 0) return;
774            syncNotes(response);
775        })
776        .catch(err => {
777            console.log(err);
778        });
779};
780
781async function cloneNote(id) {
782    await cancelEdit();
783    note = document.getElementById(id);
784    document.querySelector('input[name="title"]').value = note.querySelector('h5').innerText;
785    document.querySelector('textarea[name="content"]').value = note.querySelector('p').innerText;
786    document.querySelector('input[name="private"]').value = (note.querySelectorAll('.time')[4].innerText.includes('Hide')) ? 'off' : 'on';
787    document.querySelector('input[name="private"]').classList = (note.querySelectorAll('.time')[4].innerText.includes('Hide')) ? '' : 'active';
788    attachments = document.querySelector('.attachments');
789    note.querySelectorAll('.attachments > *').forEach(attachment => {
790        attachments.innerHTML += `<input type="url" class="attachment" placeholder="${window.location.origin}/share/..." onchange="checkAttachmentRemove(event)" value="${attachment.src}">`;
791    });
792    setTimeout(() => {
793        document.querySelector('.content').scrollTo({ top: 0, behavior: 'smooth' });
794    }, 500);
795};
796
797async function editNote(id) {
798    if (editing) await cancelEdit();
799    await cloneNote(id);
800    editing = id;
801    document.querySelector('.newNote > button').style.display = "none";
802    buttons = document.createElement('div');
803    buttons.classList = 'buttons';
804    editButton = document.createElement('button');
805    editButton.classList = 'button';
806    editButton.setAttribute('type', 'submit');
807    editButton.innerText = 'Edit Note';
808    buttons.appendChild(editButton);
809    cancelButton = document.createElement('button');
810    cancelButton.classList = 'button';
811    cancelButton.setAttribute('type', 'button');
812    cancelButton.setAttribute('onclick', 'cancelEdit()');
813    cancelButton.innerText = 'Cancel';
814    buttons.appendChild(cancelButton);
815    document.querySelector('.newNote').appendChild(buttons);
816};
817
818async function cancelEdit() {
819    if (document.querySelector('input[name="title"]')) document.querySelector('input[name="title"]').value = '';
820    document.querySelector('textarea[name="content"]').value = '';
821    if (document.querySelector('input[name="private"]')) document.querySelector('input[name="private"]').value = '';
822    if (document.querySelector('input[name="private"]')) document.querySelector('input[name="private"]').value = 'off';
823    if (document.querySelector('input[name="private"]')) document.querySelector('input[name="private"]').classList = '';
824    document.querySelectorAll('.attachment').forEach(attachment => {
825        attachment.remove();
826    });
827    if (document.querySelector('.newNote > button')) document.querySelector('.newNote > button').style.display = "flex";
828    if (document.querySelector('.newNote .buttons')) document.querySelector('.newNote .buttons').remove();
829    if (document.querySelector('.newLog > button')) document.querySelector('.newLog > button').style.display = "flex";
830    if (document.querySelector('.newLog .buttons')) document.querySelector('.newLog .buttons').remove();
831    editing = false;
832};
833
834function syncLogs(logsList) {
835    document.querySelectorAll('.log').forEach(log => log.classList.add('hidden'));
836    setTimeout(() => {
837        document.querySelectorAll('.log').forEach(log => log.remove());
838        logsList.sort((a, b) => (new Date(b.created)) - (new Date(a.created))).forEach(response => {
839            const log = document.createElement('div');
840            log.id = response.id;
841            log.classList = `log hidden`;
842            date = new Date(response.created);
843            now = new Date();
844            months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
845            date1 = document.createElement('div');
846            date1.classList = 'date';
847            date1.innerHTML = `<h2>${date.getDate()}</h2><h5>${months[date.getMonth()]}</h5>${(date.getFullYear() != now.getFullYear()) ? `<h6>${date.getFullYear()}</h6>` : ''}`
848            log.appendChild(date1);
849            details = document.createElement('div');
850            details.classList = 'details';
851            info = document.createElement('div');
852            info.classList = 'info';
853            info.innerHTML = `<p>${response.content.replaceAll('\n', '<br>')}</p>`;
854            details.appendChild(info);
855            pills = document.createElement('div');
856            pills.classList = 'pills';
857            time = document.createElement('div');
858            time.classList = 'time';
859            time.setAttribute('time', new Date());
860            diff = now - date;
861            time.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewB
861ox="0 0 11 11" fill="none"><path d="M5.5 2.34211V4.97368C5.5 5.26436 5.73564 5.5 6.02632 5.5L8.6579 5.5M5.5 10.5C2.73858 10.5 0.5 8.26142 0.5 5.5C0.5 2.73858 2.73858 0.5 5.5 0.5C8.26142 0.5 10.5 2.73858 10.5 5.5C10.5 8.26142 8.26142 10.5 5.5 10.5Z" stroke-linecap="round" stroke-linejoin="round" /></svg>${(diff < 60000) ? "Just now" : (diff < 3600000) ? "Less than an hour ago" : (diff < 43200000 && date.getDate() === now.getDate()) ? `${Math.floor(diff / 3600000)} ${Math.floor(diff / 3600000) === 1 ? "hour" : "hours"} ago` : (diff < 86400000 && now.getDate() - date.getDate() === 1) ? "Yesterday" : `${Math.floor(diff / 86400000)} ${Math.floor(diff / 86400000) === 1 ? "day" : "days"} ago`}`;
862            pills.appendChild(time);
863            owner = document.createElement('div');
864            owner.classList = 'time';
865            date = new Date(response.created);
866            now = new Date();
867            diff = now - date;
868            owner.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="11" height="11" viewBox="0 0 11 11" fill="none"><path d="M5.5 2.34211V4.97368C5.5 5.26436 5.73564 5.5 6.02632 5.5L8.6579 5.5M5.5 10.5C2.73858 10.5 0.5 8.26142 0.5 5.5C0.5 2.73858 2.73858 0.5 5.5 0.5C8.26142 0.5 10.5 2.73858 10.5 5.5C10.5 8.26142 8.26142 10.5 5.5 10.5Z" stroke-linecap="round" stroke-linejoin="round" /></svg>${response.owner}`;
869            pills.appendChild(owner);
870            details.appendChild(pills);
871            actions = document.createElement('div');
872            actions.classList = 'pills actions';
873            actions.innerHTML = `<div class="time" onclick="editLog(${response.id})"><svg xmlns="http://www.w3.org/2000/svg" width="21" height="21" viewBox="0 0 21 21" fill="none"><path d="M2.25912 19.864H20.2947M18.9143 1.18768L19.8423 2.11571C20.6961 2.96947 20.6961 4.35368 19.8423 5.20744L7.56055 17.4892C7.32057 17.7292 7.028 17.91 6.70602 18.0173L2.20299 19.5183C1.77572 19.6608 1.36924 19.2543 1.51166 18.827L3.01267 14.324C3.11999 14.002 3.30081 13.7094 3.5408 13.4694L15.8226 1.18768C16.6764 0.333923 18.0606 0.333925 18.9143 1.18768Z" stroke-linecap="round" stroke-linejoin="round"/></svg>Edit</div><div class="time" onclick="deleteLog(${response.id})"><svg xmlns="http://www.w3.org/2000/svg" width="21" height="21" viewBox="0 0 21 21" fill="none"><path d="M16.8332 4.16667H19.9999M16.8332 4.16667V17.8889C16.8332 19.0548 15.888 20 14.7221 20H6.27766C5.11172 20 4.16654 19.0548 4.16654 17.8889V4.16667M16.8332 4.16667H4.16654M0.999878 4.16667H4.16654M8.38877 7.86111V16.3056M12.611 7.86111V16.3056M6.80543 1H14.1943" stroke-linecap="round" stroke-linejoin="round" /></svg>Delete</div></div>`
874            details.appendChild(actions);
875            log.appendChild(details);
876            document.querySelector('.logs').appendChild(log);
877        });
878        snapToLayout();
879        document.querySelectorAll('.log').forEach(log => log.classList.remove('hidden'));
880    }, 250);
881    document.querySelector('.refresh').innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="23" height="23" viewBox="0 0 23 23" fill="none">
882            <path d="M18.5949 5.16663C16.8618 3.32009 14.3989 2.16663 11.6666 2.16663C6.41992 2.16663 2.16663 6.41992 2.16663 11.6666C2.16663 16.9133 6.41992 21.1666 11.6666 21.1666C14.3989 21.1666 16.8618 20.0132 18.5949 18.1666M17.3236 7.98035L20.9804 7.98035L20.9804 4.3235" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" />
883        </svg> Last Updated ${new Intl.DateTimeFormat('en-US', { hour: 'numeric', minute: '2-digit', hour12: true }).format(new Date())}`;
884};
885
886async function deleteLog(id) {
887    await fetch('/apps/visitors', {
888        method: 'POST',
889        headers: {
890            'Content-Type': 'application/json'
891        },
892        body: JSON.stringify({
893            id,
894            action: "delete",
895        }),
896    })
897        .then(response => response.json())
898        .then(response => {
899            if (!response.length === 0) return;
900            syncLogs(response);
901        })
902        .catch(err => {
903            console.log(err);
904        });
905};
906
907async function editLog(id) {
908    await cancelEdit();
909    log = document.getElementById(id);
910    document.querySelector('textarea[name="content"]').value = log.querySelector('p').innerText;
911    setTimeout(() => {
912        document.querySelector('.content').scrollTo({ top: 0, behavior: 'smooth' });
913    }, 500);
914    editing = id;
915    document.querySelector('.newLog > button').style.display = "none";
916    buttons = document.createElement('div');
917    buttons.classList = 'buttons';
918    editButton = document.createElement('button');
919    editButton.classList = 'button';
920    editButton.setAttribute('type', 'submit');
921    editButton.innerText = 'Edit Log';
922    buttons.appendChild(editButton);
923    cancelButton = document.createElement('button');
924    cancelButton.classList = 'button';
925    cancelButton.setAttribute('type', 'button');
926    cancelButton.setAttribute('onclick', 'cancelEdit()');
927    cancelButton.innerText = 'Cancel';
928    buttons.appendChild(cancelButton);
929    document.querySelector('.newLog').appendChild(buttons);
930};
931
932function adp(type) {
933    switch (type) {
934        case 'gen':
935            document.querySelectorAll("input")[0].value = "";
936            document.querySelectorAll("input")[1].value = "";
937            var randomNumber1 = Math.floor(Math.random() * 5);
938            var randomNumber2 = Math.floor(Math.random() * 5);
939            var randomNumber3 = Math.floor(Math.random() * 5);
940            var num3 = Math.floor(Math.random() * 10);
941            var num4 = Math.floor(Math.random() * 20);
942            if (randomNumber1 === 0) {
943                var sign2 = "+";
944                var num2 = num4 - num3;
945            };
946            if (randomNumber1 === 1) {
947                var sign2 = "-";
948                var num2 = num4 + num3;
949            };
950            if (randomNumber1 === 2) {
951                var sign2 = "*";
952                var num2 = num4 / num3;
953            };
954            if (randomNumber1 === 3 || randomNumber1 === 4) {
955                var sign2 = "/";
956                var num2 = num4 * num3;
957            };
958            if (randomNumber2 === 0) {
959                var sign1 = "+";
960                var num1 = randomNumber3 - num2;
961            };
962            if (randomNumber2 === 1) {
963                var sign1 = "-";
964                var num1 = randomNumber3 + num2;
965            };
966            if (randomNumber2 === 2) {
967                var sign1 = "*";
968                var num1 = randomNumber3 / num2;
969            };
970            if (randomNumber2 === 3 || randomNumber2 === 4) {
971                var sign1 = "/";
972                var num1 = randomNumber3 * num2;
973            };
974            num1 = Math.floor(num1);
975            num2 = Math.floor(num2);
976            document.querySelectorAll("h3")[0].innerHTML = num1;
977            document.querySelectorAll("h3")[1].innerHTML = randomNumber3;
978            document.querySelectorAll("h3")[2].innerHTML = num3;
979            num4 = eval(eval(document.querySelectorAll("h3")[0].innerHTML + sign1 + document.querySelectorAll("h3")[1].innerHTML) + sign2 + document.querySelectorAll("h3")[2].innerHTML);
980            document.querySelectorAll("h3")[3].innerHTML = num4;
981            if (Number.isInteger(num1) && Number.isInteger(num2) && Number.isInteger(num3) && Number.isInteger(num4)) {
982                console.log("Answers: " + sign1 + ", " + sign2);
983                document.querySelectorAll("input")[0].focus();
984            } else {
985                adp('gen');
986            };
987            break;
988        case 'check':
989            try {
990                if (!document.querySelectorAll("input")[0].value || !document.querySelectorAll("input")[1].value || document.querySelectorAll("input")[0].value === '' || document.querySelectorAll("input")[1].value === '') {
991                    if (!document.querySelectorAll("input")[1].value) document.querySelectorAll("input")[1].focus();
992                    if (!document.querySelectorAll("input")[0].value) document.querySelectorAll("input")[0].focus();
993                } else if (document.querySelectorAll("input")[0].value === ' ') {
994                    document.querySelectorAll("input")[0].value = '';
995                    document.querySelectorAll("input")[0].focus();
996                } else if (document.querySelectorAll("input")[1].value === ' ') {
997                    document.querySelectorAll("input")[1].value = '';
998                    document.querySelectorAll("input")[1].focus();
999                } else {
1000                    if (eval(eval(document.querySelectorAll("h3")[0].innerHTML + document.querySelectorAll("input")[0].value + document.querySelectorAll("h3")[1].innerHTML) + document.querySelectorAll("input")[1].value + document.querySelectorAll("h3")[2].innerHTML) == document.querySelectorAll("h3")[3].innerHTML) {
1001                        score++;
1002                        document.querySelector(".alert").innerHTML = "Correct! Score: " + score;
1003                        document.querySelector(".alert").classList = "alert green";
1004                        send();
1005                        adp('gen');
1006                    } else {
1007                        document.querySelector(".alert").innerHTML = "Incorrect! Try again. Score: " + score;
1008                        document.querySelector(".alert").classList = "alert red";
1009                    };
1010                };
1011            } catch { };
1012            break;
1013        case 'reset':
1014            score = 0;
1015            send();
1016            adp('init');
1017            document.querySelector(".alert").innerHTML = "Your score has been reset. Score: " + score;
1018            document.querySelector(".alert").classList = "alert yellow";
1019            break;
1020        case 'init':
1021            adp('skip');
1022            break;
1023        case 'skip':
1024            adp('gen');
1025            document.querySelector(".alert").innerHTML = "Score: " + score;
1026            document.querySelector(".alert").classList = "alert yellow";
1027            break;
1028        case 'next':
1029            if ((event.target.value.length === 1) && (event.target.value != ' ')) document.querySelectorAll("input")[1].focus();
1030            break;
1031        case 'regex':
1032            const regex = /^[+\-*/]$/;
1033            if (!regex.test(event.target.value)) event.target.value = '';
1034            break;
1035        default:
1036            console.log("Variable 'type' as '" + type + "' is not valid.");
1037            break;
1038    };
1039    return false;
1040};
1041
1042const url = 'https://lens.admin-host.com';
1043const host = 'faisaln';
1044const width = 600;
1045const height = 850;
1046
1047function receiveMessage(event) {
1048    if (event.origin === url) {
1049        fetch('/sso', {
1050            method: 'POST',
1051            headers: {
1052                'Content-Type': 'application/json'
1053            },
1054            body: JSON.stringify(event.data)
1055        }).then(response => response.json()).then(data => {
1056            window.location.reload();
1057        }).catch(error => {
1058            console.error('Error:', error);
1059            window.location.reload();
1060        });
1061    };
1062};
1063
1064function login() {
1065    if (window.matchMedia('(pointer: coarse)').matches) {
1066        window.location.href = `${url}?host=${host}&insecure=true&return=${document.domain}&redirect=https://${document.domain}/sso`;
1067    } else {
1068        window.addEventListener('message', receiveMessage, false);
1069        const popupWindow = window.open(`${url}?host=${host}&return=${document.domain}`, 'popup', `width=${width},height=${height},left=${(screen.width / 2) - (width / 2)},top=${(screen.height / 2) - (height / 2)}`);
1070    };
1071};
1072
1073function isRecruiter() {
1074    localStorage.setItem("recruiter", true);
1075    document.body.classList.add('recruiter');
1076};
1077
1078function notRecruiter() {
1079    localStorage.setItem("recruiter", false);
1080    document.body.classList.remove('recruiter');
1081};
1082
1083function changeTheme(event) {
1084    localStorage.setItem("theme", event.value);
1085    document.body.setAttribute('theme', event.value);
1086    themeSelectors = document.querySelectorAll('#theme-select');
1087    if (themeSelectors.length && event.value) themeSelectors.forEach(a => a.value = event.value);
1088    hideSidebar();
1089    showSidebar();
1090    if (event.value === 'light') {
1091        document.head.querySelector('link[rel="icon"]').href = window.location.origin + '/favicon-dark.png';
1092    } else {
1093        document.head.querySelector('link[rel="icon"]').href = window.location.origin + '/favicon.png';
1094    };
1095};
1096
1097function changeLayout(event) {
1098    localStorage.setItem("layout", event.value);
1099    document.body.classList = event.value;
1100    layoutSelectors = document.querySelectorAll('#layout-select');
1101    if (layoutSelectors.length && event.value) layoutSelectors.forEach(a => a.value = event.value);
1102    showSidebar();
1103    hideSidebar();
1104};
1105
1106var currentFilter = 'all';
1107var currentSort = 'default';
1108var isFiltering = false;
1109var isSorting = false;
1110
1111function filterProjects(event = currentFilter) {
1112    if (isFiltering) return;
1113    isFiltering = true;
1114    if (event.value) currentFilter = event.value;
1115    document.querySelectorAll('.works .work').forEach(project => {
1116        project.style.display = 'flex';
1117        switch (event.value || event) {
1118            case 'featured':
1119                if (!project.querySelector('.details .info h6').innerHTML.includes('⭐')) project.style.display = 'none';
1120                break;
1121            case 'templates':
1122                if (!project.querySelector('.details .info h6').innerHTML.includes('🖼️')) project.style.display = 'none';
1123                break;
1124            case 'cms':
1125                if (!project.querySelector('.details .info h6').innerHTML.includes('✨')) project.style.display = 'none';
1126                break;
1127            default:
1128                break;
1129        };
1130    });
1131    if (event.value && !isSorting) sortProjects();
1132    isFiltering = false;
1133};
1134
1135function sortProjects(event = currentSort) {
1136    if (isSorting) return;
1137    isSorting = true;
1138    if (event.value) currentSort = event.value;
1139    var projects = document.querySelectorAll('.works .work');
1140    switch (event.value || event) {
1141        case 'newest':
1142            projects = [...projects].sort((a, b) => b.getAttribute('published') - a.getAttribute('published'));
1143            break;
1144        case 'oldest':
1145            projects = [...projects].sort((a, b) => a.getAttribute('published') - b.getAttribute('published'));
1146            break;
1147        case 'recent':
1148            projects = [...projects].sort((a, b) => b.getAttribute('updated') - a.getAttribute('updated'));
1149            break;
1150        case 'a-z':
1151            projects = [...projects].sort((a, b) => a.querySelector('.details .info h6').innerHTML.localeCompare(b.querySelector('.details .info h6').innerHTML));
1152            break;
1153        case 'z-a':
1154            projects = [...projects].sort((a, b) => b.querySelector('.details .info h6').innerHTML.localeCompare(a.querySelector('.details .info h6').innerHTML));
1155            break;
1156        default:
1157            projects = [...projects].sort((a, b) => Number(a.getAttribute('rank')) - Number(b.getAttribute('rank')));
1158            break;
1159    };
1160    var projectsString = '';
1161    for (i = 0; i < projects.length; i++) {
1162        projectsString += projects[i].outerHTML;
1163    };
1164    document.querySelector('.works').innerHTML = projectsString;
1165    if (event.value && !isFiltering) filterProjects();
1166    isSorting = false;
1167};
1168
1169if (document.body.classList.toString().includes('simple')) {
1170    document.addEventListener('scroll', () => {
1171        if (window.scrollY > 150) {
1172            document.querySelector('.sidebar').classList.add('scrolled');
1173        } else {
1174            document.querySelector('.sidebar').classList.remove('scrolled');
1175        };
1176    });
1177};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.