diff --git a/web/plugin.head.html b/web/plugin.head.html index 0dc25de..9828b74 100644 --- a/web/plugin.head.html +++ b/web/plugin.head.html @@ -351,6 +351,8 @@ html:not(.politictalk-direct-access-blocked) .politictalk-chat-recipient-control, html:not(.politictalk-direct-access-blocked) .politictalk-chat-recipient-control *, + html:not(.politictalk-direct-access-blocked) [data-politictalk-chat-recipient], + html:not(.politictalk-direct-access-blocked) [data-politictalk-chat-recipient] *, html:not(.politictalk-direct-access-blocked) #chat-recipient-selector, html:not(.politictalk-direct-access-blocked) #chat-recipient-selector *, html:not(.politictalk-direct-access-blocked) [data-testid*="recipient" i], @@ -839,6 +841,67 @@ || label.indexOf('الجميع') !== -1; } + function markChatRecipientElement(element) { + if (!element || element.nodeType !== 1) { + return; + } + + element.classList.add('politictalk-chat-recipient-control'); + element.setAttribute('data-politictalk-chat-recipient', 'true'); + + var icons = element.querySelectorAll('svg, path'); + + icons.forEach(function(icon) { + icon.style.color = '#ffffff'; + icon.style.fill = 'currentColor'; + icon.style.stroke = 'currentColor'; + }); + } + + function markChatRecipientTextNode(textNode) { + var element = textNode && textNode.parentElement; + var depth = 0; + + while (element && depth < 5) { + var text = (element.textContent || '').replace(/\s+/g, ' ').trim(); + + if (text.length > 0 && text.length <= 60 && isChatRecipientControl(element)) { + markChatRecipientElement(element); + } + + element = element.parentElement; + depth += 1; + } + } + + function markChatRecipientLabels() { + var roots = document.querySelectorAll('#sideToolbarContainer, .sideToolbarContainer, .chat-panel, .chat-panel-container, .chat-container, [class*="chatPanel"]'); + + roots.forEach(function(root) { + var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, { + acceptNode: function(node) { + var text = (node.nodeValue || '').replace(/\s+/g, ' ').trim().toLowerCase(); + + if (!text || text.length > 60) { + return NodeFilter.FILTER_REJECT; + } + + return text.indexOf('everyone') !== -1 + || text.indexOf('alle') !== -1 + || text.indexOf('الجميع') !== -1 + ? NodeFilter.FILTER_ACCEPT + : NodeFilter.FILTER_REJECT; + } + }); + var node = walker.nextNode(); + + while (node) { + markChatRecipientTextNode(node); + node = walker.nextNode(); + } + }); + } + function markChatRecipientControls() { if (!document.body) { return; @@ -851,8 +914,10 @@ return; } - control.classList.add('politictalk-chat-recipient-control'); + markChatRecipientElement(control); }); + + markChatRecipientLabels(); } function mountChatRecipientStyling() {