From: Christian Heller Date: Sun, 8 Nov 2020 00:50:21 +0000 (+0100) Subject: Use local storage for web client cusotmizations. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/error?a=commitdiff_plain;h=652d60dc7fbb14a32135a5630d62b9a506f70747;p=plomrogue2-experiments Use local storage for web client cusotmizations. --- diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html index d789e6c..54f60c4 100644 --- a/new2/rogue_chat_nocanvas_monochrome.html +++ b/new2/rogue_chat_nocanvas_monochrome.html @@ -37,6 +37,18 @@ let rows_selector = document.getElementById("n_rows"); let cols_selector = document.getElementById("n_cols"); let key_selectors = document.querySelectorAll('[id^="key_"]'); +function restore_selector_value(selector) { + let stored_selection = window.localStorage.getItem(selector.id); + if (stored_selection) { + selector.value = stored_selection; + } +} +restore_selector_value(rows_selector); +restore_selector_value(cols_selector); +for (let key_selector of key_selectors) { + restore_selector_value(key_selector); +} + let terminal = { foreground: 'white', background: 'black', @@ -168,10 +180,10 @@ let server = { tui.log_msg("@ server disconnected :("); tui.log_msg("@ hint: try the '/reconnect' command"); }; - this.websocket.onmessage = this.handle_event; - }, + this.websocket.onmessage = this.handle_event; + }, reconnect: function() { - this.reconnect_to(this.url); + this.reconnect_to(this.url); }, reconnect_to: function(url) { this.websocket.close(); @@ -768,6 +780,7 @@ rows_selector.addEventListener('input', function() { if (rows_selector.value % 4 != 0) { return; } + window.localStorage.setItem(rows_selector.id, rows_selector.value); terminal.initialize(); tui.full_refresh(); }, false); @@ -775,12 +788,14 @@ cols_selector.addEventListener('input', function() { if (cols_selector.value % 4 != 0) { return; } + window.localStorage.setItem(cols_selector.id, cols_selector.value); terminal.initialize(); tui.window_width = terminal.cols / 2, tui.full_refresh(); }, false); for (let key_selector of key_selectors) { key_selector.addEventListener('input', function() { + window.localStorage.setItem(key_selector.id, key_selector.value); tui.init_keys(); }, false); }