您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
指定网页的 UI 字体和代码字体,忽略图标
// ==UserScript== // @name 钦定字体 // @description 指定网页的 UI 字体和代码字体,忽略图标 // @license MIT // @namespace http://tampermonkey.net/ // @version 0.5 // @author chenh // @match *://*/* // @grant GM_addStyle // @run-at document-start // ==/UserScript== ;(() => { 'use strict' // UI 字体 const UI_FONT = 'Microsoft YaHei UI' // 代码字体 const CODE_FONT = 'Sarasa Mono SC' // 忽略项,用于忽略字体图标 const GLOBAL_IGNORES = [ 'i', '[class*=ifont]', '[class*=ifont] *', '[class*=vjs]', '[class*=vjs] *', '[class*=icon]', '[class*=icon] *', '[class*=photo]', '[class*=photo] *', '[class*=image]', '[class*=image] *', '[class*=picture]', '[class*=picture] *', ] // UI 选择器 const UI_SELECTORS = ['*'] // 代码选择器 const CODE_SELECTORS = [ 'pre', 'pre *', 'code', 'code *', '[id*=highlighted]', '[id*=highlighted] *', '[class*=highlighted]', '[class*=highlighted] *', ] /** * 将选择器和忽略结合成选择器 * @param {string[]} selectors 普通选择器 * @param {string[]} ignores 忽略项选择器 * @returns {string} 选择器字符串 */ function buildIgnoreStyle(selectors, ignores) { return selectors.map(sel => `${sel}:not(${ignores.join(', ')})`).join(', ') } // 设置 CSS GM_addStyle(` ${buildIgnoreStyle(UI_SELECTORS, [...CODE_SELECTORS, ...GLOBAL_IGNORES])} { font-family: '${UI_FONT}' !important; } ${buildIgnoreStyle(CODE_SELECTORS, GLOBAL_IGNORES)} { font-family: '${CODE_FONT}' !important; } `) })()