From 799011212d371972772f770675cf77faacb85da0 Mon Sep 17 00:00:00 2001 From: TomatoCake <60300461+DEVTomatoCake@users.noreply.github.com> Date: Mon, 1 Jul 2024 21:19:22 +0200 Subject: [PATCH] markdown timestamps --- webpage/markdown.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ webpage/style.css | 6 +++++- webpage/themes.css | 3 +++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/webpage/markdown.ts b/webpage/markdown.ts index 0150309..41aad61 100644 --- a/webpage/markdown.ts +++ b/webpage/markdown.ts @@ -313,6 +313,48 @@ function markdown(text : string|string[],{keep=false,stdsize=false} = {}){ continue; } } + + if (txt[i]==="<" && txt[i + 1]==="t" && txt[i + 2]===":") { + let found=false; + const build=["<","t",":"]; + let j = i+3; + for (; txt[j] !== void 0; j++) { + build.push(txt[j]); + + if (txt[j]===">") { + found=true; + break; + } + } + + if (found) { + appendcurrent(); + i=j; + + const parts=build.join("").match(/^$/); + const dateInput=new Date(Number.parseInt(parts[1]) * 1000); + let time=""; + if (Number.isNaN(dateInput.getTime())) time=build.join(""); + else { + if (parts[3]==="d") time=dateInput.toLocaleString(void 0, {day: "2-digit", month: "2-digit", year: "numeric"}); + else if (parts[3]==="D") time=dateInput.toLocaleString(void 0, {day: "numeric", month: "long", year: "numeric"}); + else if (!parts[3] || parts[3]==="f") time=dateInput.toLocaleString(void 0, {day: "numeric", month: "long", year: "numeric"}) + " " + + dateInput.toLocaleString(void 0, {hour: "2-digit", minute: "2-digit"}); + else if (parts[3]==="F") time=dateInput.toLocaleString(void 0, {day: "numeric", month: "long", year: "numeric", weekday: "long"}) + " " + + dateInput.toLocaleString(void 0, {hour: "2-digit", minute: "2-digit"}); + else if (parts[3]==="t") time=dateInput.toLocaleString(void 0, {hour: "2-digit", minute: "2-digit"}); + else if (parts[3]==="T") time=dateInput.toLocaleString(void 0, {hour: "2-digit", minute: "2-digit", second: "2-digit"}); + else if (parts[3]==="R") time=Math.round((Date.now() - (Number.parseInt(parts[1]) * 1000))/1000/60) + " minutes ago"; + } + + const timeElem=document.createElement("span"); + timeElem.classList.add("markdown-timestamp"); + timeElem.textContent=time; + span.appendChild(timeElem); + continue; + } + } + current.textContent+=txt[i]; } appendcurrent(); diff --git a/webpage/style.css b/webpage/style.css index e8a90bb..5d86e19 100644 --- a/webpage/style.css +++ b/webpage/style.css @@ -312,6 +312,10 @@ div { transition: background .1s ease-in-out; } +.md-timestamp { + background-color: var(--markdown-timestamp); +} + #typebox { font-family: "acumin-pro", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; @@ -1241,4 +1245,4 @@ span { button{ background:green; } -} \ No newline at end of file +} diff --git a/webpage/themes.css b/webpage/themes.css index 6339378..4ae08cf 100644 --- a/webpage/themes.css +++ b/webpage/themes.css @@ -42,6 +42,7 @@ --scrollbar-track: #34313c; --scrollbar-thumb: #201f29; --scrollbar-thumb-hover: #16161f; + --markdown-timestamp: #2f2f33; --embed: #1a1823; } .WHITE-theme { @@ -84,6 +85,7 @@ --scrollbar-track: #d5d1e2; --scrollbar-thumb: #b0afc0; --scrollbar-thumb-hover: #a5a5b8; + --markdown-timestamp: #c8c8da; --embed: #f2f3f5; } .Light-theme { @@ -135,5 +137,6 @@ --scrollbar-track: #d2cedf; --scrollbar-thumb: #bdbcca; --scrollbar-thumb-hover: #a7a7be; + --markdown-timestamp: #c8c8da; --embed: #cdccd1; }