IMDB Rating

Display imdb rating when hovering on an imdb link

  1. // ==UserScript==
  2. // @name IMDB Rating
  3. // @namespace com.adityapurwa.jenova.gmonkey.imdbrating
  4. // @description Display imdb rating when hovering on an imdb link
  5. // @include *
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  7. // @version 1
  8. // @grant GM_xmlhttpRequest
  9. // ==/UserScript==
  10.  
  11. // MIT LICENSE
  12. // Written by Aditya Purwa (adityapurwa@myriatechnologies.com)
  13.  
  14. requesting = false;
  15. currentlyHovered = null;
  16. $('[href*=\'imdb\']').on('mouseover', function (event) {
  17. var href = $(this).attr('href');
  18. var regex = /http:\/\/www.imdb.com\/title\/(.+)/;
  19. var m = regex.exec(href);
  20. currentlyHovered = $(this) [0];
  21. setTimeout(function () {
  22. if (!requesting) {
  23. requesting = true;
  24. GM_xmlhttpRequest({
  25. method: 'GET',
  26. url: m[0].toString(),
  27. onload: function (r) {
  28. var dom = $.parseHTML(r.responseText);
  29. var rating = $(dom).find('[class=\'titlePageSprite star-box-giga-star\']');
  30. var title = $('<div/>').css({
  31. 'font-weight': 'bold',
  32. 'color': 'white'
  33. }).html('IMDB Rating');
  34. var subtitle = $('<div/>').css({
  35. 'font-weight': 'bold',
  36. 'color': 'white',
  37. 'font-size': '10px'
  38. }).html('click to dismiss');
  39. var ratingBox = $('<div/>', {
  40. id: 'imdb-popup'
  41. }).append(title).append(subtitle).append('<div>' + rating.html() + '</div>').css({
  42. 'position': 'absolute',
  43. 'left': currentlyHovered.offsetLeft + 'px',
  44. 'top': currentlyHovered.offsetTop + 'px',
  45. 'font-size': '18px',
  46. 'padding': '14px',
  47. 'color': 'black',
  48. 'z-index': 100,
  49. 'box-shadow': '0 0 12px rgba(160,120,50,.35)'
  50. }).appendTo($('body')).click(function () {
  51. $('#imdb-popup').remove();
  52. });
  53. var ratingValue = parseFloat(rating.html());
  54. if (ratingValue > 8) {
  55. $(ratingBox).css('background', 'gold');
  56. }
  57. else if (ratingValue > 5) {
  58. $(ratingBox).css('background', '#5A3');
  59. } else {
  60. $(ratingBox).css('background', '#F34');
  61. }
  62. requesting = false;
  63. }
  64. });
  65. }
  66. }, 1000);
  67. });