Made the time appear more nicely formatted.

This commit is contained in:
Ajay Ramachandran
2019-07-09 18:10:45 -04:00
parent 63ecc88392
commit ad1b1b6f8b

View File

@@ -142,7 +142,7 @@ function getVideoTimesMessage(sponsorTimes) {
for (let i = 0; i < sponsorTimes.length; i++) { for (let i = 0; i < sponsorTimes.length; i++) {
for (let s = 0; s < sponsorTimes[i].length; s++) { for (let s = 0; s < sponsorTimes[i].length; s++) {
let timeMessage = sponsorTimes[i][s].toFixed(1) + "s"; let timeMessage = getFormattedTime(sponsorTimes[i][s]);
//if this is an end time //if this is an end time
if (s == 1) { if (s == 1) {
timeMessage = " to " + timeMessage; timeMessage = " to " + timeMessage;
@@ -176,6 +176,15 @@ function submitTimes() {
}); });
} }
//converts time in seconds to minutes:seconds
function getFormattedTime(seconds) {
let minutes = Math.floor(seconds / 60);
let secondsDisplay = Math.round(seconds - minutes * 60);
let formatted = minutes+ ":" + secondsDisplay;
return formatted;
}
function getYouTubeVideoID(url) { // Return video id or false function getYouTubeVideoID(url) { // Return video id or false
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp); var match = url.match(regExp);