901af0b5934e2536e5876fdfaf863126267b20b1
   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    console.log("Saving settings")
  29    settingsString = JSON.stringify({showcurrent: show_current.checked, shownext: show_next.checked, enable_shortcuts: shortcuts.checked});
  30    setCookie(COOKIENAME, settingsString, COOKIEEXP);
  31}
  32
  33function initSettings() {
  34    if (getCookie(COOKIENAME) == 0) {
  35        if (window.obssstudio) {
  36                shortcuts.checked = False;
  37                show_current.checked = False;
  38        }
  39        saveSettings()
  40    } else {
  41        cookie = JSON.parse(getCookie(COOKIENAME));
  42        show_current.checked = cookie.showcurrent;
  43        show_next.checked = cookie.shownext;
  44        shortcuts.checked = cookie.enable_shortcuts;
  45        sync_current();
  46        sync_next();
  47    }
  48
  49}
  50