Greasy Fork is available in English.

add IMDb rating & votes next to all IMDb Movie/Series Links (Working 2024 on new view)

Adds movie ratings and number of voters to any imdb link on any webpage. Modified version of http://userscripts.org/scripts/show/96884 And from [StackOverflow community (especially Brock Adams)]

  1. // ==UserScript==
  2. // @name add IMDb rating & votes next to all IMDb Movie/Series Links (Working 2024 on new view)
  3. // @description Adds movie ratings and number of voters to any imdb link on any webpage. Modified version of http://userscripts.org/scripts/show/96884 And from [StackOverflow community (especially Brock Adams)]
  4. // @author [StackOverflow community (especially Brock Adams)]
  5. // @version 2024-03-09
  6. // @include *
  7. // @grant GM_xmlhttpRequest
  8. // @namespace Extra2020
  9. // ==/UserScript==
  10.  
  11.  
  12. var maxLinksAtATime = 38; //-- pages can have 100's of links to fetch. Don't spam server or browser.
  13. var fetchedLinkCnt = 0;
  14.  
  15. function processIMDB_Links () {
  16. //--- Get only links that could be to IMBD movie/TV pages.
  17. var linksToIMBD_Shows = document.querySelectorAll ("a[href*='/title/']");
  18.  
  19. for (var J = 0, L = linksToIMBD_Shows.length; J < L; J++) {
  20. var currentLink = linksToIMBD_Shows[J];
  21.  
  22. /*--- Strict tests for the correct IMDB link to keep from spamming the page
  23. with erroneous results.
  24.  
  25. if ( ! /^(?:www\.)?IMDB\.com$/i.test (currentLink.hostname) || ! /^\/title\/tt\d+\/?$/i.test (currentLink.pathname) || ! /nm_knf_t_/i.test (currentLink.pathname) )
  26. */
  27.  
  28. if ( ! /^(?:www\.)?IMDB\.com$/i.test (currentLink.hostname) || ! /^\/title\/tt\d+\/?$/i.test (currentLink.pathname))
  29. continue;
  30.  
  31.  
  32. if (! currentLink.getAttribute ("data-gm-fetched") ){
  33. if (fetchedLinkCnt >= maxLinksAtATime){
  34. //--- Position the "continue" button.
  35. continueBttn.style.display = 'inline';
  36. currentLink.parentNode.insertBefore (continueBttn, currentLink);
  37. break;
  38. }
  39.  
  40. fetchTargetLink (currentLink); //-- AJAX-in the ratings for a given link.
  41.  
  42. //---Mark the link with a data attribute, so we know it's been fetched.
  43. currentLink.setAttribute ("data-gm-fetched", "true");
  44. fetchedLinkCnt++;
  45. }
  46. }
  47. }
  48.  
  49. function fetchTargetLink (linkNode) {
  50. //--- This function provides a closure so that the callbacks can work correctly.
  51.  
  52. /*--- Must either call AJAX in a closure or pass a context.
  53. But Tampermonkey does not implement context correctly!
  54. (Tries to JSON serialize a DOM node.)
  55. */
  56. GM_xmlhttpRequest ( {
  57. method: 'get',
  58. url: linkNode.href,
  59. //context: linkNode,
  60. onload: function (response) {
  61. prependIMDB_Rating (response, linkNode);
  62. },
  63.  
  64. onabort: function (response) {
  65. prependIMDB_Rating (response, linkNode);
  66. }
  67. } );
  68. }
  69.  
  70.  
  71.  
  72. function prependIMDB_Rating (resp, targetLink) {
  73. var isError = true;
  74. var ratingTxt = "*Err!";
  75. var colnumber = 0;
  76. var justrate =0;
  77. var votess="";
  78. var color="#ddd";
  79. if (resp.status != 200 && resp.status != 304) {
  80. ratingTxt = '** ' + resp.status + ' Error!';
  81. }
  82. else {
  83.  
  84. // var parser = new DOMParser();
  85. // var xmlDoc = parser.parseFromString(resp.responseText, "application/xml");
  86. var votesM = resp.responseText.match (/gPVQxL">(.*)<\/div><\/div><\/div><\/span><\/a><\/div><div data-testid="hero-rating-bar__user-rating/);
  87. var ratingM = resp.responseText.match (/cMEQkK">(.*)<\/span><span>\/<!-- -->10<\/span><\/div><div class=\"sc-bde20123-5/);
  88.  
  89.  
  90. //console.log(ratingM);
  91. //console.log(votesM);
  92.  
  93. isError = false;
  94.  
  95. justrate = ratingM[1].substring(0,3);
  96. votess = votesM[1].substring(0,4);
  97.  
  98. ratingTxt =justrate + " - " + votess+ " ";
  99.  
  100.  
  101. colnumber = Math.floor(justrate);
  102. }
  103.  
  104.  
  105.  
  106. color = ["#Faa","#Faa","#Faa","#F88", "#F88","#FAA", "#FF7","#7E7", "#5e5", "#0e0", "#ddd"]
  107. var resltSpan = document.createElement ("span");
  108. resltSpan.innerHTML = '<b><font style="color:black; background-color:'+ color[colnumber] + ';">' + ratingTxt + '</font></b>&nbsp;';
  109. // resltSpan.innerHTML = '<b><font style="background-color:' + justrate + '">' + ' [' + ratingTxt + '] </font></b>&nbsp;';
  110.  
  111.  
  112. if (isError) resltSpan.style.color = 'red';
  113.  
  114. //var targetLink = resp.context;
  115. //console.log ("targetLink: ", targetLink);
  116.  
  117. targetLink.parentNode.insertBefore (resltSpan, targetLink);
  118. }
  119.  
  120. //--- Create the continue button
  121. var continueBttn = document.createElement ("button");
  122. continueBttn.innerHTML = "continueRatings";
  123.  
  124. continueBttn.addEventListener ("click", function (){
  125. fetchedLinkCnt = 0;
  126. continueBttn.style.display = 'none';
  127. processIMDB_Links ();
  128. },
  129. false
  130. );
  131.  
  132. processIMDB_Links ();