Last active
December 23, 2021 10:10
-
-
Save scarf005/4b29a33f8478d8a0a543a4943bcf3cfb to your computer and use it in GitHub Desktop.
userscript for #tempermonkey; changes font for code block. original by peko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Font Ligatures | |
// @namespace https://gist.github.com/scarf005/ | |
// @version 0.5.0 | |
// @description ligatures are good | |
// @author youkim | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== | |
/* | |
original script: https://gist.github.com/peko/08001db4ee9babd8d482e19ffae99d18 | |
matches: dict -> for specific sites; ex: 'acmicpc.net':'.CodeMirror' | |
default: array -> to change for all corresponding css styles | |
*/ | |
//== Declaration == | |
const matches = { 'stackoverflow.com': '.s-prose code' } | |
const defaults = ['.ace_content', '.blob-code-inner', '.CodeMirror'] | |
const font = `{font-family: "Fira Code" !important; font-size:14px;}` // Hack FC Ligatured | |
//==Implementation== | |
;((font) => { | |
'use strict' | |
const domain = ((h) => { | |
return h.substring(h.lastIndexOf('.', h.lastIndexOf('.') - 1) + 1, | |
)})(window.location.hostname) | |
let scope = matches[domain] || '' + defaults.join(', ') | |
let style = document.createElement('style') | |
let css = `${scope}${font}` | |
console.log(`visiting ${domain}\nscope:${scope}`) | |
style.type = 'text/css' | |
if (style.styleSheet) { | |
style.styleSheet.cssText = css | |
} else { | |
style.appendChild(document.createTextNode(css)) | |
} | |
document.getElementsByTagName('head')[0].appendChild(style) | |
})(font) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment