更纱黑体字体替换工具

将字体替换为更纱黑体(中日韩)和对应的等宽字体。

目前为 2024-05-18 提交的版本。查看 最新版本

// ==UserScript==
// @name                 Sarasa-Gothic-Font-Substitution-Tool
// @name:en-US           Sarasa Gothic Font Substitution Tool
// @name:zh-CN           更纱黑体字体替换工具
// @name:zh-TW           更紗黑體字型替換工具
// @name:zh-HK           更紗黑體字型替換工具
// @name:ja-JP           更紗ゴシックフォント置換ツール
// @name:ko-KR           사라사고딕 폰트 대체 도구
// @namespace            https://gist.github.com/zozovo/8a76915acf197a873304dd23f2cfd49c
// @version              8.0
// @author               zozovo
// @description          Replace the font with Sarasa Gothic (CJK) and the corresponding monospaced one.
// @description:en-US    Replace the font with Sarasa Gothic (CJK) and the corresponding monospaced one.
// @description:zh-CN    将字体替换为更纱黑体(中日韩)和对应的等宽字体。
// @description:zh-TW    將字體替換為更紗黑體(中日韓)和對應的等寬字體。
// @description:zh-HK    將字體替換為更紗黑體(中日韓)和對應的等寬字體。
// @description:ja-JP    フォントを更紗ゴシック(中日韓)および対応する等幅フォントに置き換えます。
// @description:ko-KR    글꼴을사라사고딕(중일한)및해당등폭글꼴로대체합니다.
// @match                *://*/*
// @run-at               document-start
// @grant                GM_addStyle
// @license              MIT
// @supportURL           https://gist.github.com/zozovo/8a76915acf197a873304dd23f2cfd49c
// ==/UserScript==

const LANG_CODE_OBJ = {
    "zh-CN": "SC",
    "zh-SG": "SC",
    "zh-TW": "TC",
    "zh-HK": "HC",
    "ja": "J",
    "ko": "K",
    "ko-KR": "K",
    "ko-KP": "K",
};

const lang_code = LANG_CODE_OBJ[navigator.language] || "SC"; // Default to SC if not found

const EMOJIS_UNICODE_RANGE = // Unicode CLDR: check https://unicode.org/emoji/charts/emoji-style.txt
    // "U+00A9, U+00AE" + // BMP: Latin-1 Supplement: copyright and registered
    "U+200C, U+200D, U+203C, U+2049, " + // BMP: General Punctuation: ZWNJ and ZWJ, double exclamation mark, exclamation question mark
    "U+20E3, " + // BMP: Combining Diacritical Marks for Symbols: combining enclosing keycap
    // "U+2122, U+2139, " + // BMP: Letterlike Symbols: trade mark, information
    "U+2190-21FF, " + // BMP: Arrows
    "U+23??, " + // BMP: Miscellaneous Technical
    "U+24C2, " + // BMP: Enclosed Alphanumerics: circled M
    "U+25A0-27BF, " + // BMP: Geometric Shapes, Miscellaneous Symbols, Dingbats
    "U+2B??, " + // BMP: Miscellaneous Symbols and Arrows
    "U+2934, U+2935, " + // BMP: Supplemental Arrows-B: right arrow curving up, right arrow curving down
    "U+3030, U+303D, " + // BMP: CJK Symbols and Punctuation: wavy dash, part alternation mark
    "U+3297, U+3299, " + // BMP: Enclosed CJK Letters and Months: Japanese “congratulations” button, Japanese “secret” button
    "U+FE0E, U+FE0F, " + // BMP: Variation Selectors: VS15, VS16
    "U+1F???"; // SMP

GM_addStyle(`
@font-face {
    font-family: "Color Emoji";
    src: local("Apple Color Emoji"), local("Noto Color Emoji"), local("Segoe UI Emoji");
    unicode-range: ${EMOJIS_UNICODE_RANGE};
}

@font-face {
    font-family: "Monochrome Emoji";
    src: local("Apple Monochrome Emoji"), local("Noto Emoji"), local("Segoe Fluent Icons"), local("Segoe MDL2 Assets");
    unicode-range: ${EMOJIS_UNICODE_RANGE};
}

@font-face {
    font-family: "Consolas";
    src: local("Sarasa Fixed ${lang_code}")
}

@font-face {
    font-family: "Courier New";
    src: local("Sarasa Fixed ${lang_code}")
}

:root {
    --icon-font-family: "Color Emoji", "Monochrome Emoji";
    --normal-font-family: "Sarasa UI ${lang_code}";
    --code-font-family: "Sarasa Fixed ${lang_code}";
}

:is([lang$="TW"], [lang$="Hant"]) {
    --normal-font-family: "Sarasa UI TC";
    --code-font-family: "Sarasa Fixed TC";
}

:is([lang$="HK"], [lang$="MO"]) {
    --normal-font-family: "Sarasa UI HC";
    --code-font-family: "Sarasa Fixed HC";
}

:lang(ja) {
    --normal-font-family: "Sarasa UI J";
    --code-font-family: "Sarasa Fixed J";
}

:lang(ko) {
    --normal-font-family: "Sarasa UI K";
    --code-font-family: "Sarasa Fixed K";
}

:not(#_#_) :not([class*="fa-"], [class*="icon"]):not([aria-hidden="true"] *, [role="presentation"] *, [role="none"] *) {
    &:not(a:hover, i, s, span, textarea):not([aria-hidden="true"], [role="presentation"], [role="none"]) {
        font-family: var(--icon-font-family), var(--normal-font-family), system-ui;

        &:where(code, kbd, pre, samp, var),
        &:where([class*="ace_editor"], [class*="cm-editor"], [class*="monaco-editor"]) {
            font-family: var(--icon-font-family), var(--code-font-family), monospace;

            & :not(a, i, span) {
                font-family: var(--icon-font-family), var(--code-font-family), monospace;
            }
        }
        &:where([class*="code"]:not(#readme, .readme)) {
            font-family: var(--icon-font-family), var(--code-font-family), monospace;
        }
    }
}
`);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址