-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.user.js
87 lines (71 loc) · 2.32 KB
/
script.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// ==UserScript==
// @name JetBrainsMono4GitHub
// @namespace https://userscript.clazex.net/
// @version 2.1.1
// @description Change GitHub code view font to JetBrains Mono
// @license MIT
// @author Clazex
// @copyright 2022, Clazex
// @icon https://github.githubassets.com/favicons/favicon.png
// @downloadURL https://raw.githubusercontent.com/Clazex/JetBrainsMono4GitHub/main/script.user.js
// @updateURL https://raw.githubusercontent.com/Clazex/JetBrainsMono4GitHub/main/script.user.js
// @supportURL https://github.com/Clazex/JetBrainsMono4GitHub/issues
// @homepage https://github.com/Clazex/JetBrainsMono4GitHub
// @run-at document-body
// @grant GM_addStyle
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @match https://github.com/*
// ==/UserScript==
(function() {
'use strict';
const DEFAULT_FONT = `'Jetbrains Mono'`;
function getFont() {
return GM_getValue('font', DEFAULT_FONT);
}
function setFont(font) {
if (getFont() === font) {
return;
}
GM_setValue('font', font);
applyFont(font);
}
let style;
function applyFont(font = getFont()) {
style?.remove();
style = GM_addStyle(
`pre, .markdown-body code, .blob-code-inner, .CodeMirror-lines, .react-code-text, .diff-text, ul[aria-label="Code Navigation"] .PRIVATE_TreeView-item-content-text span { font-family: ${font}, monospace !important }`
+ '.blob-code-inner, .CodeMirror-lines, .react-code-text, .diff-text { font-size: 1em !important; }'
);
unregisterMenuCommand();
registerMenuCommand(font);
}
function updateFont() {
const oldFont = getFont();
let newFont = '';
while (true) {
newFont = prompt('Specify font family', oldFont);
if (newFont == null) {
return;
}
if (newFont.length > 0) {
break;
}
}
setFont(newFont);
}
let menuCommandId = null;
function registerMenuCommand(font) {
menuCommandId = GM_registerMenuCommand("Current font: " + font, updateFont);
}
function unregisterMenuCommand() {
if (menuCommandId === null) {
return;
}
GM_unregisterMenuCommand(menuCommandId);
menuCommandId = null;
}
applyFont();
})();