Last active
August 8, 2018 09:42
-
-
Save d-faure/a2c4d5e66ccb895b23847115070871a6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 My Custom Fixed Font in Gmail | |
// @namespace https://mail.google.com | |
// @include https://mail.google.com/* | |
// @icon https://ssl.gstatic.com/ui/v1/icons/mail/favicon.ico | |
// @run-at document-start | |
// @description My Custom fixed-font in Gmail messages | |
// @version 1.4.1 | |
// @license CC0; https://creativecommons.org/publicdomain/zero/1.0/ | |
// @author Me and Marcin Rataj (original), Martin Baranski (tweaks) | |
// @homepageURL https://gist.github.com/d-faure/ | |
// @grant GM_addStyle | |
// @grant GM.addStyle | |
// ==/UserScript== | |
const fontName = 'Roboto Mono'; | |
const fontSubset = 'latin'; | |
// dragons below this line | |
const fontCss = 'font-family: \'' + fontName + '\', monospace !important;'; | |
// plain-text messages | |
let css = '.a3s, .ii, .Ak {' + fontCss + '}'; | |
// editor | |
css += '.editable {' + fontCss + '}'; | |
// load | |
const heads = document.getElementsByTagName('head'); | |
// load font | |
if (heads.length > 0) { | |
const link = document.createElement('link'); | |
link.rel = 'stylesheet'; | |
link.href = '//fonts.googleapis.com/css?family=' + fontName.replace(/\ /g, '+') + '&subset=' + fontSubset; | |
heads[0].appendChild(link); | |
const node = document.createElement('style'); | |
node.type = 'text/css'; | |
node.appendChild(document.createTextNode(css)); | |
heads[0].appendChild(node); | |
} | |
// attach style | |
if (typeof GM_addStyle != "undefined") { | |
GM_addStyle(css); | |
} else if (typeof addStyle != "undefined") { | |
addStyle(css); | |
} else { | |
if (heads.length > 0) { | |
const node = document.createElement('style'); | |
node.type = 'text/css'; | |
node.appendChild(document.createTextNode(css)); | |
heads[0].appendChild(node); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment