feat: hide image links from messages and improve overall handling of links

This commit is contained in:
ffqq 2023-07-13 03:22:47 +00:00
parent 69d6020865
commit 7b1e636187
1 changed files with 2 additions and 2 deletions

View File

@ -20,8 +20,8 @@ async function updateMessages(id) {
const timeParagraph = document.createElement("p"); const timeParagraph = document.createElement("p");
const { creator, content, id, created } = message; const { creator, content, id, created } = message;
// Check if the message content contains any links that are not image links // Check if the message content contains any links that are not image links and hide image links
const linkRegex = /(https?:\/\/[^\s]+(?<!\.(?:png|apng|webp|svg|jpg|jpeg|gif)))/gi; const linkRegex = /(https?:\/\/[^\s]+(?<!\.(?:png|apng|webp|svg|jpg|jpeg|gif)))(?=\s|$)|(?<=\s|^)(https?:\/\/(?:cdn\.discordapp\.com|media\.discordapp\.net|media\.tenor\.com|i\.imgur\.com|burger\.ctaposter\.xyz)\/.+?\.(?:png|apng|webp|svg|jpg|jpeg|gif))(?=$|\s)/gi;
let messageContent = content.replace(linkRegex, "<a href='$1' target='_blank'>$1</a>"); let messageContent = content.replace(linkRegex, "<a href='$1' target='_blank'>$1</a>");
messageParagraph.innerHTML = `${creator.username}: ${messageContent}`; messageParagraph.innerHTML = `${creator.username}: ${messageContent}`;