fix: forum mentions feature breaking emojis
This commit is contained in:
parent
fd55054ac6
commit
4013251a8e
1 changed files with 18 additions and 11 deletions
|
|
@ -20,13 +20,21 @@ function ForumMentions() {
|
||||||
const Regex = /@([\w.]+)/g;
|
const Regex = /@([\w.]+)/g;
|
||||||
|
|
||||||
for (let text of ForumText) {
|
for (let text of ForumText) {
|
||||||
let FormattedText = text.innerHTML;
|
const TreeWalker = document.createTreeWalker(text, NodeFilter.SHOW_TEXT, null, false);
|
||||||
let match;
|
let Node;
|
||||||
while ((match = Regex.exec(text.innerText)) !== null) {
|
|
||||||
const Username = match[0].substring(1);
|
while ((Node = TreeWalker.nextNode())) {
|
||||||
FormattedText = FormattedText.replaceAll(match[0], `<a href="/u/${Username}" class="polyplus-mention">${match[0]}</a>`);
|
let Match;
|
||||||
|
let Replacement = Node.nodeValue;
|
||||||
|
|
||||||
|
while ((Match = Regex.exec(Node.nodeValue)) !== null) {
|
||||||
|
const Username = Match[0].substring(1);
|
||||||
|
const Mention = `<a href="/u/${Username}" class="polyplus-mention">${Match[0]}</a>`;
|
||||||
|
Replacement = replacedText.replace(Match[0], Mention);
|
||||||
|
}
|
||||||
|
|
||||||
|
Node.nodeValue = replacedText;
|
||||||
}
|
}
|
||||||
text.innerHTML = FormattedText;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,7 +52,6 @@ function ForumUnixTimestamps() {
|
||||||
const Distance = new Intl.RelativeTimeFormat({numeric: 'auto', style: 'short'}).format(Math.floor((Timestamp - new Date()) / (60 * 1000)), 'day');
|
const Distance = new Intl.RelativeTimeFormat({numeric: 'auto', style: 'short'}).format(Math.floor((Timestamp - new Date()) / (60 * 1000)), 'day');
|
||||||
const Result = `<code style="color: orange;">${Months[Timestamp.getMonth()]} ${Timestamp.getDate()}, ${Timestamp.getFullYear()} (${['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'][Timestamp.getDay() - 1]}) at ${Timestamp.getHours() - 12}:${String(Timestamp.getMinutes()).padStart(2, '0')} (${Distance})</code>`;
|
const Result = `<code style="color: orange;">${Months[Timestamp.getMonth()]} ${Timestamp.getDate()}, ${Timestamp.getFullYear()} (${['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'][Timestamp.getDay() - 1]}) at ${Timestamp.getHours() - 12}:${String(Timestamp.getMinutes()).padStart(2, '0')} (${Distance})</code>`;
|
||||||
FormattedText = FormattedText.replaceAll(match[0], Result);
|
FormattedText = FormattedText.replaceAll(match[0], Result);
|
||||||
console.log(FormattedText);
|
|
||||||
}
|
}
|
||||||
text.innerHTML = FormattedText;
|
text.innerHTML = FormattedText;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue