]> git.earman.xyz Git - sensor-watch.git/commitdiff
Save the selected skin of the simulator in local storage
authorHugo Chargois <hugo.chargois@free.fr>
Sat, 16 Sep 2023 00:39:00 +0000 (02:39 +0200)
committerHugo Chargois <hugo.chargois@free.fr>
Sat, 16 Sep 2023 00:39:39 +0000 (02:39 +0200)
watch-library/simulator/shell.html

index c1162f7d3f6e645e1ade0e5426fc10ab51c72948..583829cc506dd2c3538a72bf6df8d17a06c981c4 100644 (file)
   <table cellpadding="5">
     <tr>
       <td id="skinselect">
-        <input type="radio" id="f91w" name="skin" value="f91w" onclick="toggleSkin()" checked><label for="f91w">F-91W</label>
-        <input type="radio" name="skin" id="a158wea" value="a158wea" onclick="toggleSkin()"><label id="a158wea-label" for="a158wea">A158WEA-9</label>
+        <input type="radio" id="f91w" name="skin" value="f91w" onclick="setSkin(this.value)" checked><label for="f91w">F-91W</label>
+        <input type="radio" name="skin" id="a158wea9" value="a158wea9" onclick="setSkin(this.value)"><label id="a158wea-label" for="a158wea9">A158WEA-9</label>
       </td>
       <td>
         <a href="https://github.com/alexisphilip/Casio-F-91W">Original F-91W SVG</a> is &copy; 2020 Alexis Philip,<br>used here under the terms of the MIT license.
     }
   }
 
-  function toggleSkin() {
-    var isBlack = document.getElementById('f91w').checked;
-    Array.from(document.getElementsByClassName("f91w")).forEach(
-        function(element, index, array) {
-            element.setAttribute('style', 'display:' + (isBlack ? 'inline':'none') + ';');
+  const validSkins = ["f91w", "a158wea9"];
+  function setSkin(chosenSkin) {
+    setLocalPref("skin", chosenSkin);
+    validSkins.forEach(function(skin) {
+      Array.from(document.getElementsByClassName(skin)).forEach(
+        function(element) {
+          element.setAttribute('style', 'display:' + (skin == chosenSkin ? 'inline':'none') + ';');
         }
-    );
-    Array.from(document.getElementsByClassName("a158wea9")).forEach(
-        function(element, index, array) {
-            element.setAttribute('style', 'display:' + (isBlack ? 'none':'inline') + ';');
-        }
-    );
+      );
+    });
   }
-  toggleSkin();
 
   // emulator runs on localhost:8000 which could very well be used by other
   // things, so we'll scope our localStorage keys with a prefix
     }
     document.getElementById("volume").value = vol;
     setVolume(vol);
+
+    let skin = getLocalPref("skin", "f91w");
+    if (!validSkins.includes(skin)) {
+      skin = "f91w";
+    }
+    document.getElementById(skin).checked = true;
+    setSkin(skin);
   }
   loadPrefs();
 </script>