Last active
January 17, 2020 07:19
-
-
Save thekalinga/e58edd51cb53266af6850206225d9269 to your computer and use it in GitHub Desktop.
Beautifier: Spring Documentation
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 Beautifier: Spring Documentation | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @author You | |
// @match https://docs.spring.io/*/reference/htmlsingle* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function undo() { | |
removeClass(document.getElementsByTagName('body')[0], 'toggle'); | |
toggle.src = showNavIcon; | |
} | |
function apply() { | |
addClass(document.getElementsByTagName('body')[0], 'toggle'); | |
toggle.src = hideNavIcon; | |
} | |
var showing = false; | |
var hideNavIcon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB3aWR0aD0iMTAwJSIKICAgaGVpZ2h0PSIxMDAlIgogICB2aWV3Qm94PSIwIDAgMjA0OCAxNzkyIj4KICA8cGF0aAogICAgIGQ9Ik0wIDg5NnEwLTEzMCA1MS0yNDguNXQxMzYuNS0yMDQgMjA0LTEzNi41IDI0OC41LTUxaDc2OHExMzAgMCAyNDguNSA1MXQyMDQgMTM2LjUgMTM2LjUgMjA0IDUxIDI0OC41LTUxIDI0OC41LTEzNi41IDIwNC0yMDQgMTM2LjUtMjQ4LjUgNTFoLTc2OHEtMTMwIDAtMjQ4LjUtNTF0LTIwNC0xMzYuNS0xMzYuNS0yMDQtNTEtMjQ4LjV6TTE0MDggMTQwOHExMDQgMCAxOTguNS00MC41dDE2My41LTEwOS41IDEwOS41LTE2My41IDQwLjUtMTk4LjUtNDAuNS0xOTguNS0xMDkuNS0xNjMuNS0xNjMuNS0xMDkuNS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UtMjA0IDIwNC0xMzYuNSAyNDguNS01MWg3NjhxMTMwIDAgMjQ4LjUgNTF0MjA0IDEzNi41IDEzNi41IDIwNCA1MSAyNDguNXoiLz48L3N2Zz4='; | |
var toggle = document.createElement('img'); | |
toggle.src = hideNavIcon; | |
toggle.style.position = 'fixed'; | |
toggle.style.bottom = "10px"; | |
toggle.style.right = "10px"; | |
toggle.style.width = "20px"; | |
toggle.style.height = "20px"; | |
toggle.style.cursor = "pointer"; | |
toggle.style.zIndex = "9999"; | |
toggle.addEventListener("click", function() { | |
if (!showing) { | |
apply(); | |
} else { | |
undo(); | |
} | |
showing = !showing; | |
}); | |
document.getElementsByTagName('body')[0].appendChild(toggle); | |
var newStyleToBeApplied = document.createElement('style'); | |
newStyleToBeApplied.type= 'text/css'; | |
newStyleToBeApplied.innerHTML = ` | |
body.toggle #header { | |
display: none; | |
} | |
body.toggle.toc2 #content { | |
background-image: none; | |
padding-left: 1em; | |
} | |
`; | |
document.getElementsByTagName('head')[0].appendChild(newStyleToBeApplied); | |
apply(); | |
showing = !showing; | |
function hasClass(el, className) { | |
if (el.classList) { | |
return el.classList.contains(className); | |
} else { | |
return !!el.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)')); | |
} | |
} | |
function addClass(el, className) { | |
if (el.classList) { | |
el.classList.add(className); | |
} | |
else if (!hasClass(el, className)) { | |
el.className += " " + className; | |
} | |
} | |
function removeClass(el, className) { | |
if (el.classList) { | |
el.classList.remove(className); | |
} else if (hasClass(el, className)) { | |
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)'); | |
el.className=el.className.replace(reg, ' '); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment