From fea2c3d63b3688db9d3e08ddd894925a356cdb2e Mon Sep 17 00:00:00 2001 From: Simon Hill Date: Wed, 30 Aug 2023 09:48:54 +0100 Subject: [PATCH] feat: adding drop function to remove bad laps --- README.md | 1 + public/timer.css | 4 ++++ public/timer.js | 19 +++++++++++++++++++ src/http/get-timer/index.js | 1 + views/timer.ejs | 1 + 5 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 38479e7..71ca21e 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,4 @@ | Reset | R | | Clear | T | | Squeeze | Y | +| Drop | D | diff --git a/public/timer.css b/public/timer.css index 4f87d08..9d0097a 100644 --- a/public/timer.css +++ b/public/timer.css @@ -54,6 +54,10 @@ html { color: #ddd; } +.btn_drop { + color: #93e; +} + .limiter { font-size: 6vw; position: fixed; diff --git a/public/timer.js b/public/timer.js index d430013..754308e 100644 --- a/public/timer.js +++ b/public/timer.js @@ -191,6 +191,20 @@ class Timer { this.start(); } + drop() { + console.log(`running drop`); + if (this.records.length == 0) { + return; + } + console.log(`drop ${this.results.lastChild.innerText}`); + this.results.removeChild(this.results.lastChild); + // update bestlap + this.records.splice(this.records.length - 1, 1); + this.sorted = this.records.slice(); + this.sorted.sort(compare); + this.bestlap.innerText = this.format(this.sorted[0]); + } + format(times) { return `${lpad(times[0], 2)}:${lpad(times[1], 2)}.${lpad(Math.floor(times[2]), 3)}`; } @@ -265,6 +279,9 @@ function exec(name) { case 'squeeze': timer.squeeze(); break; + case 'drop': + timer.drop(); + break; } } @@ -275,6 +292,7 @@ let key_map = { '82': 'reset', // r '84': 'clear', // t '89': 'squeeze', // y + '68': 'drop', // d }; document.addEventListener('keydown', function (event) { @@ -294,3 +312,4 @@ document.getElementById('btn_pause').addEventListener('click', btn_listener); document.getElementById('btn_passed').addEventListener('click', btn_listener); document.getElementById('btn_reset').addEventListener('click', btn_listener); document.getElementById('btn_clear').addEventListener('click', btn_listener); +document.getElementById('btn_drop').addEventListener('click', btn_listener); diff --git a/src/http/get-timer/index.js b/src/http/get-timer/index.js index fc867ea..6264995 100644 --- a/src/http/get-timer/index.js +++ b/src/http/get-timer/index.js @@ -28,6 +28,7 @@ exports.handler = async function http(req) { Passed Reset Clear + Drop
diff --git a/views/timer.ejs b/views/timer.ejs index a1b4939..1fc10a4 100644 --- a/views/timer.ejs +++ b/views/timer.ejs @@ -14,6 +14,7 @@ Passed Reset Clear + Drop