import { preferences } from "@/utils/storage"; export function forumMentions() { const textBlocks = document.querySelectorAll('p:not(.text-muted):not(.mb-0)'); const regex = /@([\w.]+)/g; textBlocks.forEach(text => { const walker = document.createTreeWalker(text, NodeFilter.SHOW_TEXT, null); let node; while ((node = walker.nextNode())) { const fragment = document.createDocumentFragment(); let lastIndex = 0; let match; while ((match = regex.exec(node.nodeValue!)) !== null) { const username = match[1]; const link = document.createElement('a'); link.href = `/u/${username}`; link.className = 'polyplus-mention'; link.textContent = match[0]; fragment.appendChild(document.createTextNode(node.nodeValue!.substring(lastIndex, match.index))); fragment.appendChild(link); lastIndex = match.index + match[0].length; } fragment.appendChild(document.createTextNode(node.nodeValue!.substring(lastIndex))); node.parentNode!.replaceChild(fragment, node); } }); }