Letterboxd Average Rating

Adds average rating of film to film pages

当前为 2014-08-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Letterboxd Average Rating
  3. // @namespace https://github.com/rcalderong/userscripts
  4. // @description Adds average rating of film to film pages
  5. // @copyright 2014, Ramón Calderón (http://rcalderon.es)
  6. // @homepageURL https://github.com/rcalderong/userscripts
  7. // @supportURL https://github.com/rcalderong/userscripts/issues
  8. // @icon https://raw.githubusercontent.com/rcalderong/userscripts/master/img/letterboxd_icon.png
  9. // @license GPLv3; http://www.gnu.org/licenses/gpl.html
  10. // @version 1.1
  11. // @include /^http:\/\/(www.)?letterboxd.com\/film\/[\w|\-]+\/$/
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. var newElt, // Element with average rating to be inserted in page
  17. newInnerElt, // Element with average rating to be inserted in page
  18. rating5, // Average rating of the film in a five-star scale
  19. rating10, // Average rating of the film in a one-to-ten scale
  20. ratingsElt; // Page element of the ratings section
  21.  
  22. // Get average rating from page metadata
  23. ratingsElt = document.querySelector(".ratings-histogram-chart");
  24. rating10 = ratingsElt.querySelector("span meta").getAttribute("content");
  25. rating5 = (rating10 / 2).toFixed(1);
  26.  
  27. // Create element to be inserted in page
  28. newElt = document.createElement("a");
  29. newElt.className = "rating-green tooltip";
  30. newElt.setAttribute("href",
  31. ratingsElt.querySelector("h3 a").getAttribute("href"));
  32. newElt.setAttribute("title", rating5.replace(/\./, ",") + " stars");
  33. newElt.setAttribute("style", "position: absolute; top: 0; left: 72px;");
  34. newInnerElt = document.createElement("span");
  35. newInnerElt.className = "rating rated-" + Math.round(rating10);
  36. newElt.appendChild(newInnerElt);
  37.  
  38. // Insert element in page
  39. ratingsElt.insertBefore(newElt, ratingsElt.children[1]);
  40. }());