Skip to content

Instantly share code, notes, and snippets.

@rf5860
Last active October 19, 2021 03:53
Show Gist options
  • Save rf5860/c66307fceed0ab43d6bb60962723abe0 to your computer and use it in GitHub Desktop.
Save rf5860/c66307fceed0ab43d6bb60962723abe0 to your computer and use it in GitHub Desktop.
[perlmonks.org Readability Enhancements] Make posts & code easier to read on perlmonks.org #UserScript
// ==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});
})();
@hellojukay
Copy link

good job ,it works for me. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment