修改 Safari 代码字体

Published Thu 17 January 2019 in 工具折腾

by HanXiao  

工具: 油猴插件

添加以下脚本:

// ==UserScript==
// @name         使用等宽字体
// @namespace    https://github.com/uldaman/
// @version      1.0.0
// @description  强制修改网页中代码部分为等宽字体!
// @author       HanXiao
// @include      *
// @exclude      *.seedr.cc*
// @exclude      *console.cloud.google.com/cloudshell*
// @run-at       document-start
// @grant        unsafeWindow
// ==/UserScript==

(function () {
    'use strict';
    let element = document.createElement("link");
    element.rel = "stylesheet";
    element.type = "text/css";
    element.href = 'data:text/css, pre, code {font-family: Menlo !important;}';
    document.documentElement.appendChild(element);
    setTimeout(function () {
        let modStyle = document.querySelector('#modCSS_font');
        if (modStyle === null) {
            modStyle = document.createElement('style');
            modStyle.id = 'modCSS_font';
            document.body.appendChild(modStyle);
        }
        modStyle.innerHTML = 'pre, code {font-family: Menlo !important;}';
    }, 300);
})();