Last active
July 22, 2021 00:40
-
-
Save Mohsen-94/2516a6836d44ccc80d3a8369eadce635 to your computer and use it in GitHub Desktop.
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
// Paste this into your console on IMDB's episodes page for a TV show. | |
function waitForEpisodes() { | |
return new Promise((resolve, reject) => { | |
const callback = function (mutationsList, observer) { | |
resolve(mutationsList); | |
observer.disconnect(); | |
}; | |
const observer = new MutationObserver(callback); | |
observer.observe(document.getElementById("episodes_content"), { | |
attributes: true, | |
childList: true, | |
}); | |
}); | |
} | |
async function avgRatingPerSeason() { | |
const numOfSeasons = $("#bySeason").children().length; | |
const id = $("#bySeason").attr("tconst"); | |
const ratings = {}; | |
for (let i = 1; i <= numOfSeasons; i++) { | |
CS.Episodes.changeTo("/title/" + id + "/episodes/_ajax?season=" + i); | |
await waitForEpisodes(); | |
ratings["Season " + i] = ( | |
[...(list = $(".ipl-rating-star.small > .ipl-rating-star__rating"))] | |
.map((e) => e.textContent) | |
.map(Number) | |
.reduce((a, c) => a + c) / list.length | |
).toFixed(2); | |
} | |
console.table(ratings); | |
} | |
avgRatingPerSeason(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment