更改默认的github代码字体

时间:2011-09-10 14:07:58

标签: github

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

5 个答案:

答案 0 :(得分:7)

答案 1 :(得分:4)

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

答案 2 :(得分:2)

如果您使用兼容的浏览器,您可以使用greasemonkey脚本来定位github.com上的代码块,并使用monaco而不是courier new来呈现它们。

答案 3 :(得分:0)

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

// ==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 + '; } ' +
  '');

答案 4 :(得分:0)

我也对 GitHub 代码字体不满意,我决定构建一个 Chrome 扩展程序,允许更改和自定义 GitHub 代码查看器字体,但是此时的扩展程序提供了一些您可以选择的字体,但是以后我会添加更多。

您可以在此 GitHub repo 中找到此扩展程序。

相关问题