Skip to content

Instantly share code, notes, and snippets.

@sli
Last active December 6, 2019 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sli/9b48d499490469975eef5e943d21b8b8 to your computer and use it in GitHub Desktop.
Save sli/9b48d499490469975eef5e943d21b8b8 to your computer and use it in GitHub Desktop.
A userscript to enable ligatures (using Fira Code) on <code> blocks and Monaco Editors.
// ==UserScript==
// @name Browser Fira Code
// @version 1
// @grant none
// ==/UserScript==
const GM_addCssResource = href => {
const head = document.getElementsByTagName('head')[0]
if (!head) { return }
let link = document.createElement('link')
link.type = 'text/css'
link.href = href
head.appendChild(link)
}
const GM_addStyle = css => {
const head = document.getElementsByTagName('head')[0]
if (!head) { return }
let style = document.createElement('style')
style.type = 'text/css'
style.innerHTML = css.replace(/;/g, ' !important;')
head.appendChild(style)
}
GM_addCssResource('https://fonts.googleapis.com/css?family=Fira+Code&display=swap')
GM_addStyle('code, .view-lines *, table.highlight tr *, div.highlight:not(.result) *, pre.highlight * { font-family: \'Fira Code\', monospace; font-feature-settings: "liga" on; }')
/* Selector explanations:
* code -> all code blocks
* .view-lines * -> Azure support
* table.highlight tr * -> Github support
* div.highlight:not(.result) * -> div blocks with the highlight class, but not result class (duckduckgo fix)
* pre.highlight * -> Gitlab support
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment