Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save btamayo/6b7d0904ba4dd5aaebcd4eec45481633 to your computer and use it in GitHub Desktop.
Save btamayo/6b7d0904ba4dd5aaebcd4eec45481633 to your computer and use it in GitHub Desktop.
[ZSH Documentation Enhancer] Make ZSH Documentation more readable #UserScript
// ==UserScript==
// @name ZSH Documentation Enhancer - Dark
// @version 0.4
// @description Make ZSH Documentation more readable (fork from rjf89)
// @require http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/highlight.min.js
// @resource theme http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/tomorrow-night.min.css
// @resource bootstrap https://bootswatch.com/4/darkly/bootstrap.min.css
// @author btamayo
// @match http://zsh.sourceforge.net/Doc/*
// @run-at document-start
// @grant GM_addStyle
// @grant GM_getResourceText
// ==/UserScript==
const STYLE_TWEAKS = `
p { margin: 1rem 2rem 1rem 2rem; }
p > tt { color: khaki; font-size: 1.3rem; }
dl { margin: 1rem 2rem 1rem 2rem; }
h1,h2,h3 { margin: 1rem 2rem 1rem 2rem; }
dd { border-width: 1px; border-color: #949494; border-style: groove; margin: 0rem 1rem 1rem 1rem; }
dt > tt { margin: 0rem 1rem 1rem 1rem; font-weight: 600; color: chartreuse; font-size: 1.5rem; }
dt > var { color: #fff06b; letter-spacing: 1.2px; }
dd > p { margin: 1rem 1rem 1rem 1rem; }
dd > em { font-weight: 600; }
dt { font-weight: 600; }
.hljs { font-size: 1.1rem; }
table.header { margin: 1rem 2rem 1rem 2rem; }
body { color: #efefef; font-size: 1rem; font-family: "Georgia", "Merriweather", "Montserrat", "Georgia"; --font-family-monospace: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace }
`;
let concat = (previous, current) => {
return [...previous, ...current];
};
let flatMap = (xs, fn) => {
return 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' || e.tagName == "tt") {
GM_log(e.tagName);
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