Skip to content

Instantly share code, notes, and snippets.

@rf5860
Last active April 8, 2020 19:48
Show Gist options
  • Save rf5860/2f02adbec521a46ca0c242c987511701 to your computer and use it in GitHub Desktop.
Save rf5860/2f02adbec521a46ca0c242c987511701 to your computer and use it in GitHub Desktop.
[ZSH Documentation Enhancer] Make ZSH Documentation more readable #UserScript
// ==UserScript==
// @name ZSH Documentation Enhancer
// @version 0.3
// @description Make ZSH Documentation more readable
// @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
// @resource bootstrap https://bootswatch.com/4/darkly/bootstrap.min.css
// @author rjf89
// @match http://zsh.sourceforge.net/Doc/*
// @run-at document-start
// @grant GM_addStyle
// @grant GM_getResourceText
// ==/UserScript==
const STYLE_TWEAKS = `dd { border-width: thin; border-style: groove; margin: 0em 1em 1em 1em; }
dt > tt { margin: 0em 1em 1em 1em; color: chartreuse; }
dt > var { color: khaki; }
dd > p { margin: 1em 1em 1em 1em; }
.hljs { font-size: 1.1em; }`;
let concat = (previous, current) => [...previous, ...current];
let flatMap = (xs, fn) => xs.map(fn).reduce(concat, []);
function hlCode(e) {
if (!e.classList.contains('language-bash')) {
e.classList.add('language-bash');
window.hljs.highlightBlock(e);
}
}
function process(e) {
if (e.tagName == 'PRE') hlCode(e);
else if (e.childElementCount > 0) [...e.getElementsByTagName('pre')].forEach(hlCode);
}
(function() {
"use strict";
GM_addStyle(GM_getResourceText('theme'));
GM_addStyle(GM_getResourceText('bootstrap'));
GM_addStyle(STYLE_TWEAKS);
[...document.getElementsByTagName('pre')].forEach(hlCode);
new MutationObserver(ms => { flatMap(ms, m => m.addedNodes).forEach(process) }).observe(document, {childList: true, subtree: true});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment