From f98ae446d14706c2fd106a3ec4d80d7c63d82a42 Mon Sep 17 00:00:00 2001 From: HUSSEIN Date: Thu, 25 Sep 2025 19:07:30 +0330 Subject: [PATCH] Update Chatgpt-RTL.user.js --- Chatgpt-RTL.user.js | 134 +++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 71 deletions(-) diff --git a/Chatgpt-RTL.user.js b/Chatgpt-RTL.user.js index cce07c9..1058c83 100644 --- a/Chatgpt-RTL.user.js +++ b/Chatgpt-RTL.user.js @@ -1,91 +1,83 @@ // ==UserScript== // @name ChatGPT RTL // @namespace http://chat.openai.com +// @namespace http://deepseek.com // @author Alireza Farzaneh -// @version 0.1.2 -// @description Fixes the direction of RTL languages in ChatGPT's interface +// @version 0.1.2.1 +// @description Fixes the direction of RTL languages in LLM's interface // @match https://chat.openai.com/* // @match https://chatgpt.com/* +// @match https://chat.deepseek.com/* +// @match https://claude.ai/* +// @match https://chat.qwen.ai/* // @grant none // ==/UserScript== ;(function() { "use strict"; - - var PERSIAN_REGEX = /[\u0600-\u06FF]/; - var HEBREW_REGEX = /[\u0590-\u05FF]/; - var ARABIC_REGEX = /[\u0600-\u06FF]/; - var RTL_REGEX = new RegExp([PERSIAN_REGEX.source, HEBREW_REGEX.source, ARABIC_REGEX.source].join("|")); + const RTL_REGEX = /[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/; - function containsRTLText(text) { - return RTL_REGEX.test(text); + const styleId = 'deepseek-rtl-fix-style'; + if (!document.getElementById(styleId)) { + const style = document.createElement('style'); + style.id = styleId; + style.textContent = ` + .deepseek-rtl-applied, .deepseek-rtl-applied * { + direction: rtl !important; + text-align: right !important; + } + `; + document.head.appendChild(style); } - function changeTextElementDirection(element) { - if (element.parentNode) { - const parentElement = element.parentNode; - parentElement.setAttribute('dir', 'rtl'); - parentElement.style.cssText += 'text-align: right !important; direction: rtl !important;'; - - // Apply to parent containers to ensure proper alignment - let currentElement = parentElement; - while (currentElement && currentElement !== document.body) { - if (currentElement.classList.contains('markdown-content') || - currentElement.classList.contains('text-message') || - /^H[1-6]$/.test(currentElement.tagName)) { - currentElement.style.cssText += 'text-align: right !important; direction: rtl !important;'; + function applyRTLToNode(node) { + if (!node) return; + let elem = null; + if (node.nodeType === Node.TEXT_NODE) { + elem = node.parentElement; + } else if (node.nodeType === Node.ELEMENT_NODE) { + elem = node; + } + if (!elem) return; + + if (elem.closest('.deepseek-rtl-applied')) return; + + const txt = elem.textContent || ""; + if (RTL_REGEX.test(txt)) { + elem.classList.add('deepseek-rtl-applied'); + } + } + + function initialScan(root) { + if (!root) root = document.body; + const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null, false); + let cur; + while ((cur = walker.nextNode())) { + applyRTLToNode(cur); + } + } + + initialScan(document.body); + + const observer = new MutationObserver((mutations) => { + for (const mut of mutations) { + if (mut.type === 'childList') { + for (const nd of mut.addedNodes) { + applyRTLToNode(nd); + if (nd.nodeType === Node.ELEMENT_NODE) { + initialScan(nd); + } } - currentElement = currentElement.parentElement; + } else if (mut.type === 'characterData') { + applyRTLToNode(mut.target); } } - } + }); - function isAlreadyModified(element) { - return element.parentNode.getAttribute('dir') === 'rtl'; - } + observer.observe(document.body, { + childList: true, + subtree: true, + characterData: true + }); - function modifyPersianTextElements(element) { - if (element === document.body) { - const style = document.createElement('style'); - style.textContent = ` - .markdown-content, .text-message, - .markdown-content h1, .markdown-content h2, - .markdown-content h3, .markdown-content h4, - .markdown-content h5, .markdown-content h6, - .markdown-content p, .markdown-content div, - [dir="rtl"] { - text-align: right !important; - direction: rtl !important; - } - `; - document.head.appendChild(style); - } - - var childNodes = element.childNodes; - for (var i = 0; i < childNodes.length; i++) { - var childNode = childNodes[i]; - if (childNode.nodeType === Node.TEXT_NODE) { - if (isAlreadyModified(childNode)) { - continue; - } - if (containsRTLText(childNode.textContent)) { - changeTextElementDirection(childNode); - } - } else if (childNode.nodeType === Node.ELEMENT_NODE) { - modifyPersianTextElements(childNode); - } - } - } - - function handleMutations(mutationsList) { - for (let i = 0; i < mutationsList.length; i++) { - const mutation = mutationsList[i]; - modifyPersianTextElements(mutation.target.parentNode); - } - }; - - modifyPersianTextElements(document.body); - - var observer = new MutationObserver(handleMutations); - observer.observe(document.body, { childList: true, subtree: true, attributes: true, characterData: true }); })();