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);
|
||||
}
|
||||
|
||||
function getOrDefault(cookie, def) {
|
||||
var cook = readCookie(cookie);
|
||||
if(cook === null) {
|
||||
getOrDefault = function(k, def) {
|
||||
var v = localStorage.getItem(k);
|
||||
if(v === null)
|
||||
return def;
|
||||
}
|
||||
return cook;
|
||||
if(v === "true")
|
||||
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 = {
|
||||
theme : getOrDefault("cytube_theme", "default"),
|
||||
css : getOrDefault("cytube_css", ""),
|
||||
layout : getOrDefault("cytube_layout", "default"),
|
||||
synch : parseBool(getOrDefault("cytube_synch", true)),
|
||||
hidevid : parseBool(getOrDefault("cytube_hidevid", false)),
|
||||
show_timestamps : parseBool(getOrDefault("cytube_show_timestamps", false)),
|
||||
modhat : parseBool(getOrDefault("cytube_modhat", false)),
|
||||
blink_title : parseBool(getOrDefault("cytube_blink_title", false)),
|
||||
sync_accuracy : parseFloat(getOrDefault("cytube_sync_accuracy", 2)) || 2,
|
||||
chatbtn : parseBool(getOrDefault("cytube_chatbtn", false)),
|
||||
altsocket : parseBool(getOrDefault("cytube_altsocket", false))
|
||||
theme : getOrDefault("theme", "default"),
|
||||
css : getOrDefault("css", ""),
|
||||
layout : getOrDefault("layout", "default"),
|
||||
synch : getOrDefault("synch", true),
|
||||
hidevid : getOrDefault("hidevid", false),
|
||||
show_timestamps : getOrDefault("show_timestamps", true),
|
||||
modhat : getOrDefault("modhat", false),
|
||||
blink_title : getOrDefault("blink_title", false),
|
||||
sync_accuracy : getOrDefault("sync_accuracy", 2),
|
||||
chatbtn : getOrDefault("chatbtn", false),
|
||||
altsocket : getOrDefault("altsocket", false)
|
||||
};
|
||||
applyOpts();
|
||||
$("#optlink").click(showUserOpts);
|
||||
|
|
|
@ -1142,7 +1142,7 @@ function showUserOpts() {
|
|||
|
||||
function saveOpts() {
|
||||
for(var key in USEROPTS) {
|
||||
createCookie("cytube_"+key, USEROPTS[key], 100);
|
||||
localStorage.setItem(key, USEROPTS[key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue