Kimi.com RTL

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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