mirror of https://github.com/calzoneman/sync.git
Move user options to localStorage instead of cookies
This commit is contained in:
parent
a1862496a9
commit
685358b0d8
|
@ -53,26 +53,33 @@ function parseBool(x) {
|
||||||
else return Boolean(x);
|
else return Boolean(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOrDefault(cookie, def) {
|
getOrDefault = function(k, def) {
|
||||||
var cook = readCookie(cookie);
|
var v = localStorage.getItem(k);
|
||||||
if(cook === null) {
|
if(v === null)
|
||||||
return def;
|
return def;
|
||||||
}
|
if(v === "true")
|
||||||
return cook;
|
return true;
|
||||||
|
if(v === "false")
|
||||||
|
return false;
|
||||||
|
if(v.match(/[0-9]+/))
|
||||||
|
return parseInt(v);
|
||||||
|
if(v.match(/[0-9\.]+/))
|
||||||
|
return parseFloat(v);
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
var USEROPTS = {
|
var USEROPTS = {
|
||||||
theme : getOrDefault("cytube_theme", "default"),
|
theme : getOrDefault("theme", "default"),
|
||||||
css : getOrDefault("cytube_css", ""),
|
css : getOrDefault("css", ""),
|
||||||
layout : getOrDefault("cytube_layout", "default"),
|
layout : getOrDefault("layout", "default"),
|
||||||
synch : parseBool(getOrDefault("cytube_synch", true)),
|
synch : getOrDefault("synch", true),
|
||||||
hidevid : parseBool(getOrDefault("cytube_hidevid", false)),
|
hidevid : getOrDefault("hidevid", false),
|
||||||
show_timestamps : parseBool(getOrDefault("cytube_show_timestamps", false)),
|
show_timestamps : getOrDefault("show_timestamps", true),
|
||||||
modhat : parseBool(getOrDefault("cytube_modhat", false)),
|
modhat : getOrDefault("modhat", false),
|
||||||
blink_title : parseBool(getOrDefault("cytube_blink_title", false)),
|
blink_title : getOrDefault("blink_title", false),
|
||||||
sync_accuracy : parseFloat(getOrDefault("cytube_sync_accuracy", 2)) || 2,
|
sync_accuracy : getOrDefault("sync_accuracy", 2),
|
||||||
chatbtn : parseBool(getOrDefault("cytube_chatbtn", false)),
|
chatbtn : getOrDefault("chatbtn", false),
|
||||||
altsocket : parseBool(getOrDefault("cytube_altsocket", false))
|
altsocket : getOrDefault("altsocket", false)
|
||||||
};
|
};
|
||||||
applyOpts();
|
applyOpts();
|
||||||
$("#optlink").click(showUserOpts);
|
$("#optlink").click(showUserOpts);
|
||||||
|
|
|
@ -1142,7 +1142,7 @@ function showUserOpts() {
|
||||||
|
|
||||||
function saveOpts() {
|
function saveOpts() {
|
||||||
for(var key in USEROPTS) {
|
for(var key in USEROPTS) {
|
||||||
createCookie("cytube_"+key, USEROPTS[key], 100);
|
localStorage.setItem(key, USEROPTS[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue