Kimi.com RTL

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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 });
})();