fix: wrap links inside of <a> for convenience

This commit is contained in:
ffqq 2023-07-13 02:50:16 +00:00
parent 48321233c3
commit df75e02efc
1 changed files with 5 additions and 1 deletions

View File

@ -20,7 +20,11 @@ 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;
messageParagraph.appendChild(document.createTextNode(`${creator.username}: ${content}`)); // Check if the message content contains any links that are not image links
const linkRegex = /(https?:\/\/[^\s]+(?<!\.(?:png|apng|webp|svg|jpg|jpeg|gif)))/gi;
let messageContent = content.replace(linkRegex, "<a href='$1' target='_blank'>$1</a>");
messageParagraph.innerHTML = `${creator.username}: ${messageContent}`;
messageParagraph.classList.add("messageParagraph"); messageParagraph.classList.add("messageParagraph");
messageParagraph.id = `messageParagraph${id}`; messageParagraph.id = `messageParagraph${id}`;
messageParagraph.appendChild(timeParagraph); messageParagraph.appendChild(timeParagraph);