Kimi.com RTL

يمنع النص من الانتقال لسطر جديد بعد الرقم/النقطة في القوائم

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Kimi.com RTL
// @namespace    http://tampermonkey.net/
// @version      2.2
// @description  يمنع النص من الانتقال لسطر جديد بعد الرقم/النقطة في القوائم
// @author       أنت
// @match        https://www.kimi.com/*
// @match        http://www.kimi.com/*
// @grant        GM_addStyle
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // ========== 1. تطبيق dir="auto" على العناصر النصية (كما كان) ==========
    function applyDirAuto(element) {
        const textSelectors = [
            'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
            'td', 'th', 'blockquote', 'pre', 'code',
            'span', 'a', 'button', 'label', 'figcaption',
            'caption', 'address', 'dt', 'dd', 'legend',
            'optgroup', 'option', 'select', 'textarea',
            'input[type="text"]', 'input[type="search"]',
            'div:not(:has(> *))'
        ];
        const elements = element.querySelectorAll(textSelectors.join(','));
        elements.forEach(el => {
            if (!el.hasAttribute('dir')) {
                el.setAttribute('dir', 'auto');
            }
        });
    }
    applyDirAuto(document.body);

    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === 1) applyDirAuto(node);
            });
        });
    });
    observer.observe(document.body, { childList: true, subtree: true });

    // ========== 2. إصلاح القوائم (li) ومنع النص من النزول لسطر جديد ==========
    GM_addStyle(`
        li {
            direction: rtl !important;           /* الرقم في أقصى اليمين */
            text-align: right !important;         /* محاذاة النص لليمين */
            list-style-position: inside !important; /* الرقم داخل العنصر */
            padding: 0 !important;
            margin: 0 !important;
            white-space: normal !important;       /* السماح بالتفاف النص طبيعياً */
            display: list-item !important;        /* الحفاظ على السلوك الافتراضي */
        }

        /* ضبط padding للقوائم نفسها */
        ol, ul {
            padding-right: 1.5em !important;
            padding-left: 0 !important;
        }

        /* منع أي عنصر داخل li من أخذ سطر كامل (إجباره ليكون inline) */
        li > * {
            display: inline !important;            /* يجعل الأبناء المباشرين في نفس السطر */
            vertical-align: baseline !important;
        }

        /* معالجة عناصر معروفة قد تكون block ونريدها inline */
        li > div, li > p, li > h1, li > h2, li > h3, li > h4, li > h5, li > h6, li > blockquote {
            display: inline !important;
        }

        /* السماح للنص داخل الـ li باستخدام dir="auto" الذي طبقناه سابقاً */
        li * {
            direction: auto !important;
            unicode-bidi: normal !important;
        }

        /* ضبط الـ marker (الرقم/النقطة) ليكون متوافقاً مع RTL */
        li::marker {
            unicode-bidi: isolate;
            text-align: right;
        }
    `);

    // تأكيد أن li لها dir="rtl" بعد تطبيق dir="auto"
    function fixListItems() {
        document.querySelectorAll('li').forEach(li => {
            li.setAttribute('dir', 'rtl');
        });
    }
    setTimeout(fixListItems, 150);

    const listObserver = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === 1) {
                    if (node.matches && node.matches('li')) node.setAttribute('dir', 'rtl');
                    node.querySelectorAll && node.querySelectorAll('li').forEach(li => li.setAttribute('dir', 'rtl'));
                }
            });
        });
    });
    listObserver.observe(document.body, { childList: true, subtree: true });
})();