Skip to content

Instantly share code, notes, and snippets.

@theand
Last active September 22, 2017 05:07
Show Gist options
  • Save theand/c73e3328393ea2efa0107beef02db568 to your computer and use it in GitHub Desktop.
Save theand/c73e3328393ea2efa0107beef02db568 to your computer and use it in GitHub Desktop.
Deprecated. ~User Script for docs.spring.io code highlight~ go to https://gist.github.com/theand/90f75fc03b8a32feff4473c1c97277b9
// ==UserScript==
// @name docs.spring.io code highlight
// @namespace http://127.0.0.1
// @description User Script for docs.spring.io code highlight
// @author Heesang Chae
// @include http://docs.spring.io/*
// @require https://cdn.jsdelivr.net/prism/1.6.0/prism.js
// @require https://cdn.jsdelivr.net/prism/1.6.0/components/prism-java.min.js
// @require https://cdn.jsdelivr.net/gh/mathiasbynens/he@v1.1.1/he.js
// @version 2017.07.18
// @grant none
// ==/UserScript==
var userscript = function (Prism, he) {
console.log("init : docs.spring.io Code Syntax - " + document.location.toString());
try {
document.querySelectorAll("pre.code").forEach(e => {
const text = he.decode(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.appendChild(newCode);
e.parentNode.replaceChild(newPre, e);
});
} catch (err) {
console.error("UserScript : " + err.toString());
}
};
window.prismjs = Prism;
window.hejs = he;
setTimeout(() => {
var el = document.createElement('script');
el.type = 'text/javascript';
el.text = '(' + userscript + ')(window.prismjs, window.hejs);';
document.head.appendChild(el);
}, 500);
function injectStyleSheet(href) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = href;
document.head.appendChild(link);
}
injectStyleSheet("https://cdn.jsdelivr.net/prism/1.6.0/themes/prism.css");
@theand
Copy link
Author

theand commented Jul 18, 2017

screen shot 2017-07-18 at 6 41 37

left - userscript applied.
right - original

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