Created
June 14, 2018 06:12
-
-
Save orientalperil/076b96b311bf158f60851903132ff902 to your computer and use it in GitHub Desktop.
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
| var convertStringToSeconds = function (s) { | |
| var array = s.split(':'); | |
| array = array.map(function(x){return parseInt(x);}); | |
| var hours; | |
| var minutes; | |
| var seconds; | |
| if (array.length === 2) { | |
| hours = 0; | |
| minutes = array[0]; | |
| seconds = array[1]; | |
| } else { | |
| hours = array[0]; | |
| minutes = array[1]; | |
| seconds = array[2]; | |
| } | |
| return hours * 60 * 60 + minutes * 60 + seconds; | |
| }; | |
| var s = document.createElement('script'); | |
| s.src = 'https://code.jquery.com/jquery-3.3.1.js'; | |
| s.onload = function () { | |
| var times = $('span.ytd-thumbnail-overlay-time-status-renderer').map(function (index, element) { | |
| return $(element).text().trim() | |
| }).toArray(); | |
| console.log(JSON.stringify(times)); | |
| var timesAsSeconds = times.map(function(x){return convertStringToSeconds(x);}); | |
| var total = timesAsSeconds.reduce(function(a, b){return a + b}, 0); | |
| var hours = total / 60 / 60; | |
| console.log(`${hours} hours`); | |
| } | |
| document.getElementsByTagName('head')[0].appendChild(s); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment