Last active
September 22, 2017 05:07
-
-
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
This file contains hidden or 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 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/[email protected]/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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
left - userscript applied.
right - original