home · contact · privacy
Use local storage for web client cusotmizations.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 8 Nov 2020 00:50:21 +0000 (01:50 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 8 Nov 2020 00:50:21 +0000 (01:50 +0100)
new2/rogue_chat_nocanvas_monochrome.html

index d789e6c8ad54a4e847f2f90aa21f9fe3c42dc31c..54f60c4111e12358a817e1171bee704f0992d7cb 100644 (file)
@@ -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);
 }