IMDB Ratings on Actor Page

Request and add your own API key

  1. // ==UserScript==
  2. // @name IMDB Ratings on Actor Page
  3. // @namespace Bzly
  4. // @version 0.1
  5. // @description Request and add your own API key
  6. // @author Bzly
  7. // @match https://www.imdb.com/name/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=imdb.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // this should really be several functions and the querySelectors should be more sensible
  17. function imdbPls() {
  18. // https://www.omdbapi.com/apikey.aspx rate limited to 1000 reqs/day
  19. const apiKey = 'foo123bar'
  20. // get array of previous media entries, but not ones we've inserted earlier
  21. const l = document.querySelectorAll('.date-credits-accordion .ipc-metadata-list-summary-item__c:not(.imdb-rating-inserted)')
  22.  
  23. l.forEach(e => {
  24. // try to find imdb unique title number in url
  25. const m = e.querySelector('a.ipc-metadata-list-summary-item__t').href.match(/tt[0-9]+/)
  26. if (m !== null) {
  27. // get information about title from OMDB API
  28. fetch('https://www.omdbapi.com/?i=' + m[0] + '&apikey=' + apiKey)
  29. .then((response) => response.json())
  30. .then((mediaInfo) => {
  31. if (mediaInfo.Response === 'True' && mediaInfo.imdbRating !== 'N/A') {
  32. // create element and insert
  33. let x = document.createElement('div')
  34. x.setAttribute('style', 'color:black;')
  35. x.textContent = '⭐ ' + mediaInfo.imdbRating
  36. e.lastChild.prepend(x)
  37. // add flag to mark this item as done
  38. e.classList.add('imdb-rating-inserted')
  39. }
  40. })
  41. }
  42. })
  43. }
  44.  
  45. function main() {
  46. const observer = new MutationObserver(imdbPls);
  47. // watch 'previous' list for expansion ('view more')
  48. observer.observe(
  49. document.querySelector('.date-credits-accordion ul.ipc-metadata-list'), {
  50. childList: true,
  51. subtree: false
  52. });
  53. // watch whole section tag for updates from using filters (actor, producer, etc)
  54. observer.observe(
  55. document.querySelector('div[data-testid=Filmography').lastChild, {
  56. childList: true,
  57. subtree: false
  58. });
  59. imdbPls()
  60. }
  61.  
  62. main()
  63. })();