Google Docs Change Outline Arabic Font

Changes outline arabic font to Tajawal

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Google Docs Change Outline Arabic Font
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Changes outline arabic font to Tajawal
// @match        https://docs.google.com/document/*
// @license      MIT
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // 1) Load Tajawal
    GM_addStyle(`
        @import url("https://fonts.googleapis.com/css?family=Tajawal&display=swap");
    `);  // :contentReference[oaicite:0]{index=0}

    // 2) Font + size bump for anything Arabic
    function applyArabicFont(el) {
        if (/[\u0600-\u06FF]/.test(el.textContent)) {
            el.style.fontFamily = '"Tajawal", sans-serif';
            const cs = window.getComputedStyle(el);
            const size = parseFloat(cs.fontSize) || 0;
            el.style.fontSize = (size + 0) + 'px';
        }
    }

    // 3) Restyle all headings, tab-labels, and the header text
    function restyleAll() {
        document.querySelectorAll(
            '.outlines-widget-chaptered .navigation-item-content,' +
            '.outlines-widget-chaptered .chapter-label-content,' +
            '.kix-outlines-widget-header-text-chaptered'
        ).forEach(applyArabicFont);
    }
    restyleAll();

    // 4) Observe for newly inserted outline items or tabs
    const observer = new MutationObserver(mutations => {
        for (const m of mutations) {
            for (const n of m.addedNodes) {
                if (!(n instanceof Element)) continue;
                if (n.matches(
                    '.navigation-item-content,' +
                    '.chapter-label-content,' +
                    '.kix-outlines-widget-header-text-chaptered'
                )) {
                    applyArabicFont(n);
                }
                n.querySelectorAll &&
                    n.querySelectorAll('.navigation-item-content, .chapter-label-content')
                     .forEach(applyArabicFont);
            }
        }
    });
    observer.observe(document.body, { childList: true, subtree: true });
})();