Recently, Stack Exchange decided to switch to system fonts. For those of you who prefered the old appearance, or would like a different font to appear in code blocks or across the site as a whole, Custom Fonts is a user script I wrote this morning to allow just that.
Features
Custom Fonts allows rules to be set for different sites, which can specify a sans serif, serif, and monospace font. A default can also be specified, allowing you to choose between sans serif and serif for any site.
Custom Fonts initially doesn't change anything (unless you download one with a preset), but on lines 26 and 27 are rules that revert all of Stack Exchange to its original fonts (once un-commented). Custom rules can be written, and there is a short reference in the comments under the Rules object.
Download
Custom Fonts is a user script, meaning that it requires Greasemonkey (Firefox or browsers that support Firefox extensions) or Tampermonkey (Chrome or browsers that support Chrome extensions) to be installed.
@run-at document-start) so there shouldn't be a visible delay very often. A lot more people have userscript managers installed than userstyle ones, so I figured this would be useful to share, at least as a temporary solution. – Radvylf Programs May 11 '21 at 12:45@match https://stackexchange.com. This line wasn't there in 1.2.1, which does work fine. – HolyBlackCat May 17 '21 at 17:11@excludes for chat and the API – Radvylf Programs May 17 '21 at 17:39document-startthe<head>and<body>elements will commonly not yet exist. The element which is guaranteed to exist and to which you can.appendChildis thedocument.documentElement. However, given that usingdocument.documentElement.appendChildat that time will result in your<style>being before the<head>in the document, you will need to make sure that the CSS rules have a higher specificity than the ones you're wanting to replace, because they will be before, not after, any rules in CSS provided by the page. (continued) – Makyen May 18 '21 at 00:10bodyorhtml. For those two elements,bodyandhtml, you can add a:not(.withSomeMadeUpClassWhichWillNeverExistInTheDocumentOnThatElement). Using thedocument.documentElementis significantly superior to waiting for theDOMContentLoadedevent. If you wait forDOMContentLoaded, which is going to be the case most of the time, depending on userscript manager, browser, and OS, the user will experience a flash of the incorrectly formatted content. – Makyen May 18 '21 at 00:10MutationObserverto wait for the<head>and/or<body>to be created, but that approach really isn't justified for something like this (and didn't work in the older versions of Edge). – Makyen May 18 '21 at 00:13