Skip to content

Instantly share code, notes, and snippets.

@redrohX
Last active May 12, 2020 14:10
Show Gist options
  • Save redrohX/d641f7ea2bbf88876121a3a90e526526 to your computer and use it in GitHub Desktop.
Save redrohX/d641f7ea2bbf88876121a3a90e526526 to your computer and use it in GitHub Desktop.
Select all [data-name] items on the page and convert to array
const items = Array.from(document.querySelectorAll('[data-name]'));
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