Add cookie saving for day/night mode

This commit is contained in:
John Mulhausen 2017-02-24 16:24:16 -08:00
parent 12c25322c3
commit 20c91a529b
No known key found for this signature in database
GPG Key ID: 0FC599ECCDBFDE02
1 changed files with 36 additions and 3 deletions

View File

@ -1,3 +1,37 @@
// Cookie functions
function createCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + value + expires + "; path=/";
}
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;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
if (readCookie("night") == "true") {
document.getElementById('pagestyle').setAttribute('href', '/css/style-alt.css');
$('#switch-style').prop('checked', true);
} else {
document.getElementById('pagestyle').setAttribute('href', '/css/style.css');
$('#switch-style').prop('checked', false);
}
/*
*
* swapStyleSheet*********************************************************************
@ -97,11 +131,10 @@ $('#switch-style').change(function() {
if ($(this).is(':checked')) {
swapStyleSheet('/css/style-alt.css');
createCookie("night",true,999)
} else {
swapStyleSheet('/css/style.css');
eraseCookie("night")
}
});