From a69bee0548c84e9affc4cd6134b1e9a0e3ce5b2d Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Sun, 12 Sep 2021 21:29:59 +1000 Subject: [PATCH] thrimbletrimmer: Replace var with let/const and other related bits --- thrimbletrimmer/scripts/IO.js | 85 ++++++++++---------- thrimbletrimmer/scripts/keyboardShortcuts.js | 6 +- thrimbletrimmer/scripts/playerSetup.js | 44 ++++------ 3 files changed, 61 insertions(+), 74 deletions(-) diff --git a/thrimbletrimmer/scripts/IO.js b/thrimbletrimmer/scripts/IO.js index 8ab7193..da844f3 100644 --- a/thrimbletrimmer/scripts/IO.js +++ b/thrimbletrimmer/scripts/IO.js @@ -1,10 +1,10 @@ -var desertBusStart = new Date("1970-01-01T00:00:00Z"); -var timeFormat = "AGO"; +let desertBusStart = new Date("1970-01-01T00:00:00Z"); +let timeFormat = "AGO"; function pageSetup(isEditor) { //Get values from ThrimShim if (isEditor && /id=/.test(document.location.search)) { - var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1]; + const rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1]; fetch("/thrimshim/" + rowId) .then(data => data.json()) .then(function (data) { @@ -24,10 +24,10 @@ function pageSetup(isEditor) { // Apply padding - start 1min early, finish 2min late because these times are generally // rounded down to the minute, so if something ends at "00:10" it might actually end // at 00:10:59 so we should pad to 00:12:00. - var start = data.event_start + const start = data.event_start ? new Date(fromTimestamp(data.event_start).getTime() - 60 * 1000) : null; - var end = data.event_end + const end = data.event_end ? new Date(fromTimestamp(data.event_end).getTime() + 2 * 60 * 1000) : null; setTimeRange(start, end); @@ -102,12 +102,12 @@ function pageSetup(isEditor) { // Time-formatting functions function parseDuration(duration) { - var direction = 1; + let direction = 1; if (duration.startsWith("-")) { duration = duration.slice(1); direction = -1; } - var parts = duration.split(":"); + const parts = duration.split(":"); return ( (parseInt(parts[0]) + (parts[1] || "0") / 60 + (parts[2] || "0") / 3600) * 60 * 60 * direction ); @@ -147,7 +147,7 @@ function fromAgo(ago) { // Set the stream start/end range from a pair of Dates using the current format // If given null, sets to blank. function setTimeRange(start, end) { - var toFunc = { + const toFunc = { UTC: toTimestamp, BUSTIME: toBustime, AGO: toAgo, @@ -160,16 +160,16 @@ function setTimeRange(start, end) { // Returns an object containing 'start' and 'end' fields. // If either is empty / invalid, returns null. function getTimeRange() { - var fromFunc = { + const fromFunc = { UTC: fromTimestamp, BUSTIME: fromBustime, AGO: fromAgo, }[timeFormat]; - var convert = function (value) { + function convert(value) { if (!value) { return null; } - var date = fromFunc(value); + const date = fromFunc(value); return isNaN(date) ? null : date; }; return { @@ -179,7 +179,7 @@ function getTimeRange() { }; function getTimeRangeAsTimestamp() { - var range = getTimeRange(); + const range = getTimeRange(); return { // if not null, format as timestamp start: range.start && toTimestamp(range.start), @@ -188,12 +188,12 @@ function getTimeRangeAsTimestamp() { }; function toggleHiddenPane(paneID) { - var pane = document.getElementById(paneID); + const pane = document.getElementById(paneID); pane.style.display = pane.style.display === "none" ? "block" : "none"; }; function toggleUltrawide() { - var body = document.getElementsByTagName("Body")[0]; + const body = document.getElementsByTagName("Body")[0]; body.classList.contains("ultrawide") ? body.classList.remove("ultrawide") : body.classList.add("ultrawide"); @@ -201,7 +201,7 @@ function toggleUltrawide() { function toggleTimeInput(toggleInput) { // Get times using current format, then change format, then write them back - var range = getTimeRange(); + const range = getTimeRange(); timeFormat = toggleInput; setTimeRange(range.start, range.end); }; @@ -213,7 +213,7 @@ function setOptions(element, options, selected) { if (!selected && options.length > 0) { selected = options[0]; } - options.forEach(function (option) { + options.forEach(option => { document.getElementById(element).innerHTML += '