Pi66

git.pi66.xyz
A web interface for the pi66.xyz Git server
git clone https://git.pi66.xyz/git.pi66.xyz

src/templates/partials/scripts.html

 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
<script>
function timeAgo(dateString) {
    const date = new Date(dateString.replace(" ", "T"));
    const now = new Date();
    const diff = now - date;

    const units = [
        ["year", 365 * 24 * 60 * 60 * 1000],
        ["month", 30 * 24 * 60 * 60 * 1000],
        ["day", 24 * 60 * 60 * 1000],
        ["hour", 60 * 60 * 1000],
        ["minute", 60 * 1000],
        ["second", 1000],
    ];

    for (const [unit, ms] of units) {
        const value = Math.floor(diff / ms);

        if (value >= 1) {
            return `<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mrow><mi>v</mi><mi>a</mi><mi>l</mi><mi>u</mi><mi>e</mi></mrow></mrow></math>{unit}${value !== 1 ? "s" : ""} ago`;
        }
    }

    return "just now";
}

    function typePerLetter(selector, speed = 100) {
        const el = document.querySelector(selector);
        if (!el) return;

        const text = el.textContent;
        el.textContent = "";
        let i = 0;

        const interval = setInterval(() => {
            if (i >= text.length) {
                clearInterval(interval);
                return;
            }

            const char = text[i];
            if (char === "\n") {
                el.appendChild(document.createElement("br"));
            } else {
                el.append(char);
            }
            i++;
        }, speed);
    }

    typePerLetter(".pi66-title", 120);
    document.body.style.zoom = "100%";
    document.querySelectorAll(".time-ago").forEach(element => {
        element.textContent = timeAgo(element.textContent.trim());
    });
</script>