Last active
May 12, 2020 14:10
-
-
Save redrohX/d641f7ea2bbf88876121a3a90e526526 to your computer and use it in GitHub Desktop.
Select all [data-name] items on the page and convert to array
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 items = Array.from(document.querySelectorAll('[data-name]')); |
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 filtered = items | |
.filter(item => item.textContent.includes('Text')) | |
.map(item => item.dataset.time) //data-time | |
// map to an array of seconds | |
.map(timecode => { | |
const parts = timecode.split(':').map(part => parseFloat(part)); | |
return (parts[0] * 60) + parts[1]; | |
}) | |
// reduce to get total | |
.reduce((runningTotal, seconds) => runningTotal + seconds, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment