Force Microsoft YaHei Font (No-Flash Safe)

无闪烁强制微软雅黑,安全排除图标/公式/控件,站点/页面级排除在脚本头完成

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Force Microsoft YaHei Font (No-Flash Safe)
// @namespace    https://tampermonkey.net/
// @version      1.2.1
// @description  无闪烁强制微软雅黑,安全排除图标/公式/控件,站点/页面级排除在脚本头完成
// @match        *://*/*

// ===== 站点 / 页面排除 =====
// @exclude-match  *://www.google.com/*
// @exclude-match  *://accounts.google.com/*
// @exclude-match  *://docs.google.com/*
// @exclude-match  *://example.com/special/page

// ===== 运行时机 =====
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const FONT_FALLBACK = [
        '"Microsoft YaHei"',
        '"微软雅黑"',
        '"PingFang SC"',
        'system-ui',
        'sans-serif'
    ].join(',');

    const EXCLUDE_SELECTORS = `
        code, pre, kbd, samp, tt,
        input, textarea, select, option, button,
        [role="button"], [type="button"], [type="submit"], [type="reset"],

        i, i[class],
        svg, svg *, canvas,
        [class*="icon"], [class^="icon-"], [class*="glyph"],
        [class^="fa"], .fa, .fas, .far, .fab, .fal, .fad,
        .material-icons, .material-symbols-outlined,
        .material-symbols-rounded, .material-symbols-sharp,
        .iconfont, [class*="iconfont"],

        math, mjx-container, .MathJax,
        .katex, .katex *,

        .monaco-editor, .monaco-editor *,
        .CodeMirror, .CodeMirror *,
        .ace_editor, .ace_editor *,

        nav, nav *, menu, menu *,
        [role="menu"], [role="menuitem"],
        [role="toolbar"], [role="tab"], [role="tabpanel"],

        progress, meter, summary, details,
        [draggable="true"],
        [aria-hidden="true"]
    `.replace(/\s+/g, ' ');

    const style = document.createElement('style');
    style.id = 'tm-force-yahei-font';
    style.textContent = `
        html, body {
            font-family: ${FONT_FALLBACK} !important;
        }
        body *:not(${EXCLUDE_SELECTORS}) {
            font-family: ${FONT_FALLBACK} !important;
        }
    `;

    document.documentElement.appendChild(style);
})();