From b370510ecda6f8c7b7297f9343e1b3b1e32e29f9 Mon Sep 17 00:00:00 2001 From: Kibi Kelburton Date: Thu, 16 Jul 2026 21:16:32 +0200 Subject: [PATCH] comment preview foobar --- public/s/js/comments.js | 6 +++--- public/s/js/f0ckm.js | 14 +++++++++++++- public/s/js/messages.js | 15 +++++++++++---- public/s/js/sidebar-activity.js | 15 +++++++++++---- public/s/js/user_comments.js | 15 +++++++++++---- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/public/s/js/comments.js b/public/s/js/comments.js index f4c1a85..641ba63 100644 --- a/public/s/js/comments.js +++ b/public/s/js/comments.js @@ -1750,7 +1750,7 @@ class CommentSystem { const imageRegex = new RegExp(`(? { @@ -1779,8 +1779,8 @@ class CommentSystem { // Handle Mentions — use placeholders so the markdown escape pass (step 3) // never corrupts usernames that contain underscores or dots. const mentionStore = []; - processedLine = processedLine.replace(mentionRegex, (match, g1, g2) => { - const user = g1 || g2; + processedLine = processedLine.replace(mentionRegex, (match, g1, g2, g3, g4) => { + const user = g1 || g2 || g4; const html = `@${user}`; const idx = mentionStore.length; mentionStore.push(html); diff --git a/public/s/js/f0ckm.js b/public/s/js/f0ckm.js index 24fe95f..9d214e3 100644 --- a/public/s/js/f0ckm.js +++ b/public/s/js/f0ckm.js @@ -8507,9 +8507,18 @@ class NotificationSystem { }; // Pre-process mentions before marked (skip greentext lines) + const mentionStore = []; + const mentionRegex = /(? { if (line.trimStart().startsWith('>')) return line; - return line.replace(/(? { + const user = g1 || g2 || g4; + const html = `@${user}`; + const idx = mentionStore.length; + mentionStore.push(html); + return `\x02MNT${idx}\x03`; + }); }).join('\n'); content = marked.parse(safe, { @@ -8517,6 +8526,9 @@ class NotificationSystem { breaks: true, renderer: renderer }); + + // Restore mention placeholders + content = content.replace(/\x02MNT(\d+)\x03/g, (_, i) => mentionStore[+i]); } catch (e) { console.error('Marked error in w0bm.js', e); // Fallback diff --git a/public/s/js/messages.js b/public/s/js/messages.js index b2b3ac1..47be836 100644 --- a/public/s/js/messages.js +++ b/public/s/js/messages.js @@ -640,7 +640,7 @@ if (window.__dmLoaded) { let escaped = escHtml(normalized).replace(/>/g, ">"); // 3. Mentions - const mentionRegex = /(? 10000) return line; if (!line.trim()) return ' '; - let processedLine = line.replace(mentionRegex, (match, g1, g2) => { - const user = g1 || g2; - return `@${user}`; + const mentionStore = []; + let processedLine = line.replace(mentionRegex, (match, g1, g2, g3, g4) => { + const user = g1 || g2 || g4; + const html = `@${user}`; + const idx = mentionStore.length; + mentionStore.push(html); + return `\x02MNT${idx}\x03`; }); const escapedSiteHost = window.location.host.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); @@ -735,6 +739,9 @@ if (window.__dmLoaded) { const escapedAsterisks = processedLine.replace(/\*/g, '\\*'); let rendered = marked.parseInline ? marked.parseInline(escapedAsterisks, { renderer: renderer }) : marked.parse(escapedAsterisks, { renderer: renderer }).replace(/

|<\/p>/g, ''); + // Restore Mentions + rendered = rendered.replace(/\x02MNT(\d+)\x03/g, (_, i) => mentionStore[+i]); + return rendered; }); diff --git a/public/s/js/sidebar-activity.js b/public/s/js/sidebar-activity.js index c7fec29..2fe7923 100644 --- a/public/s/js/sidebar-activity.js +++ b/public/s/js/sidebar-activity.js @@ -154,7 +154,7 @@ const domainOrRelative = `(?:(?:https?:\\/\\/|\\/\\/)?(?:${hostsRegexPart})|(?:(? { - const user = g1 || g2; - return `@${user}`; + const mentionStore = []; + processedLine = processedLine.replace(mentionRegex, (match, g1, g2, g3, g4) => { + const user = g1 || g2 || g4; + const html = `@${user}`; + const idx = mentionStore.length; + mentionStore.push(html); + return `\x02MNT${idx}\x03`; }); // Handle Comment Context Links (>>ID) @@ -294,6 +298,9 @@ let rendered = marked.parseInline ? marked.parseInline(mdSafe, { renderer: renderer }) : marked.parse(mdSafe, { renderer: renderer }).replace(/

|<\/p>/g, ''); + // Restore Mentions + rendered = rendered.replace(/\x02MNT(\d+)\x03/g, (_, i) => mentionStore[+i]); + // Render emojis ONLY if this is NOT a quote line OR if the user prefers it const quoteEmojis = window.f0ckSession?.quote_emojis === true; if (!trimmed.startsWith('>') || quoteEmojis) { diff --git a/public/s/js/user_comments.js b/public/s/js/user_comments.js index 8758c13..63b2c9a 100644 --- a/public/s/js/user_comments.js +++ b/public/s/js/user_comments.js @@ -221,7 +221,7 @@ if (!window.UserCommentSystem) { let escaped = this.escapeHtml(content).replace(/>/g, ">"); // 2. Mentions - const mentionRegex = /(? { - const user = g1 || g2; - return `@${user}`; + const mentionStore = []; + processedLine = processedLine.replace(mentionRegex, (match, g1, g2, g3, g4) => { + const user = g1 || g2 || g4; + const html = `@${user}`; + const idx = mentionStore.length; + mentionStore.push(html); + return `\x02MNT${idx}\x03`; }); // Handle Comment Context Links (>>ID) @@ -337,6 +341,9 @@ if (!window.UserCommentSystem) { const escapedAsterisks = processedLine.replace(/\*/g, '\\*'); let rendered = marked.parseInline ? marked.parseInline(escapedAsterisks, { renderer: renderer }) : marked.parse(escapedAsterisks, { renderer: renderer }).replace(/

|<\/p>/g, ''); + // Restore Mentions + rendered = rendered.replace(/\x02MNT(\d+)\x03/g, (_, i) => mentionStore[+i]); + // Render emojis ONLY if this is NOT a quote line OR if the user prefers it const quoteEmojis = window.f0ckSession?.quote_emojis === true; if (!trimmed.startsWith('>') || quoteEmojis) {