2019-07-10 04:10:25 +02:00
//setup click listeners
2019-07-09 05:43:06 +02:00
document . getElementById ( "sponsorStart" ) . addEventListener ( "click" , sendSponsorStartMessage ) ;
document . getElementById ( "clearTimes" ) . addEventListener ( "click" , clearTimes ) ;
2019-07-09 21:55:33 +02:00
document . getElementById ( "submitTimes" ) . addEventListener ( "click" , submitTimes ) ;
2019-07-10 04:10:25 +02:00
document . getElementById ( "showNoticeAgain" ) . addEventListener ( "click" , showNoticeAgain ) ;
2019-07-13 01:04:24 +02:00
document . getElementById ( "hideVideoPlayerControls" ) . addEventListener ( "click" , hideVideoPlayerControls ) ;
document . getElementById ( "showVideoPlayerControls" ) . addEventListener ( "click" , showVideoPlayerControls ) ;
2019-07-13 01:11:09 +02:00
document . getElementById ( "optionsButton" ) . addEventListener ( "click" , openOptions ) ;
2019-07-18 04:53:42 +02:00
document . getElementById ( "reportAnIssue" ) . addEventListener ( "click" , reportAnIssue ) ;
2019-07-09 05:43:06 +02:00
//if true, the button now selects the end time
var startTimeChosen = false ;
//the start and end time pairs (2d)
2019-07-10 01:46:55 +02:00
var sponsorTimes = [ ] ;
2019-07-09 05:43:06 +02:00
2019-07-09 22:36:06 +02:00
//current video ID of this tab
var currentVideoID = null ;
2019-07-09 05:43:06 +02:00
2019-07-09 23:51:49 +02:00
//is this a YouTube tab?
var isYouTubeTab = false ;
2019-07-10 04:10:25 +02:00
//if the don't show notice again variable is true, an option to
// disable should be available
2019-07-22 22:42:57 +02:00
chrome . storage . sync . get ( [ "dontShowNoticeAgain" ] , function ( result ) {
2019-07-10 04:10:25 +02:00
let dontShowNoticeAgain = result . dontShowNoticeAgain ;
if ( dontShowNoticeAgain != undefined && dontShowNoticeAgain ) {
document . getElementById ( "showNoticeAgain" ) . style . display = "unset" ;
}
} ) ;
2019-07-13 01:04:24 +02:00
//show proper video player controls option
2019-07-22 22:42:57 +02:00
chrome . storage . sync . get ( [ "hideVideoPlayerControls" ] , function ( result ) {
2019-07-13 01:04:24 +02:00
let hideVideoPlayerControls = result . hideVideoPlayerControls ;
if ( hideVideoPlayerControls != undefined && hideVideoPlayerControls ) {
document . getElementById ( "hideVideoPlayerControls" ) . style . display = "none" ;
document . getElementById ( "showVideoPlayerControls" ) . style . display = "unset" ;
}
} ) ;
2019-07-23 01:08:21 +02:00
//get the amount of times this user has contributed and display it to thank them
chrome . storage . sync . get ( [ "sponsorTimesContributed" ] , function ( result ) {
if ( result . sponsorTimesContributed != undefined ) {
2019-07-24 00:32:05 +02:00
let sponsorTimesContributionsContainer = document . getElementById ( "sponsorTimesContributionsContainer" ) ;
2019-07-23 01:08:21 +02:00
let sponsorTimesContributionsDisplay = document . getElementById ( "sponsorTimesContributionsDisplay" ) ;
2019-07-24 00:32:05 +02:00
let sponsorTimesContributionsDisplayEndWord = document . getElementById ( "sponsorTimesContributionsDisplayEndWord" ) ;
2019-07-23 01:08:21 +02:00
if ( result . sponsorTimesContributed > 1 ) {
2019-07-24 00:32:05 +02:00
sponsorTimesContributionsDisplayEndWord . innerText = "sponsors."
2019-07-23 01:08:21 +02:00
} else {
2019-07-24 00:32:05 +02:00
sponsorTimesContributionsDisplayEndWord . innerText = "sponsor."
2019-07-23 01:08:21 +02:00
}
2019-07-24 00:32:05 +02:00
sponsorTimesContributionsDisplay . innerText = result . sponsorTimesContributed ;
sponsorTimesContributionsContainer . style . display = "unset" ;
//get the userID
chrome . storage . sync . get ( [ "userID" ] , function ( result ) {
let userID = result . userID ;
if ( userID != undefined ) {
//there are probably some views on these submissions then
//get the amount of views from the sponsors submitted
sendRequestToServer ( "GET" , "/api/getViewsForUser?userID=" + userID , function ( xmlhttp ) {
if ( xmlhttp . readyState == 4 && xmlhttp . status == 200 ) {
let viewCount = JSON . parse ( xmlhttp . responseText ) . viewCount ;
if ( viewCount != 0 ) {
let sponsorTimesViewsContainer = document . getElementById ( "sponsorTimesViewsContainer" ) ;
let sponsorTimesViewsDisplay = document . getElementById ( "sponsorTimesViewsDisplay" ) ;
let sponsorTimesViewsDisplayEndWord = document . getElementById ( "sponsorTimesViewsDisplayEndWord" ) ;
if ( viewCount > 1 ) {
sponsorTimesViewsDisplayEndWord . innerText = "sponsor segments."
} else {
sponsorTimesViewsDisplayEndWord . innerText = "sponsor segment."
}
sponsorTimesViewsDisplay . innerText = viewCount ;
sponsorTimesViewsContainer . style . display = "unset" ;
}
}
} ) ;
}
} ) ;
2019-07-23 01:08:21 +02:00
}
} ) ;
2019-07-24 00:32:05 +02:00
2019-07-09 06:05:27 +02:00
chrome . tabs . query ( {
active : true ,
currentWindow : true
2019-07-09 22:36:06 +02:00
} , loadTabData ) ;
function loadTabData ( tabs ) {
//set current videoID
currentVideoID = getYouTubeVideoID ( tabs [ 0 ] . url ) ;
2019-07-10 18:04:30 +02:00
if ( ! currentVideoID ) {
//this isn't a YouTube video then
displayNoVideo ( ) ;
return ;
}
2019-07-09 22:36:06 +02:00
//load video times for this video
2019-07-10 01:46:55 +02:00
let sponsorTimeKey = "sponsorTimes" + currentVideoID ;
2019-07-22 22:42:57 +02:00
chrome . storage . sync . get ( [ sponsorTimeKey ] , function ( result ) {
2019-07-10 03:53:07 +02:00
let sponsorTimesStorage = result [ sponsorTimeKey ] ;
2019-07-10 04:23:35 +02:00
if ( sponsorTimesStorage != undefined && sponsorTimesStorage . length > 0 ) {
2019-07-10 03:53:07 +02:00
if ( sponsorTimesStorage [ sponsorTimesStorage . length - 1 ] != undefined && sponsorTimesStorage [ sponsorTimesStorage . length - 1 ] . length < 2 ) {
2019-07-09 22:36:06 +02:00
startTimeChosen = true ;
2019-07-10 04:26:15 +02:00
document . getElementById ( "sponsorStart" ) . innerHTML = "Sponsorship Ends Now" ;
2019-07-09 22:36:06 +02:00
}
2019-07-10 03:53:07 +02:00
sponsorTimes = sponsorTimesStorage ;
2019-07-10 01:46:55 +02:00
displaySponsorTimes ( ) ;
2019-07-10 04:23:35 +02:00
//show submission section
document . getElementById ( "submissionSection" ) . style . display = "unset" ;
2019-07-12 04:35:40 +02:00
showSubmitTimesIfNecessary ( ) ;
2019-07-09 22:36:06 +02:00
}
} ) ;
//check if this video's sponsors are known
2019-07-09 06:05:27 +02:00
chrome . tabs . sendMessage (
tabs [ 0 ] . id ,
2019-07-10 04:10:25 +02:00
{ message : 'isInfoFound' } ,
2019-07-09 06:05:27 +02:00
infoFound
) ;
2019-07-09 22:36:06 +02:00
}
2019-07-09 21:55:33 +02:00
2019-07-09 06:05:27 +02:00
function infoFound ( request ) {
2019-07-10 17:55:09 +02:00
if ( chrome . runtime . lastError ) {
//This page doesn't have the injected content script, or at least not yet
2019-07-10 18:04:30 +02:00
displayNoVideo ( ) ;
2019-07-10 17:55:09 +02:00
return ;
}
2019-07-09 18:07:39 +02:00
//if request is undefined, then the page currently being browsed is not YouTube
if ( request != undefined ) {
2019-07-09 23:51:49 +02:00
//this must be a YouTube video
//set variable
isYouTubeTab = true ;
//remove loading text
document . getElementById ( "mainControls" ) . style . display = "unset"
document . getElementById ( "loadingIndicator" ) . innerHTML = "" ;
2019-07-09 18:07:39 +02:00
if ( request . found ) {
document . getElementById ( "videoFound" ) . innerHTML = "This video's sponsors are in the database!"
2019-07-10 00:03:56 +02:00
2019-07-10 01:46:55 +02:00
displayDownloadedSponsorTimes ( request ) ;
2019-07-09 18:07:39 +02:00
} else {
document . getElementById ( "videoFound" ) . innerHTML = "No sponsors found"
}
2019-07-09 06:05:27 +02:00
}
}
2019-07-09 21:55:33 +02:00
function setVideoID ( request ) {
//if request is undefined, then the page currently being browsed is not YouTube
if ( request != undefined ) {
videoID = request . videoID ;
}
}
2019-07-09 05:43:06 +02:00
function sendSponsorStartMessage ( ) {
//the content script will get the message if a YouTube page is open
chrome . tabs . query ( {
active : true ,
currentWindow : true
} , tabs => {
chrome . tabs . sendMessage (
tabs [ 0 ] . id ,
2019-07-09 06:05:27 +02:00
{ from : 'popup' , message : 'sponsorStart' }
2019-07-09 05:43:06 +02:00
) ;
} ) ;
}
chrome . runtime . onMessage . addListener ( function ( request , sender , callback ) {
if ( request . message == "time" ) {
2019-07-10 01:46:55 +02:00
let sponsorTimesIndex = sponsorTimes . length - ( startTimeChosen ? 1 : 0 ) ;
2019-07-09 05:43:06 +02:00
2019-07-10 01:46:55 +02:00
if ( sponsorTimes [ sponsorTimesIndex ] == undefined ) {
sponsorTimes [ sponsorTimesIndex ] = [ ] ;
2019-07-09 05:43:06 +02:00
}
2019-07-10 01:46:55 +02:00
sponsorTimes [ sponsorTimesIndex ] [ startTimeChosen ? 1 : 0 ] = request . time ;
2019-07-09 05:43:06 +02:00
2019-07-10 01:46:55 +02:00
let sponsorTimeKey = "sponsorTimes" + currentVideoID ;
2019-07-22 22:42:57 +02:00
chrome . storage . sync . set ( { [ sponsorTimeKey ] : sponsorTimes } ) ;
2019-07-09 05:43:06 +02:00
2019-07-10 18:23:49 +02:00
updateStartTimeChosen ( ) ;
2019-07-09 05:43:06 +02:00
//display video times on screen
2019-07-10 01:46:55 +02:00
displaySponsorTimes ( ) ;
2019-07-10 04:23:35 +02:00
//show submission section
document . getElementById ( "submissionSection" ) . style . display = "unset" ;
2019-07-12 04:35:40 +02:00
showSubmitTimesIfNecessary ( ) ;
2019-07-09 05:43:06 +02:00
}
} ) ;
//display the video times from the array
2019-07-10 01:46:55 +02:00
function displaySponsorTimes ( ) {
2019-07-10 00:03:56 +02:00
//set it to the message
2019-07-10 01:46:55 +02:00
document . getElementById ( "sponsorMessageTimes" ) . innerHTML = getSponsorTimesMessage ( sponsorTimes ) ;
2019-07-10 00:03:56 +02:00
}
//display the video times from the array at the top, in a different section
2019-07-10 01:46:55 +02:00
function displayDownloadedSponsorTimes ( request ) {
2019-07-10 00:03:56 +02:00
if ( request . sponsorTimes != undefined ) {
//set it to the message
2019-07-10 01:46:55 +02:00
document . getElementById ( "downloadedSponsorMessageTimes" ) . innerHTML = getSponsorTimesMessage ( request . sponsorTimes ) ;
2019-07-18 04:53:42 +02:00
//add them as buttons to the issue reporting container
let container = document . getElementById ( "issueReporterTimeButtons" ) ;
for ( let i = 0 ; i < request . sponsorTimes . length ; i ++ ) {
let sponsorTimeButton = document . createElement ( "button" ) ;
sponsorTimeButton . className = "warningButton" ;
sponsorTimeButton . innerText = getFormattedTime ( request . sponsorTimes [ i ] [ 0 ] ) + " to " + getFormattedTime ( request . sponsorTimes [ i ] [ 1 ] ) ;
let votingButtons = document . createElement ( "div" ) ;
let UUID = request . UUIDs [ i ] ;
//thumbs up and down buttons
let voteButtonsContainer = document . createElement ( "div" ) ;
voteButtonsContainer . id = "sponsorTimesVoteButtonsContainer" + UUID ;
voteButtonsContainer . setAttribute ( "align" , "center" ) ;
voteButtonsContainer . style . display = "none"
let upvoteButton = document . createElement ( "img" ) ;
upvoteButton . id = "sponsorTimesUpvoteButtonsContainer" + UUID ;
upvoteButton . className = "voteButton" ;
upvoteButton . src = chrome . extension . getURL ( "icons/upvote.png" ) ;
upvoteButton . addEventListener ( "click" , ( ) => vote ( 1 , UUID ) ) ;
let downvoteButton = document . createElement ( "img" ) ;
downvoteButton . id = "sponsorTimesDownvoteButtonsContainer" + UUID ;
downvoteButton . className = "voteButton" ;
downvoteButton . src = chrome . extension . getURL ( "icons/downvote.png" ) ;
downvoteButton . addEventListener ( "click" , ( ) => vote ( 0 , UUID ) ) ;
//add thumbs up and down buttons to the container
voteButtonsContainer . appendChild ( document . createElement ( "br" ) ) ;
voteButtonsContainer . appendChild ( document . createElement ( "br" ) ) ;
voteButtonsContainer . appendChild ( upvoteButton ) ;
voteButtonsContainer . appendChild ( downvoteButton ) ;
//add click listener to open up vote panel
sponsorTimeButton . addEventListener ( "click" , function ( ) {
voteButtonsContainer . style . display = "unset" ;
} ) ;
container . appendChild ( sponsorTimeButton ) ;
container . appendChild ( voteButtonsContainer ) ;
//if it is not the last iteration
if ( i != request . sponsorTimes . length - 1 ) {
container . appendChild ( document . createElement ( "br" ) ) ;
container . appendChild ( document . createElement ( "br" ) ) ;
}
}
2019-07-10 00:03:56 +02:00
}
}
2019-07-09 05:43:06 +02:00
2019-07-10 00:03:56 +02:00
//get the message that visually displays the video times
2019-07-10 01:46:55 +02:00
function getSponsorTimesMessage ( sponsorTimes ) {
2019-07-10 00:03:56 +02:00
let sponsorTimesMessage = "" ;
for ( let i = 0 ; i < sponsorTimes . length ; i ++ ) {
for ( let s = 0 ; s < sponsorTimes [ i ] . length ; s ++ ) {
2019-07-10 00:10:45 +02:00
let timeMessage = getFormattedTime ( sponsorTimes [ i ] [ s ] ) ;
2019-07-09 05:43:06 +02:00
//if this is an end time
if ( s == 1 ) {
timeMessage = " to " + timeMessage ;
} else if ( i > 0 ) {
//add commas if necessary
timeMessage = ", " + timeMessage ;
}
2019-07-10 00:03:56 +02:00
sponsorTimesMessage += timeMessage ;
2019-07-09 05:43:06 +02:00
}
}
2019-07-10 00:03:56 +02:00
return sponsorTimesMessage ;
2019-07-09 05:43:06 +02:00
}
function clearTimes ( ) {
2019-07-22 00:19:56 +02:00
//send new sponsor time state to tab
if ( sponsorTimes . length > 0 ) {
2019-07-12 23:45:20 +02:00
chrome . tabs . query ( {
active : true ,
currentWindow : true
} , function ( tabs ) {
chrome . tabs . sendMessage ( tabs [ 0 ] . id , {
2019-07-22 00:19:56 +02:00
message : "changeStartSponsorButton" ,
2019-07-22 22:46:50 +02:00
showStartSponsor : true ,
2019-07-22 00:19:56 +02:00
uploadButtonVisible : false
2019-07-12 23:45:20 +02:00
} ) ;
} ) ;
}
//reset sponsorTimes
2019-07-10 01:46:55 +02:00
sponsorTimes = [ ] ;
2019-07-09 05:43:06 +02:00
2019-07-10 01:46:55 +02:00
let sponsorTimeKey = "sponsorTimes" + currentVideoID ;
2019-07-22 22:42:57 +02:00
chrome . storage . sync . set ( { [ sponsorTimeKey ] : sponsorTimes } ) ;
2019-07-09 05:43:06 +02:00
2019-07-10 01:46:55 +02:00
displaySponsorTimes ( ) ;
2019-07-10 04:23:35 +02:00
//hide submission section
document . getElementById ( "submissionSection" ) . style . display = "none" ;
2019-07-10 18:23:49 +02:00
resetStartTimeChosen ( ) ;
2019-07-09 21:55:33 +02:00
}
function submitTimes ( ) {
2019-07-20 22:03:42 +02:00
//make info message say loading
document . getElementById ( "submitTimesInfoMessage" ) . innerText = "Loading..." ;
document . getElementById ( "submitTimesInfoMessageContainer" ) . style . display = "unset" ;
2019-07-10 03:53:07 +02:00
if ( sponsorTimes . length > 0 ) {
chrome . runtime . sendMessage ( {
message : "submitTimes" ,
videoID : currentVideoID
2019-07-20 22:03:42 +02:00
} , function ( response ) {
if ( response != undefined ) {
if ( response . statusCode == 200 ) {
//hide loading message
document . getElementById ( "submitTimesInfoMessageContainer" ) . style . display = "none" ;
clearTimes ( ) ;
} else if ( response . statusCode == 400 ) {
document . getElementById ( "submitTimesInfoMessage" ) . innerText = "Server said this request was invalid" ;
document . getElementById ( "submitTimesInfoMessageContainer" ) . style . display = "unset" ;
} else if ( response . statusCode == 429 ) {
document . getElementById ( "submitTimesInfoMessage" ) . innerText = "You have submitted too many sponsor times for this one video, are you sure there are this many?" ;
document . getElementById ( "submitTimesInfoMessageContainer" ) . style . display = "unset" ;
} else if ( response . statusCode == 409 ) {
document . getElementById ( "submitTimesInfoMessage" ) . innerText = "This has already been submitted before" ;
document . getElementById ( "submitTimesInfoMessageContainer" ) . style . display = "unset" ;
} else {
document . getElementById ( "submitTimesInfoMessage" ) . innerText = "There was an error submitting your sponsor times, please try again later" ;
document . getElementById ( "submitTimesInfoMessageContainer" ) . style . display = "unset" ;
}
}
2019-07-10 03:53:07 +02:00
} ) ;
}
2019-07-09 22:36:06 +02:00
}
2019-07-10 04:10:25 +02:00
function showNoticeAgain ( ) {
2019-07-22 22:42:57 +02:00
chrome . storage . sync . set ( { "dontShowNoticeAgain" : false } ) ;
2019-07-10 04:10:25 +02:00
chrome . tabs . query ( {
active : true ,
currentWindow : true
} , function ( tabs ) {
chrome . tabs . sendMessage ( tabs [ 0 ] . id , {
message : "showNoticeAgain"
} ) ;
} ) ;
document . getElementById ( "showNoticeAgain" ) . style . display = "none" ;
}
2019-07-13 01:04:24 +02:00
function hideVideoPlayerControls ( ) {
2019-07-22 22:42:57 +02:00
chrome . storage . sync . set ( { "hideVideoPlayerControls" : true } ) ;
2019-07-13 01:04:24 +02:00
chrome . tabs . query ( {
active : true ,
currentWindow : true
} , function ( tabs ) {
chrome . tabs . sendMessage ( tabs [ 0 ] . id , {
message : "changeVideoPlayerControlsVisibility" ,
value : true
} ) ;
} ) ;
document . getElementById ( "hideVideoPlayerControls" ) . style . display = "none" ;
document . getElementById ( "showVideoPlayerControls" ) . style . display = "unset" ;
}
function showVideoPlayerControls ( ) {
2019-07-22 22:42:57 +02:00
chrome . storage . sync . set ( { "hideVideoPlayerControls" : false } ) ;
2019-07-13 01:04:24 +02:00
chrome . tabs . query ( {
active : true ,
currentWindow : true
} , function ( tabs ) {
chrome . tabs . sendMessage ( tabs [ 0 ] . id , {
message : "changeVideoPlayerControlsVisibility" ,
value : false
} ) ;
} ) ;
document . getElementById ( "hideVideoPlayerControls" ) . style . display = "unset" ;
document . getElementById ( "showVideoPlayerControls" ) . style . display = "none" ;
}
2019-07-10 18:23:49 +02:00
function updateStartTimeChosen ( ) {
//update startTimeChosen variable
if ( ! startTimeChosen ) {
startTimeChosen = true ;
document . getElementById ( "sponsorStart" ) . innerHTML = "Sponsorship Ends Now" ;
} else {
resetStartTimeChosen ( ) ;
}
}
//set it to false
function resetStartTimeChosen ( ) {
startTimeChosen = false ;
document . getElementById ( "sponsorStart" ) . innerHTML = "Sponsorship Starts Now" ;
}
2019-07-20 22:03:42 +02:00
//hides and shows the submit times button when needed
2019-07-12 04:35:40 +02:00
function showSubmitTimesIfNecessary ( ) {
//check if an end time has been specified for the latest sponsor time
if ( sponsorTimes . length > 0 && sponsorTimes [ sponsorTimes . length - 1 ] . length > 1 ) {
//show submit times button
2019-07-20 22:03:42 +02:00
document . getElementById ( "submitTimesContainer" ) . style . display = "unset" ;
2019-07-12 04:35:40 +02:00
} else {
2019-07-20 22:03:42 +02:00
//hide submit times button
document . getElementById ( "submitTimesContainer" ) . style . display = "none" ;
2019-07-12 04:35:40 +02:00
}
}
2019-07-13 01:11:09 +02:00
//make the options div visisble
function openOptions ( ) {
document . getElementById ( "optionsButtonContainer" ) . style . display = "none" ;
document . getElementById ( "options" ) . style . display = "unset" ;
}
2019-07-10 18:04:30 +02:00
//this is not a YouTube video page
function displayNoVideo ( ) {
document . getElementById ( "loadingIndicator" ) . innerHTML = "This probably isn't a YouTube tab, or you clicked too early. " +
"If you know this is a YouTube tab, close this popup and open it again." ;
}
2019-07-18 04:53:42 +02:00
function reportAnIssue ( ) {
document . getElementById ( "issueReporterContainer" ) . style . display = "unset" ;
document . getElementById ( "reportAnIssue" ) . style . display = "none" ;
}
2019-07-20 04:24:59 +02:00
function addVoteMessage ( message , UUID ) {
2019-07-18 04:53:42 +02:00
let container = document . getElementById ( "sponsorTimesVoteButtonsContainer" + UUID ) ;
//remove all children
while ( container . firstChild ) {
container . removeChild ( container . firstChild ) ;
}
let thanksForVotingText = document . createElement ( "h2" ) ;
2019-07-20 04:24:59 +02:00
thanksForVotingText . innerText = message ;
2019-07-18 04:53:42 +02:00
//there are already breaks there
thanksForVotingText . style . marginBottom = "0px" ;
container . appendChild ( thanksForVotingText ) ;
2019-07-20 04:24:59 +02:00
}
2019-07-18 04:53:42 +02:00
2019-07-20 04:24:59 +02:00
function vote ( type , UUID ) {
2019-07-20 19:41:13 +02:00
//add loading info
addVoteMessage ( "Loading..." , UUID )
2019-07-18 04:53:42 +02:00
//send the vote message to the tab
chrome . runtime . sendMessage ( {
message : "submitVote" ,
type : type ,
UUID : UUID
2019-07-20 04:24:59 +02:00
} , function ( response ) {
if ( response != undefined ) {
//see if it was a success or failure
if ( response . successType == 1 ) {
//success
addVoteMessage ( "Thanks for voting!" , UUID )
} else if ( response . successType == 0 ) {
//failure: duplicate vote
addVoteMessage ( "You have already voted this way before." , UUID )
2019-07-20 19:26:55 +02:00
} else if ( response . successType == - 1 ) {
//failure: duplicate vote
addVoteMessage ( "A connection error has occured." , UUID )
2019-07-20 04:24:59 +02:00
}
}
2019-07-18 04:53:42 +02:00
} ) ;
}
2019-07-10 00:10:45 +02:00
//converts time in seconds to minutes:seconds
function getFormattedTime ( seconds ) {
let minutes = Math . floor ( seconds / 60 ) ;
let secondsDisplay = Math . round ( seconds - minutes * 60 ) ;
2019-07-11 20:00:03 +02:00
if ( secondsDisplay < 10 ) {
//add a zero
secondsDisplay = "0" + secondsDisplay ;
}
2019-07-10 00:10:45 +02:00
let formatted = minutes + ":" + secondsDisplay ;
return formatted ;
}
2019-07-24 00:32:05 +02:00
function sendRequestToServer ( type , address , callback ) {
let xmlhttp = new XMLHttpRequest ( ) ;
xmlhttp . open ( type , serverAddress + address , true ) ;
if ( callback != undefined ) {
xmlhttp . onreadystatechange = function ( ) {
callback ( xmlhttp , false ) ;
} ;
xmlhttp . onerror = function ( ev ) {
callback ( xmlhttp , true ) ;
} ;
}
//submit this request
xmlhttp . send ( ) ;
}
2019-07-09 22:36:06 +02:00
function getYouTubeVideoID ( url ) { // Return video id or false
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/ ;
var match = url . match ( regExp ) ;
return ( match && match [ 7 ] . length == 11 ) ? match [ 7 ] : false ;
2019-07-09 05:43:06 +02:00
}