Skip to content

Instantly share code, notes, and snippets.

@ksmithbaylor
Last active August 1, 2016 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksmithbaylor/6f4b8ee78afcf0dc5eec7bb2765e5940 to your computer and use it in GitHub Desktop.
Save ksmithbaylor/6f4b8ee78afcf0dc5eec7bb2765e5940 to your computer and use it in GitHub Desktop.
Given
// Visit https://www.youtube.com/user/{username}/videos
// Keep scrolling down to trigger loading of all videos so they are all visible
// Run this to get the user's combined view count
function countViews() {
return Array.from(document.querySelectorAll('.yt-lockup-meta-info li'))
.map(li => li.textContent)
.filter(text => text.includes('views'))
.map(text => text.replace(',', '').replace(' views', ''))
.map(num => parseInt(num))
.reduce((a, b) => a + b);
}
countViews();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment