Last active
January 7, 2024 10:17
-
-
Save theand/90f75fc03b8a32feff4473c1c97277b9 to your computer and use it in GitHub Desktop.
User Script for javadocs - link style, code highlight (docs.spring.io, docs.oracle.com)
This file contains 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 javadocs-refiner | |
// @namespace http://127.0.0.1 | |
// @description User Script for javadocs - link style, code highlight (docs.spring.io, docs.oracle.com) | |
// @author Heesang Chae | |
// @include /https?://docs.spring.io/ | |
// @include /https?://docs.oracle.com/ | |
// @include /https?://openjdk.java.net/jeps/ | |
// @exclude /https?://docs.spring.io/spring-framework/docs/5/ | |
// @exclude /https?://docs.spring.io/.*/site/xref/ | |
// @require https://cdn.jsdelivr.net/npm/prismjs@1.9.0/prism.min.js | |
// @require https://cdn.jsdelivr.net/npm/prismjs@1.9.0/components/prism-java.min.js | |
// @require https://cdn.jsdelivr.net/gh/mathiasbynens/he@v1.1.1/he.js | |
// @require https://cdn.jsdelivr.net/gh/theand/userscript-util@latest/exec.js | |
// @require https://cdn.jsdelivr.net/gh/theand/userscript-util@latest/inject.js | |
// @require https://cdn.jsdelivr.net/gh/theand/userscript-util@latest/add.js | |
// @version 2018.03.05 | |
// @grant none | |
// ==/UserScript== | |
/*global Prism he userscript_util*/ | |
window.Prism = Prism; | |
window.he = he; | |
const userscript = function (GM_info) { | |
console.group(GM_info.script.name); | |
userscript_util.exec.logGmInfo(GM_info); | |
function strip(html) { | |
const tmp = document.createElement("DIV"); | |
tmp.innerHTML = html; | |
return tmp.textContent || tmp.innerText; | |
} | |
try { | |
document.querySelectorAll("pre > code, td > pre").forEach(e => { | |
const text = he.decode(strip(e.innerHTML)); | |
const html = Prism.highlight(text, Prism.languages.java); | |
e.setAttribute("class", "language-java"); | |
e.innerHTML = html; | |
const preNode = e.parentNode; | |
preNode.setAttribute("class", "language-java"); | |
}); | |
document.querySelectorAll("pre.code, blockquote > pre, pre.codeblock, pre.programlisting").forEach(e => { | |
const text = he.decode(strip(e.innerHTML)); | |
const html = Prism.highlight(text, Prism.languages.java); | |
const newCode = document.createElement("code"); | |
newCode.setAttribute("class", "language-java"); | |
newCode.innerHTML = html; | |
const newPre = document.createElement("pre"); | |
newPre.setAttribute("class", "language-java"); | |
newPre.appendChild(newCode); | |
e.parentNode.replaceChild(newPre, e); | |
}); | |
} catch (err) { | |
userscript_util.exec.logGmError(GM_info, err); | |
} | |
console.groupEnd(); | |
}; | |
//default themes | |
// userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/prism/1.6.0/themes/prism.css"); | |
// userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/prism/1.6.0/themes/prism-twilight.css"); | |
// userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/prism/1.6.0/themes/prism-okaidia.css"); | |
// userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/prism/1.6.0/themes/prism-solarizedlight.css"); | |
//wider themes | |
//userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/gh/theand-fork/prism-themes@1.0/themes/prism-atom-dark.css"); | |
//userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/gh/theand-fork/prism-themes@1.0/themes/prism-base16-ateliersulphurpool.light.css"); | |
//userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/gh/theand-fork/prism-themes@1.0/themes/prism-cb.css"); | |
userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/gh/theand-fork/prism-themes@1.0/themes/prism-darcula.css"); | |
//userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/gh/theand-fork/prism-themes@1.0/themes/prism-duotone-light.css"); | |
//userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/gh/theand-fork/prism-themes@1.0/themes/prism-ghcolors.css"); | |
//userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/gh/theand-fork/prism-themes@1.0/themes/prism-hopscotch.css"); | |
//userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/gh/theand-fork/prism-themes@1.0/themes/prism-pojoaque.css"); | |
//userscript_util.inject.injectExternalStyleSheet("https://cdn.jsdelivr.net/gh/theand-fork/prism-themes@1.0/themes/prism-xonokai.css"); | |
userscript_util.add.addGlobalStyle(` | |
a:link, a:visited { | |
color: #3b99f1 !important; | |
text-decoration: underline !important; | |
} | |
`); | |
userscript_util.exec.executeLater(userscript, GM_info, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/ExceptionHandler.html
original
after