更改默认的github代码字体

mis*_*tor 13 github

我对github的默认代码字体Courier New感到不满意.我想将它更改为Monaco,这是我首选的等宽字体.是否可以更改我的github代码字体?如果有,怎么样?

spi*_*ike 5

没有 Github 设置可以执行此操作,您必须考虑编写自己的自定义样式表。这将是特定于浏览器的,您必须手动在所有计算机上同步它,所以它并不理想。


dmc*_*dor 5

我在 Firefox 上也遇到同样的问题,所以这是我正在使用的 Greasemonkey 的用户脚本。只需将其粘贴到脚本编辑器窗口中即可。

// ==UserScript==
// @name        Github font changer
// @namespace   local.greasemonkey.githubfontchanger
// @include     https://github.com/*
// @version     1
// @grant       none
// ==/UserScript==

var fontdef ="Monaco, Monospace ! important"; // Set your font here.

// Function helper to inject css
function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

// Apply the font-family definition to code styles.
addGlobalStyle(
  '.blob-code { font-family: ' + fontdef + '; } ' +
  '.blob-num { font-family: ' + fontdef + '; } ' +
  '');
Run Code Online (Sandbox Code Playgroud)