Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name 10C Light/Dark Toggle
// @namespace http://mikedeep.com
// @description Adds back the light/dark toggle switch on the Pearl Jam Forum.
// @include http://community.pearljam.com/*
// @version 1
// @grant none
// ==/UserScript==
var brightness = readCookie('dark');
if(brightness > 0) { toggleCSS(); }
function addGlobalStyle(css) {
var head = document.getElementsByTagName('head')[0];
if (!head) { return; }
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
var brightnessToggle = document.createElement('span');
brightnessToggle.className = "ToggleFlyout";
document.getElementsByClassName('MeMenu')[0].appendChild(brightnessToggle);
var brightnessAnchor = document.createElement('a');
brightnessAnchor.className = "MeButton FlyoutButton";
brightnessToggle.appendChild(brightnessAnchor);
brightnessAnchor.href = "#";
brightnessAnchor.title = "Switch to Dark Theme";
var brightnessSpan = document.createElement('span');
brightnessSpan.className = "Sprite Sprite16 SpOptions userScriptToggle";
brightnessAnchor.appendChild(brightnessSpan);
brightnessAnchor.addEventListener('click', toggleCSS);
function toggleCSS() {
var darkClass = "Theme-Dark";
var checkClass = document.body.classList.contains(darkClass);
if(checkClass > 0) {
document.body.classList.remove(darkClass);
document.cookie = "dark = 0; max-age = 31536e3; path=/";
} else {
document.body.classList.add(darkClass);
document.cookie = "dark = 1; max-age = 31536e3; path=/";
}
}
addGlobalStyle (
"body.Theme-Dark {" +
" background-color: #000;" +
"}" +
".Theme-Dark .Navbar .Menu .Brand {" +
" -webkit-filter: invert(100%);" +
" -moz-filter: invert(100%);" +
" filter: invert(100%);" +
"}" +
".Theme-Dark .Navbar .Menu a," +
".Theme-Dark .Toolbar .Menu li a {" +
" color: #fff;" +
"}" +
".Theme-Dark .Navbar .Menu a:hover {" +
" color: #a88231;" +
"}" +
".userScriptToggle {" +
" background-position: -320px -100px;" +
"}" +
".Theme-Dark .userScriptToggle {" +
" background-position: -320px -120px;" +
"}" +
".Theme-Dark .TagCloud li a {" +
" color: #fff;" +
"}"
);
// quirksmode.org/js/cookies.html
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.