Kimi.com RTL

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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 });
})();