From 51ac4b6fc1504df129228f682f6e699901a15fe4 Mon Sep 17 00:00:00 2001 From: Stian Aune Date: Thu, 7 Nov 2019 21:52:11 +0100 Subject: [PATCH] Fix me maybe? --- contentScript.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/contentScript.js b/contentScript.js index c25b04d..4e17453 100644 --- a/contentScript.js +++ b/contentScript.js @@ -50,6 +50,8 @@ if (typeof Overlay === "undefined") { this.mCenter.style.left = "50%"; this.mCenter.style.top = "50%"; this.mCenter.style.transform = "translate(-50%, -50%)"; + this.mCenter.style.backgroundColor = "rgba(0, 0, 0, 0.75)"; + this.mCenter.style.fontSize = "4vmax"; this.mBottomRight.id = "overlay-mBottomRight"; this.mBottomRight.style.right = 0; @@ -206,6 +208,7 @@ if (typeof Overlay === "undefined") { async startWorkout(bike, program) { this.bike = bike; this.program = program; + this.milestones = []; const bikeId = bike.id; const programId = program.id; @@ -320,15 +323,26 @@ if (typeof Overlay === "undefined") { } updateMilestones(minutes, calories) { - this.milestones.push({minutes, calories}); + const expected = this.expectedCalories(minutes, 0); + const diff = calories - expected; + + this.milestones.push({minutes, calories, diff}); if (minutes % 5 === 0) { this.milestones = this.milestones.filter(m => m.minutes % 5 === 0) } let lines = ""; - this.milestones.sort((i, j) => j.minutes - i.minutes).forEach(({minutes, calories}) => { - lines += `${minutes}  ${calories}`; + let lastDiff = 0; + this.milestones.sort((i, j) => j.minutes - i.minutes).forEach(({minutes, calories, diff}) => { + let color = this.colors["0"]; + if (diff < 0) { + color = diff < lastDiff ? this.colors["-2"] : this.colors["-1"]; + } else { + color = diff > lastDiff ? this.colors["2"] : this.colors["1"]; + } + + lines += `${minutes}  ${calories}`; }); if (lines.length > 0) {