Created
December 24, 2016 09:41
-
-
Save thekalinga/7dbb466416b0c97be71fb608a23f34bb to your computer and use it in GitHub Desktop.
Angular documentation, fat cleanup
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 Angular documentation, fat cleanup | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://angular.io/docs/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var showing = true; | |
var hideNavIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAyMDQ4IDE3OTIiPjxwYXRoIGZpbGw9InJnYigyMSwxMDEsMTkyKSIgZD0iTTAgODk2cTAtMTMwIDUxLTI0OC41dDEzNi41LTIwNCAyMDQtMTM2LjUgMjQ4LjUtNTFoNzY4cTEzMCAwIDI0OC41IDUxdDIwNCAxMzYuNSAxMzYuNSAyMDQgNTEgMjQ4LjUtNTEgMjQ4LjUtMTM2LjUgMjA0LTIwNCAxMzYuNS0yNDguNSA1MWgtNzY4cS0xMzAgMC0yNDguNS01MXQtMjA0LTEzNi41LTEzNi41LTIwNC01MS0yNDguNXpNMTQwOCAxNDA4cTEwNCAwIDE5OC41LTQwLjV0MTYzLjUtMTA5LjUgMTA5LjUtMTYzLjUgNDAuNS0xOTguNS00MC41LTE5OC41LTEwOS41LTE2My41LTE2My41LTEwOS41LTE5OC41LTQwLjUtMTk4LjUgNDAuNS0xNjMuNSAxMDkuNS0xMDkuNSAxNjMuNS00MC41IDE5OC41IDQwLjUgMTk4LjUgMTA5LjUgMTYzLjUgMTYzLjUgMTA5LjUgMTk4LjUgNDAuNXoiLz48L3N2Zz4='; | |
var showNavIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAyMDQ4IDE3OTIiPjxwYXRoIGZpbGw9InJnYigxODksMTg5LDE4OSkiIGQ9Ik0xMTUyIDg5NnEwLTEwNC00MC41LTE5OC41dC0xMDkuNS0xNjMuNS0xNjMuNS0xMDkuNS0xOTguNS00MC41LTE5OC41IDQwLjUtMTYzLjUgMTA5LjUtMTA5LjUgMTYzLjUtNDAuNSAxOTguNSA0MC41IDE5OC41IDEwOS41IDE2My41IDE2My41IDEwOS41IDE5OC41IDQwLjUgMTk4LjUtNDAuNSAxNjMuNS0xMDkuNSAxMDkuNS0xNjMuNSA0MC41LTE5OC41ek0xOTIwIDg5NnEwLTEwNC00MC41LTE5OC41dC0xMDkuNS0xNjMuNS0xNjMuNS0xMDkuNS0xOTguNS00MC41aC0zODZxMTE5IDkwIDE4OC41IDIyNHQ2OS41IDI4OC02OS41IDI4OC0xODguNSAyMjRoMzg2cTEwNCAwIDE5OC41LTQwLjV0MTYzLjUtMTA5LjUgMTA5LjUtMTYzLjUgNDAuNS0xOTguNXpNMjA0OCA4OTZxMCAxMzAtNTEgMjQ4LjV0LTEzNi41IDIwNC0yMDQgMTM2LjUtMjQ4LjUgNTFoLTc2OHEtMTMwIDAtMjQ4LjUtNTF0LTIwNC0xMzYuNS0xMzYuNS0yMDQtNTEtMjQ4LjUgNTEtMjQ4LjUgMTM2LjUtMjA0IDIwNC0xMzYuNSAyNDguNS01MWg3NjhxMTMwIDAgMjQ4LjUgNTF0MjA0IDEzNi41IDEzNi41IDIwNCA1MSAyNDguNXoiLz48L3N2Zz4='; | |
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.addEventListener("click", function() { | |
showing = !showing; | |
if (!showing) { | |
hideNav(); | |
} else { | |
showNav(); | |
} | |
}); | |
document.getElementsByTagName('body')[0].appendChild(toggle); | |
function hideNav() { | |
var body = document.getElementsByTagName('body')[0]; | |
if (hasClass(body, 'l-offset-side-nav')) { | |
removeClass(body, 'l-offset-side-nav'); | |
} | |
if (hasClass(body, 'l-offset-nav')) { | |
removeClass(body, 'l-offset-nav'); | |
} | |
var mainNav = document.getElementsByClassName('main-nav')[0]; | |
mainNav.style.display = 'none'; | |
var sideNav = document.getElementsByClassName('sidenav')[0]; | |
sideNav.style.display = 'none'; | |
toggle.src = showNavIcon; | |
} | |
function showNav() { | |
var body = document.getElementsByTagName('body')[0]; | |
if (!hasClass(body, 'l-offset-side-nav')) { | |
addClass(body, 'l-offset-side-nav'); | |
} | |
if (!hasClass(body, 'l-offset-nav')) { | |
addClass(body, 'l-offset-nav'); | |
} | |
var mainNav = document.getElementsByClassName('main-nav')[0]; | |
mainNav.style.display = ''; | |
var sideNav = document.getElementsByClassName('sidenav')[0]; | |
sideNav.style.display = ''; | |
toggle.src = hideNavIcon; | |
} | |
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