Skip to content

Instantly share code, notes, and snippets.

@iceener
Created November 30, 2020 22:45
Show Gist options
  • Save iceener/1b2080907816f75c803fb251a118e16f to your computer and use it in GitHub Desktop.
Save iceener/1b2080907816f75c803fb251a118e16f to your computer and use it in GitHub Desktop.
const videos = [...document.querySelectorAll('.label.style-scope.ytcp-thumbnail')];
const pattern = /[0-9]:../gi
const time = videos.map(item => item.textContent.match(pattern)[0]);
const pageTime = time.reduce((acc, curr) => acc += curr.split(':').reduce((acc,time) => (60 * acc) + +time), 0);
console.log(`Total time on page ${pageTime} seconds`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment