Forked from rf5860/perlmonksReadabilityEnhancements.user.js
Created
June 11, 2021 22:06
-
-
Save oremb/46b4cabe7a71d27d3e6ca2493b09c981 to your computer and use it in GitHub Desktop.
[perlmonks.org Readability Enhancements] Make posts & code easier to read on perlmonks.org #UserScript
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 perlmonks.org Readability Enhancements | |
| // @description Readability Enhancements for perlmonks.org | |
| // @author rjf89 | |
| // @include http://perlmonks.org/* | |
| // @include https://perlmonks.org/* | |
| // @include http://*.perlmonks.org/* | |
| // @include https://*.perlmonks.org/* | |
| // @include http://www.perlmonks.org/* | |
| // @include https://www.perlmonks.org/* | |
| // @include http://*.www.perlmonks.org/* | |
| // @include https://*.www.perlmonks.org/* | |
| // @require http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js | |
| // @resource theme http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow-night.min.css | |
| // @grant GM_addStyle | |
| // @grant GM_getResourceText | |
| // @run-at document-start | |
| // @version 0.1 | |
| // ==/UserScript== | |
| const STYLE_TWEAKS = ` | |
| h3 { margin-bock-end: 0px; } | |
| tr.titlebar { display: none; } | |
| .hljs { | |
| font-size: 1.1em; | |
| font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; | |
| } | |
| `; | |
| let concat = (previous, current) => [...previous, ...current]; | |
| let flatMap = (xs, fn) => xs.map(fn).reduce(concat, []); | |
| (function () { | |
| 'use strict' | |
| GM_addStyle(STYLE_TWEAKS); | |
| GM_addStyle(GM_getResourceText('theme')); | |
| function hlCode(elem) { | |
| elem.classList.add('language-perl'); | |
| window.hljs.highlightBlock(elem); | |
| }; | |
| function processCodeBlock(e) { | |
| if (e.classList && e.classList.contains('codetext') && !e.classList.contains('language-perl')) hlCode(e); | |
| else if (e.childElementCount > 0) [...e.getElementsByClassName('codetext')].forEach(hlCode); | |
| } | |
| var observer = new MutationObserver(function(ms) { flatMap(ms, m => m.addedNodes).forEach(processCodeBlock); }); | |
| observer.observe(document, {childList: true, subtree: true}); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment