28078017adde2257831e2ca70ce8fbc7261c3e66
   1const COOKIENAME = "settings";
   2const COOKIEEXP = 365;
   3
   4function setCookie(cname, cvalue, exdays) {
   5    var d = new Date();
   6    d.setTime(d.getTime() + (exdays*24*60*60*1000));
   7    var expires = "expires="+ d.toUTCString();
   8    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
   9}
  10
  11function getCookie(cname) {
  12    var name = cname + "=";
  13    var decodedCookie = decodeURIComponent(document.cookie);
  14    var ca = decodedCookie.split(';');
  15    for(var i = 0; i <ca.length; i++) {
  16        var c = ca[i];
  17        while (c.charAt(0) == ' ') {
  18            c = c.substring(1);
  19        }
  20        if (c.indexOf(name) == 0) {
  21            return c.substring(name.length, c.length);
  22        }
  23    }
  24    return 0;
  25}
  26
  27function saveSettings() {
  28    settingsString = JSON.stringify({showcurrent: show_current.checked, shownext: show_next.checked});
  29    console.log("Saving cookie " + settingsString);
  30    setCookie(COOKIENAME, settingsString, COOKIEEXP);
  31}
  32
  33function initSettings() {
  34    console.log("Retrieving cookie");
  35    if (getCookie(COOKIENAME) == 0) {
  36        console.log("No cookie found - setting new cookie");
  37        saveSettings()
  38    } else {
  39        cookie = JSON.parse(getCookie(COOKIENAME));
  40        console.log("Found cookie " + cookie);
  41        show_current.checked = cookie.showcurrent;
  42        show_next.checked = cookie.shownext;
  43        sync_current();
  44        sync_next();
  45    }
  46
  47}
  48