persistence_set/get functions, save the join/part status

This commit is contained in:
mappu 2017-02-05 16:11:52 +13:00
parent e9b3fedb17
commit 2c94713ba0

View File

@ -258,9 +258,7 @@ var submit = function() {
if (hub_state === 0) {
hub_state = 1;
if (window.localStorage) {
localStorage["login"] = str;
}
persistence_set("login", str);
var name_parts = str.split(":", 2);
hub_last_nick = name_parts[0];
@ -594,6 +592,7 @@ var joinparts_getstr = function() {
var toggle_joinparts = function(ev) {
var $el = ev.target || ev.srcElement;
show_joins = ! show_joins;
persistence_set("show_joins", show_joins);
$el.innerHTML = joinparts_getstr();
};
@ -609,7 +608,7 @@ var updateTitle = function() {
var sock = {};
var hub_state = 0; // [disconnected, sent-nick, connected]
var hub_last_nick = '';
var hub_hubname = 'DCWebUI';
var hub_hubname = DCWEBUI_CONF.title;
var pm_tabs = {}; // nick => tabid
var next_tabid = 1;
@ -619,15 +618,27 @@ var last_tab = "tab-main";
var show_joins = false;
/* */
var persistence_set = function(key, value) {
if (window.localStorage) {
window.localStorage[key] = JSON.stringify(value);
}
};
var persistence_get = function(key, fallback) {
try {
return JSON.parse( window.localStorage[key] );
} catch (ex) {
return fallback;
}
};
window.onload = function() {
write("tab-main").system("Communicating with server...");
if (window.localStorage) {
var saved_login = localStorage["login"];
if (saved_login !== undefined) {
$("#chatbox").value = saved_login;
}
}
$("#chatbox").value = persistence_get("login", "");
show_joins = persistence_get("show_joins", false);
document.title = DCWEBUI_CONF.title;