Merge pull request #23 from DEVTomatoCake/jank/markdown-timestamps
markdown timestamps
This commit is contained in:
commit
cd82bd6c26
3 changed files with 49 additions and 0 deletions
|
@ -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(/^<t:([0-9]{1,16})(:([tTdDfFR]))?>$/);
|
||||
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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
--scrollbar-track: #34313c;
|
||||
--scrollbar-thumb: #201f29;
|
||||
--scrollbar-thumb-hover: #16161f;
|
||||
--markdown-timestamp: #2f2f33;
|
||||
--embed: #1a1823;
|
||||
--discovery-bg: #37373b;
|
||||
}
|
||||
|
@ -85,6 +86,7 @@
|
|||
--scrollbar-track: #d5d1e2;
|
||||
--scrollbar-thumb: #b0afc0;
|
||||
--scrollbar-thumb-hover: #a5a5b8;
|
||||
--markdown-timestamp: #c8c8da;
|
||||
--embed: #f2f3f5;
|
||||
--discovery-bg: #c6c6d8;
|
||||
}
|
||||
|
@ -137,6 +139,7 @@
|
|||
--scrollbar-track: #d2cedf;
|
||||
--scrollbar-thumb: #bdbcca;
|
||||
--scrollbar-thumb-hover: #a7a7be;
|
||||
--markdown-timestamp: #c8c8da;
|
||||
--embed: #cdccd1;
|
||||
--discovery-bg: #c6c6d8;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue