字体替换

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

As of 2021-10-17. See the latest version.

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

const main = () => {
    const fonts = new Set();
    [...document.querySelectorAll('*')].forEach(node => {
        const nodeFontFamily = getComputedStyle(node).fontFamily
        if (nodeFontFamily.includes('mono')) { return }
        fonts.add(nodeFontFamily.split(',')[0])
    });
    const fontFaceCSS = [...fonts].map(font => `
        @font-face {
            font-family: ${font};
            src: local('Ubuntu');
        }`
    ).join('')
    GM_addStyle(fontFaceCSS)
}

main()
setInterval(main, 3000)