fix eslint errors
authorLaurent Mazet <mazet@softndesign.org>
Tue, 18 Aug 2020 12:34:42 +0000 (14:34 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Tue, 18 Aug 2020 12:34:42 +0000 (14:34 +0200)
public/trivabble.js

index 78361c2846b0163478e86e5b9d9ce7cd3b876d6c..88ea1893aae78b009302514e3922d8ec8240d25b 100644 (file)
 
     const trivabble = window.trivabble = {l10n: _};
 
-    function format(s, v1, v2, v3, v4) {
-        return s.replace("{0}", v1).replace("{1}", v2).replace("{2}", v3).replace("{3}", v4);
+    function format(s, ...v) {
+        for (let i = 0; i < v.length; i++) {
+            s = s.replace("{" + i + "}", v[i]);
+        }
+        return s;
     }
 
     let board;
     }
 
     function timerString(delta) {
-        let d = Math.floor(delta / (60 * 60 * 24));
-        let h = Math.floor((delta % (60 * 60 * 24)) / (60 * 60));
-        let m = Math.floor((delta % (60 * 60)) / 60);
-        let s = Math.floor(delta % 60);
+        const d = Math.floor(delta / (60 * 60 * 24));
+        const h = Math.floor((delta % (60 * 60 * 24)) / (60 * 60));
+        const m = Math.floor((delta % (60 * 60)) / 60);
+        const s = Math.floor(delta % 60);
         return format(_("{0}d {1}h {2}m {3}s"), d, h, m, s);
     }
 
         if (!Object.prototype.hasOwnProperty.call(localStorage, "timerEnable")) {
             localStorage.timerEnable = Conf.ENABLE_TIMER;
         }
-        document.getElementById("enable-timer").onclick = function() {
+        document.getElementById("enable-timer").onclick = function () {
             setTimerState(document.getElementById("enable-timer").checked);
         };
-        setTimerState (localStorage.timerEnable);
+        setTimerState(localStorage.timerEnable);
     }
 
     function setTimerState(state) {
         if (state) {
             document.getElementById("timer").style.display = "block";
             document.getElementById("enable-timer").checked = true;
-            localStorage.timer = setInterval(function() {
-                document.getElementById("timer-turn").innerHTML = timerString(++localStorage.timerTurn)
+            localStorage.timer = setInterval(function () {
+                document.getElementById("timer-turn").innerHTML = timerString(++localStorage.timerTurn);
                 document.getElementById("timer-global").innerHTML = timerString(++localStorage.timerGlobal);
             }, 1000);
         } else {
             document.getElementById("enable-timer").checked = false;
             if (Object.prototype.hasOwnProperty.call(localStorage, "timer")) {
                 clearInterval(localStorage.timer);
-                delete(localStorage.timer);
+                delete localStorage.timer;
             }
             localStorage.timerGlobal = localStorage.timerTurn = 0;
         }
                 _("It seems your did not give your name. You need to do it for the game to run properly."),
                 function (name) {
                     if (name && name.trim()) {
-                        localStorage.trivabblePlayerName = name1111111111111.trim();
+                        localStorage.trivabblePlayerName = name.trim();
                     }
 
                     repromptName(f);