Writing (Greasemonkey) Userscripts to Add a Feature in IMDb.com

Say, hypothetically, you want to watch the best episodes of The Twilight Zone, or perhaps a sitcom like Malcolm in the Middle. The show is episodic, so you’re not missing anything by skipping subpar episodes.

Sorting a season by rating is not a native feature in IMDb.com (surprisingly), so here are the steps you would take to do that using a browser and a notepad:

1- Go to the seasons page on IMDb https://www.imdb.com/title/tt0212671/.
2- Write down ALL episode numbers and user ratings.
3- Sort the episodes by rating.

But as Douglas Adams would say “I am rarely happier than when spending an entire day programming my computer to perform automatically a task that would otherwise take me a good ten seconds to do by hand.” Therefore, I’m going to automate the previous task >:)

One solution is to crawl the data of the pages (using BeautifulSoup or a similar library), but that’s against the terms of use of IMDb. We could get the data from IMDb interface which is provided officially for personal, non-commercial use, but I find this approach time-consuming as we still have to create an application to display the results — an application that practically mirrors the IMDb season page but slightly altered.

Alternatively, we could “hack” the page our browser is currently seeing and add a client-faced button that sorts the episodes for us. And we can do that using a Greasemonkey script.

I already wrote a script that sorts the episodes. It uses pretty straightforward JavaScript to add a button on the page. You have to have the Greasemonkey plugin for Firefox (or a similar alternative like Tampermonkey for Chrome) to install it https://greasyfork.org/en/scripts/418936-imdb-sort-episodes-by-rating

Example of my script’s result!

Greasemonkey is a plugin for Firefox that allows you to run 3rd party scripts. Many of them can be found in https://greasyfork.org. For example, here’s a collection of scripts by various authors to extend the functionality of Youtube.com https://greasyfork.org/en/scripts/by-site/youtube.com. You can find scripts for any website really. Back in the day, I used a lot of scripts on Newgrounds.com to see who’s online, and display hidden stats that were only intended to be seen by the web developers.

Hope that was helpful, hack away!