Greasy Fork

Greasy Fork is available in English.

字体替换

字体替换,默认为Ubuntu,可自行修改,略过等宽字体

当前为 2021-03-11 提交的版本,查看 最新版本

// ==UserScript==
// @name         字体替换
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  字体替换,默认为Ubuntu,可自行修改,略过等宽字体
// @match        *://*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const replaceFont = ele => {
        if (!window.getComputedStyle(ele).fontFamily.toLowerCase().includes('mono')
            && window.getComputedStyle(ele, ':before').content === 'none'
            && window.getComputedStyle(ele, ':after').content === 'none') {
            ele.style.fontFamily = 'Ubuntu'
        }
    }

    [...document.querySelectorAll('h1, h2, h3, h4, h5, h6, div, li, ol, p, ul, a, span, td, th, button, input, label, option, select')].map(ele => replaceFont(ele))

    new MutationObserver(records => records.map(record => replaceFont(record.target)))
        .observe(document.documentElement, {
            'subtree': true,
            'characterData': true,
        })
})();