Home › Forums › JavaScript › Dark/Light color switch › Reply To: Dark/Light color switch
March 16, 2018 at 10:17 am
#268340
Participant
Check it out:
(function() {
var motif = document.getElementById('theme'),
flip = document.querySelector('.theme-switcher'),
tone = true, depot = (function() {
try {
var bin = localStorage;
bin.temp = 1;
delete bin.temp;
return bin || false;
}
catch(e) {
return false;
}
})();
if (depot) {
if (!depot.shade) depot.shade = true;
else {
tone = JSON.parse(depot.shade);
if (tone) motif.setAttribute('class', 'wrap light');
else {
motif.setAttribute('class', 'wrap dark');
flip.innerHTML = 'bright';
}
}
}
flip.addEventListener('click', function() {
tone = !tone;
if (depot) depot.shade = tone;
if (this.innerHTML == 'bright') this.innerHTML = 'dark';
else this.innerHTML = 'bright';
motif.classList.toggle('light');
motif.classList.toggle('dark');
});
})();
Dunno about the anons, haven’t noticed anything myself yet…