mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-15 17:25:26 -04:00
Respect text-only emoji setting after svgification
Follow-up to #271. Skip svgifyEmoji when body.text-emojis is set so deEmojify can strip Unicode from replies; also unwrap existing .emoji spans from messages rendered before the setting was applied. Related to #270
This commit is contained in:
+10
-1
@@ -2553,14 +2553,23 @@ function initializeEventListeners() {
|
||||
});
|
||||
}
|
||||
|
||||
const _DEOJ_SKIP = '.sources-section, .thinking-toggle, .memory-used-pill';
|
||||
|
||||
/** Walk all text nodes inside an element and replace emojis with text descriptions */
|
||||
function deEmojify(root) {
|
||||
if (!root || !root.querySelectorAll) return;
|
||||
// Monochrome SVG spans from svgifyEmoji — Unicode lives in aria-label only
|
||||
root.querySelectorAll('.emoji[aria-label]').forEach((span) => {
|
||||
if (span.closest(_DEOJ_SKIP)) return;
|
||||
const label = span.getAttribute('aria-label') || '';
|
||||
span.replaceWith(document.createTextNode(emojiToText(label)));
|
||||
});
|
||||
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
||||
const nodes = [];
|
||||
while (walker.nextNode()) nodes.push(walker.currentNode);
|
||||
for (const node of nodes) {
|
||||
// Skip UI elements that use unicode symbols as functional icons
|
||||
if (node.parentElement && node.parentElement.closest('.sources-section, .thinking-toggle, .memory-used-pill')) continue;
|
||||
if (node.parentElement && node.parentElement.closest(_DEOJ_SKIP)) continue;
|
||||
if (EMOJI_RE.test(node.textContent)) {
|
||||
EMOJI_RE.lastIndex = 0; // reset regex state
|
||||
node.textContent = emojiToText(node.textContent);
|
||||
|
||||
Reference in New Issue
Block a user