mirror of
https://github.com/HUSSEIN-Syu/LLMs-RTL.git
synced 2026-11-03 12:19:41 +00:00
Support for RTL languages
This commit is contained in:
+9
-6
@@ -2,8 +2,8 @@
|
||||
// @name ChatGPT RTL
|
||||
// @namespace http://chat.openai.com
|
||||
// @author Alireza Farzaneh
|
||||
// @version 0.1.0
|
||||
// @description Changes the direction of Persian text on ChatGPT interface to RTL
|
||||
// @version 0.1.1
|
||||
// @description Fixes the direction of RTL languages in ChatGPT's interface
|
||||
// @match https://chat.openai.com/*
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
@@ -11,10 +11,13 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
const PERSIAN_REGEX = /[\u0600-\u06FF\uFB8A\u067E\u0686\u06AF\u200C\u200F]+/;
|
||||
const HEBREW_REGEX = /[\u0590-\u05FF\uFB1D-\uFB4F]+/;
|
||||
const ARABIC_REGEX = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDCF\uFDF0-\uFDFF\uFE70-\uFEFF]+/;
|
||||
const RTL_REGEX = new RegExp(PERSIAN_REGEX.source + '|' + HEBREW_REGEX.source + '|' + ARABIC_REGEX.source);
|
||||
|
||||
// Function to check if a given string contains Persian text
|
||||
function containsPersianText(text) {
|
||||
return PERSIAN_REGEX.test(text);
|
||||
// Function to check if a given string contains a text in any RTL language
|
||||
function containsRTLText(text) {
|
||||
return RTL_REGEX.test(text);
|
||||
}
|
||||
|
||||
// Function to modify a single text node
|
||||
@@ -27,7 +30,7 @@
|
||||
var childNodes = element.childNodes;
|
||||
for (var i = 0; i < childNodes.length; i++) {
|
||||
var childNode = childNodes[i];
|
||||
if (childNode.nodeType === Node.TEXT_NODE && containsPersianText(childNode.textContent)) {
|
||||
if (childNode.nodeType === Node.TEXT_NODE && containsRTLText(childNode.textContent)) {
|
||||
changeTextElementDirection(childNode);
|
||||
} else if (childNode.nodeType === Node.ELEMENT_NODE) {
|
||||
modifyPersianTextElements(childNode);
|
||||
|
||||
Reference in New Issue
Block a user