Last active
January 23, 2017 07:27
-
-
Save WPprodigy/dea3541a099efcbb2d4f1516d33e8f4a to your computer and use it in GitHub Desktop.
Find out how long you have spent watching videos at https://es6.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const watched = document.querySelectorAll( '.video.completed' ); | |
let totalSeconds = 0; | |
// Loop over each video watched. | |
watched.forEach( video => { | |
let videoTime = video.querySelector( 'span.duration' ).textContent.split( ':' ); | |
// Turn minutes:seconds into just seconds and append to totalSeconds. | |
videoTime.map( array => { | |
totalSeconds += ( parseInt( array[0] ) * 60 ) + parseInt( array[1] ); | |
}) | |
}); | |
const secondsSaved = totalSeconds * (1.25 - 1); | |
const actualSecondsSpent = totalSeconds - secondsSaved; | |
// Convert seconds into hours:minutes:seconds. | |
function convertTime( secs ) { | |
let convertedTime = { | |
hours: Math.floor( secs / 3600 ), | |
minutes: Math.floor( (secs % 3600) / 60 ), | |
seconds: secs % 60 | |
}; | |
return `${convertedTime.hours}:${convertedTime.minutes}:${convertedTime.seconds}`; | |
} | |
console.clear(); | |
console.log(`Watched video time is ${convertTime(totalSeconds)}`); | |
console.log(`You actually spent ${convertTime(actualSecondsSpent)}`); | |
console.log(`You saved ${convertTime(secondsSaved)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment