Skip to content

Instantly share code, notes, and snippets.

@Mohsen-94
Last active July 22, 2021 00:40
Show Gist options
  • Save Mohsen-94/2516a6836d44ccc80d3a8369eadce635 to your computer and use it in GitHub Desktop.
Save Mohsen-94/2516a6836d44ccc80d3a8369eadce635 to your computer and use it in GitHub Desktop.
// 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