summaryrefslogtreecommitdiffstats
path: root/twt.gumx.cc/body.html
blob: 7f3adc3a553bf92eb4686871ff177872bb4972a1 (plain) (blame)
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
<p>
<a href="/twtxt.txt">twtxt.txt</a> /
follow: <code>twtxt follow gumx https://twt.gumx.cc/twtxt.txt</code>
</p>
<div id="feed"></div>

<script>
async function loadFeed() {
    const feed = document.getElementById('feed');
    try {
        const res = await fetch('/twtxt.txt');
        if (!res.ok) throw new Error('HTTP ' + res.status);
        const text = await res.text();
        const lines = text.split('\n')
            .filter(l => l && !l.startsWith('#'))
            .map(l => {
                const tab = l.indexOf('\t');
                if (tab === -1) return null;
                return { time: l.slice(0, tab), text: l.slice(tab + 1) };
            })
            .filter(Boolean)
            .reverse();

        if (lines.length === 0) {
            feed.innerHTML = '<p id="error">no twts yet.</p>';
            return;
        }

        feed.innerHTML = lines.map(t => {
            const d = new Date(t.time);
            const dateStr = d.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
            const timeStr = d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' });
            return `<div class="twt">
<hr>
<span class="twt-time">${dateStr} ${timeStr}</span>
<span class="twt-text">${escapeHtml(t.text)}</span>
</div>`;
        }).join('');
    } catch (e) {
        feed.innerHTML = '<p id="error">could not load feed.</p>';
    }
}

function escapeHtml(s) {
    return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}

loadFeed();
</script>