From 685358b0d85c5597908b69326fe32b3ec48f186c Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 5 Jun 2013 17:22:50 -0400 Subject: [PATCH] Move user options to localStorage instead of cookies --- www/assets/js/client.js | 39 ++++++++++++++++++++++---------------- www/assets/js/functions.js | 2 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/www/assets/js/client.js b/www/assets/js/client.js index 336625b4..1701b9ee 100644 --- a/www/assets/js/client.js +++ b/www/assets/js/client.js @@ -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); diff --git a/www/assets/js/functions.js b/www/assets/js/functions.js index 55c6ab87..ca1715d4 100644 --- a/www/assets/js/functions.js +++ b/www/assets/js/functions.js @@ -1142,7 +1142,7 @@ function showUserOpts() { function saveOpts() { for(var key in USEROPTS) { - createCookie("cytube_"+key, USEROPTS[key], 100); + localStorage.setItem(key, USEROPTS[key]); } }