thrimbletrimmer: Use "function NAME(...)" instead of "NAME = function (...)"

It's less confusing and more like other languages
pull/225/head
Mike Lang 3 years ago committed by Mike Lang
parent ce73f7b0ea
commit 241d302220

@ -1,7 +1,7 @@
var desertBusStart = new Date("1970-01-01T00:00:00Z"); var desertBusStart = new Date("1970-01-01T00:00:00Z");
var timeFormat = "AGO"; var timeFormat = "AGO";
pageSetup = function (isEditor) { function pageSetup(isEditor) {
//Get values from ThrimShim //Get values from ThrimShim
if (isEditor && /id=/.test(document.location.search)) { if (isEditor && /id=/.test(document.location.search)) {
var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1]; var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1];
@ -101,7 +101,7 @@ pageSetup = function (isEditor) {
// Time-formatting functions // Time-formatting functions
parseDuration = function (duration) { function parseDuration(duration) {
var direction = 1; var direction = 1;
if (duration.startsWith("-")) { if (duration.startsWith("-")) {
duration = duration.slice(1); duration = duration.slice(1);
@ -113,26 +113,26 @@ parseDuration = function (duration) {
); );
}; };
toBustime = function (date) { function toBustime(date) {
return ( return (
(date < desertBusStart ? "-" : "") + (date < desertBusStart ? "-" : "") +
videojs.formatTime(Math.abs((date - desertBusStart) / 1000), 600.01).padStart(7, "0:") videojs.formatTime(Math.abs((date - desertBusStart) / 1000), 600.01).padStart(7, "0:")
); );
}; };
fromBustime = function (bustime) { function fromBustime(bustime) {
return new Date(desertBusStart.getTime() + 1000 * parseDuration(bustime)); return new Date(desertBusStart.getTime() + 1000 * parseDuration(bustime));
}; };
toTimestamp = function (date) { function toTimestamp(date) {
return date.toISOString().substring(0, 19); return date.toISOString().substring(0, 19);
}; };
fromTimestamp = function (ts) { function fromTimestamp(ts) {
return new Date(ts + "Z"); return new Date(ts + "Z");
}; };
toAgo = function (date) { function toAgo(date) {
now = new Date(); now = new Date();
return ( return (
(date < now ? "" : "-") + (date < now ? "" : "-") +
@ -140,13 +140,13 @@ toAgo = function (date) {
); );
}; };
fromAgo = function (ago) { function fromAgo(ago) {
return new Date(new Date().getTime() - 1000 * parseDuration(ago)); return new Date(new Date().getTime() - 1000 * parseDuration(ago));
}; };
// 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) { function setTimeRange(start, end) {
var toFunc = { var toFunc = {
UTC: toTimestamp, UTC: toTimestamp,
BUSTIME: toBustime, BUSTIME: toBustime,
@ -159,7 +159,7 @@ setTimeRange = function (start, end) {
// Get the current start/end range as Dates using the current format // Get the current start/end range as Dates using the current format
// 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 () { function getTimeRange() {
var fromFunc = { var fromFunc = {
UTC: fromTimestamp, UTC: fromTimestamp,
BUSTIME: fromBustime, BUSTIME: fromBustime,
@ -178,7 +178,7 @@ getTimeRange = function () {
}; };
}; };
getTimeRangeAsTimestamp = function () { function getTimeRangeAsTimestamp() {
var range = getTimeRange(); var range = getTimeRange();
return { return {
// if not null, format as timestamp // if not null, format as timestamp
@ -187,19 +187,19 @@ getTimeRangeAsTimestamp = function () {
}; };
}; };
toggleHiddenPane = function (paneID) { function toggleHiddenPane(paneID) {
var pane = document.getElementById(paneID); var pane = document.getElementById(paneID);
pane.style.display = pane.style.display === "none" ? "block" : "none"; pane.style.display = pane.style.display === "none" ? "block" : "none";
}; };
toggleUltrawide = function () { function toggleUltrawide() {
var body = document.getElementsByTagName("Body")[0]; var body = document.getElementsByTagName("Body")[0];
body.classList.contains("ultrawide") body.classList.contains("ultrawide")
? body.classList.remove("ultrawide") ? body.classList.remove("ultrawide")
: body.classList.add("ultrawide"); : body.classList.add("ultrawide");
}; };
toggleTimeInput = function (toggleInput) { function toggleTimeInput(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
var range = getTimeRange(); var range = getTimeRange();
timeFormat = toggleInput; timeFormat = toggleInput;
@ -209,7 +209,7 @@ toggleTimeInput = function (toggleInput) {
// For a given select input element id, add the given list of options. // For a given select input element id, add the given list of options.
// If selected is given, it should be the name of an option to select. // If selected is given, it should be the name of an option to select.
// Otherwise the first one is used. // Otherwise the first one is used.
setOptions = function (element, options, selected) { function setOptions(element, options, selected) {
if (!selected && options.length > 0) { if (!selected && options.length > 0) {
selected = options[0]; selected = options[0];
} }
@ -225,14 +225,14 @@ setOptions = function (element, options, selected) {
}); });
}; };
buildQuery = function (params) { function buildQuery(params) {
return Object.keys(params) return Object.keys(params)
.filter(key => params[key] !== null) .filter(key => params[key] !== null)
.map(key => encodeURIComponent(key) + "=" + encodeURIComponent(params[key])) .map(key => encodeURIComponent(key) + "=" + encodeURIComponent(params[key]))
.join("&"); .join("&");
}; };
loadPlaylist = function (isEditor, startTrim, endTrim, defaultQuality) { function loadPlaylist(isEditor, startTrim, endTrim, defaultQuality) {
var playlist = "/playlist/" + document.getElementById("StreamName").value + ".m3u8"; var playlist = "/playlist/" + document.getElementById("StreamName").value + ".m3u8";
var range = getTimeRangeAsTimestamp(); var range = getTimeRangeAsTimestamp();
@ -280,7 +280,7 @@ loadPlaylist = function (isEditor, startTrim, endTrim, defaultQuality) {
}); });
}; };
thrimbletrimmerSubmit = function (state, override_changes = false) { function thrimbletrimmerSubmit(state, override_changes = false) {
document.getElementById("SubmitButton").disabled = true; document.getElementById("SubmitButton").disabled = true;
var discontinuities = mapDiscontinuities(); var discontinuities = mapDiscontinuities();
@ -371,7 +371,7 @@ thrimbletrimmerSubmit = function (state, override_changes = false) {
); );
}; };
thrimbletrimmerDownload = function (isEditor) { function thrimbletrimmerDownload(isEditor) {
var range = getTimeRangeAsTimestamp(); var range = getTimeRangeAsTimestamp();
if (isEditor) { if (isEditor) {
if (player.trimmingControls().options.startTrim >= player.trimmingControls().options.endTrim) { if (player.trimmingControls().options.startTrim >= player.trimmingControls().options.endTrim) {
@ -416,7 +416,7 @@ thrimbletrimmerDownload = function (isEditor) {
document.getElementById("DownloadLink").style.display = ""; document.getElementById("DownloadLink").style.display = "";
}; };
thrimbletrimmerManualLink = function () { function thrimbletrimmerManualLink() {
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];
var upload_location = document.getElementById("ManualYoutube").checked var upload_location = document.getElementById("ManualYoutube").checked
@ -453,7 +453,7 @@ thrimbletrimmerManualLink = function () {
); );
}; };
thrimbletrimmerResetLink = function (force) { function thrimbletrimmerResetLink(force) {
var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1]; var rowId = /id=(.*)(?:&|$)/.exec(document.location.search)[1];
if ( if (
force && force &&
@ -498,18 +498,18 @@ thrimbletrimmerResetLink = function (force) {
); );
}; };
tags_list_to_string = function (tag_list) { function tags_list_to_string(tag_list) {
return tag_list.join(", "); return tag_list.join(", ");
}; };
tags_string_to_list = function (tag_string) { function tags_string_to_list(tag_string) {
return tag_string return tag_string
.split(",") .split(",")
.map(tag => tag.trim()) .map(tag => tag.trim())
.filter(tag => tag.length > 0); .filter(tag => tag.length > 0);
}; };
round_trip_tag_string = function () { function round_trip_tag_string() {
var element = document.getElementById("VideoTags"); var element = document.getElementById("VideoTags");
element.value = tags_list_to_string(tags_string_to_list(element.value)); element.value = tags_list_to_string(tags_string_to_list(element.value));
}; };

@ -67,7 +67,7 @@ function setupPlayer(isEditor, source, startTrim, endTrim) {
var hlsQS = player.hlsQualitySelector(); var hlsQS = player.hlsQualitySelector();
} }
mapDiscontinuities = function () { function mapDiscontinuities() {
var playlist = player.vhs.playlists.master.playlists.filter( var playlist = player.vhs.playlists.master.playlists.filter(
playlist => typeof playlist.discontinuityStarts !== "undefined" playlist => typeof playlist.discontinuityStarts !== "undefined"
)[0]; //Only one of the playlists will have the discontinuity or stream start objects, and it's not necessarily the first one or the source one. )[0]; //Only one of the playlists will have the discontinuity or stream start objects, and it's not necessarily the first one or the source one.
@ -94,7 +94,7 @@ mapDiscontinuities = function () {
return discontinuities; return discontinuities;
}; };
getRealTimeForPlayerTime = function (discontinuities, playbackIndex) { function getRealTimeForPlayerTime(discontinuities, playbackIndex) {
var streamStart = player.vhs.playlists.master.playlists.filter( var streamStart = player.vhs.playlists.master.playlists.filter(
playlist => typeof playlist.dateTimeObject !== "undefined" playlist => typeof playlist.dateTimeObject !== "undefined"
)[0].dateTimeObject; //Only one of the playlists will have the discontinuity or stream start objects, and it's not necessarily the first one or the source one. )[0].dateTimeObject; //Only one of the playlists will have the discontinuity or stream start objects, and it's not necessarily the first one or the source one.

Loading…
Cancel
Save