Created
September 1, 2021 12:15
-
-
Save eviltester/ac7ed61c589855c7d35fe56e6718cc77 to your computer and use it in GitHub Desktop.
Calculate average number of views for a YouTube channel's visible videos
This file contains 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 viewCounts = [...document.querySelectorAll('div#metadata-line span:first-child')].map((node) => {viewCount = node.innerText.replace(" views","");valueOfViewCount = viewCount.indexOf("K")==-1 ? parseInt(viewCount,10) : parseFloat(viewCount)*1000; return valueOfViewCount;}); | |
console.log(viewCounts); | |
const sum = viewCounts.reduce(( previousValue, currentValue ) => previousValue + currentValue); | |
console.log(`${sum} / ${viewCounts.length}`); | |
console.log(sum/viewCounts.length) |
Author
eviltester
commented
Sep 1, 2021
- on a YouTube Channel page with videos listed
- scroll down to add more videos to page
- inspect to open console
- run script in the console to calculate average number of views for videos displayed
- console output shows the views in an array, and the calculation so you can double check
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment