thrimbletrimmer: Fix lack of usage of var throughout code

Chalk this one up to not knowing the language.
You need to declare variables as var otherwise they're implicitly globals.

This leads to many bugs where if a function runs twice at once it'll do weird things.
pull/134/head
Mike Lang 5 years ago
parent 8accc1338e
commit 671079861a

@ -53,8 +53,8 @@ pageSetup = function() {
setOptions('uploadLocation', data.upload_locations); setOptions('uploadLocation', data.upload_locations);
// Default time range to the last 10min. This is useful for immediate replay, etc. // Default time range to the last 10min. This is useful for immediate replay, etc.
end = new Date(); var end = new Date();
start = new Date(end.getTime() - 1000*60*10); var start = new Date(end.getTime() - 1000*60*10);
setTimeRange(start, end); setTimeRange(start, end);
loadPlaylist(); loadPlaylist();
@ -70,13 +70,13 @@ toBustime = function(date) {
}; };
fromBustime = function(bustime) { fromBustime = function(bustime) {
direction = 1; var direction = 1;
if(bustime.startsWith("-")) { if(bustime.startsWith("-")) {
bustime = bustime.slice(1); bustime = bustime.slice(1);
direction = -1; direction = -1;
} }
parts = bustime.split(':') var parts = bustime.split(':')
bustime_ms = (parseInt(parts[0]) + parts[1]/60 + parts[2]/3600) * 1000 * 60 * 60; var bustime_ms = (parseInt(parts[0]) + parts[1]/60 + parts[2]/3600) * 1000 * 60 * 60;
return new Date(desertBusStart.getTime() + direction * bustime_ms); return new Date(desertBusStart.getTime() + direction * bustime_ms);
}; };
@ -91,7 +91,7 @@ fromTimestamp = function(ts) {
// Set the stream start/end range from a pair of Dates using the current format // Set the stream start/end range from a pair of Dates using the current format
// If given null, sets to blank. // If given null, sets to blank.
setTimeRange = function(start, end) { setTimeRange = function(start, end) {
toFunc = { var toFunc = {
UTC: toTimestamp, UTC: toTimestamp,
BUSTIME: toBustime, BUSTIME: toBustime,
}[timeFormat]; }[timeFormat];
@ -103,13 +103,13 @@ setTimeRange = function(start, end) {
// Returns an object containing 'start' and 'end' fields. // Returns an object containing 'start' and 'end' fields.
// If either is empty / invalid, returns null. // If either is empty / invalid, returns null.
getTimeRange = function() { getTimeRange = function() {
fromFunc = { var fromFunc = {
UTC: fromTimestamp, UTC: fromTimestamp,
BUSTIME: fromBustime, BUSTIME: fromBustime,
}[timeFormat]; }[timeFormat];
convert = function(value) { convert = function(value) {
if (!value) { return null; } if (!value) { return null; }
date = fromFunc(value); var date = fromFunc(value);
return (isNaN(date)) ? null : date; return (isNaN(date)) ? null : date;
}; };
return { return {
@ -130,7 +130,7 @@ toggleUltrawide = function() {
toggleTimeInput = function(toggleInput) { toggleTimeInput = function(toggleInput) {
// Get times using current format, then change format, then write them back // Get times using current format, then change format, then write them back
range = getTimeRange(); var range = getTimeRange();
timeFormat = toggleInput; timeFormat = toggleInput;
setTimeRange(range.start, range.end); setTimeRange(range.start, range.end);
} }
@ -214,7 +214,7 @@ thrimbletrimmerSubmit = function(state) {
}) })
.then(response => response.text().then(text => { .then(response => response.text().then(text => {
if (!response.ok) { if (!response.ok) {
error = response.statusText + ": " + text; var error = response.statusText + ": " + text;
console.log(error); console.log(error);
alert(error); alert(error);
} else if (state == 'EDITED') { } else if (state == 'EDITED') {
@ -250,7 +250,7 @@ thrimbletrimmerDownload = function() {
thrimbletrimmerManualLink = function() { thrimbletrimmerManualLink = function() {
document.getElementById("ManualButton").disabled = true; document.getElementById("ManualButton").disabled = true;
var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1]; var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1];
body = {link: document.getElementById("ManualLink").value}; var body = {link: document.getElementById("ManualLink").value};
if (!!user) { if (!!user) {
body.token = user.getAuthResponse().id_token; body.token = user.getAuthResponse().id_token;
} }
@ -264,7 +264,7 @@ thrimbletrimmerManualLink = function() {
}) })
.then(response => response.text().then(text => { .then(response => response.text().then(text => {
if (!response.ok) { if (!response.ok) {
error = response.statusText + ": " + text; var error = response.statusText + ": " + text;
console.log(error); console.log(error);
alert(error); alert(error);
document.getElementById("ManualButton").disabled = false; document.getElementById("ManualButton").disabled = false;
@ -287,7 +287,7 @@ thrimbletrimmerResetLink = function() {
return; return;
} }
document.getElementById("ResetButton").disabled = true; document.getElementById("ResetButton").disabled = true;
body = {} var body = {}
if (!!user) { if (!!user) {
body.token = user.getAuthResponse().id_token; body.token = user.getAuthResponse().id_token;
} }
@ -301,7 +301,7 @@ thrimbletrimmerResetLink = function() {
}) })
.then(response => response.text().then(text => { .then(response => response.text().then(text => {
if (!response.ok) { if (!response.ok) {
error = response.statusText + ": " + text; var error = response.statusText + ": " + text;
console.log(error); console.log(error);
alert(error); alert(error);
document.getElementById("ResetButton").disabled = false; document.getElementById("ResetButton").disabled = false;

@ -39,7 +39,7 @@ function setupPlayer(source, startTrim, endTrim) {
this.vhs.playlists.on('loadedmetadata', function() { this.vhs.playlists.on('loadedmetadata', function() {
// setTimeout(function() { player.play(); }, 1000); // setTimeout(function() { player.play(); }, 1000);
player.hasStarted(true); //So it displays all the controls. player.hasStarted(true); //So it displays all the controls.
stream_start = player.vhs.playlists.master.playlists.filter(playlist => typeof playlist.discontinuityStarts !== "undefined")[0].dateTimeObject; var stream_start = player.vhs.playlists.master.playlists.filter(playlist => typeof playlist.discontinuityStarts !== "undefined")[0].dateTimeObject;
startTrim = startTrim ? (new Date(startTrim+"Z")-stream_start)/1000:0; startTrim = startTrim ? (new Date(startTrim+"Z")-stream_start)/1000:0;
endTrim = endTrim ? (new Date(endTrim+"Z")-stream_start)/1000:player.duration(); endTrim = endTrim ? (new Date(endTrim+"Z")-stream_start)/1000:player.duration();
var trimmingControls = player.trimmingControls({ startTrim:startTrim, endTrim:endTrim }); var trimmingControls = player.trimmingControls({ startTrim:startTrim, endTrim:endTrim });
@ -56,7 +56,6 @@ function setupPlayer(source, startTrim, endTrim) {
}) })
}); });
var hlsQS = player.hlsQualitySelector(); var hlsQS = player.hlsQualitySelector();
//var trimmingControls = player.trimmingControls({ startTrim:(startTrim ? startTrim:0), endTrim:(endTrim ? endTrim:player.duration()) });
} }
mapDiscontinuities = function() { mapDiscontinuities = function() {

Loading…
Cancel
Save