Greasy Fork is available in English.

字体替换

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

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

const fonts = new Set()
const main = () => {
    let fontFaceCSS = '';
    document.querySelectorAll('*').forEach(node => {
        let nodeFont = getComputedStyle(node).fontFamily
        if (nodeFont.includes('mono')) { return }
        nodeFont = nodeFont.split(',')[0]
        if (fonts.has(nodeFont)) { return }
        fonts.add(nodeFont)
        fontFaceCSS += `
        @font-face {
            font-family: ${nodeFont};
            src: local('Ubuntu');
        }`
    })
    if (!fontFaceCSS.length) { return }
    GM_addStyle(fontFaceCSS)
    console.log('font replace done')
}
 
main()
setInterval(main, 3000)