From 026858509a413ce8b1c88129c8d2d27061a9c9df Mon Sep 17 00:00:00 2001 From: Evan Gubarev Date: Sun, 7 Feb 2021 10:09:01 -0800 Subject: [PATCH] Fixed getFormattedTime sometimes returning (NaN:NaN) (#643) * Fixed getFormattedTime sometimes returning (NaN:NaN) getFormattedTime() with nothing passed into it and a couple other edge cases returned (NaN:NaN). This is a problem since on a slow machine getFormattedTime get called without anything passed into it around the time the computer is fetching the timing data. I haven't found the exact spot / place it is called wrongly, but this should fix it. I've have a slow machine so it's really been bugging me seeing (NaN:NaN) for a couple seconds before the page fully loads. Hopefully this should fix it. --- src/content.ts | 4 +++- src/utils.ts | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/content.ts b/src/content.ts index e6e87704..67aac19f 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1646,6 +1646,8 @@ function showTimeWithoutSkips(skippedDuration: number): void { display.appendChild(duration); } + + const durationAfterSkips = utils.getFormattedTime(video.duration - skippedDuration) - duration.innerText = skippedDuration <= 0 ? "" : " (" + utils.getFormattedTime(video.duration - skippedDuration) + ")"; + duration.innerText = (durationAfterSkips == null || skippedDuration <= 0) ? "" : " (" + durationAfterSkips + ")"; } diff --git a/src/utils.ts b/src/utils.ts index fd47b27c..f45a5a1c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -376,6 +376,9 @@ class Utils { //add a zero minutesDisplay = "0" + minutesDisplay; } + if (isNaN(hours) || isNaN(minutes)) { + return null; + } const formatted = (hours ? hours + ":" : "") + minutesDisplay + ":" + secondsDisplay;