Derpibooru - Rating Info

Shows image's rating above its thumbnail on Derpibooru.

  1. // ==UserScript==
  2. // @name Derpibooru - Rating Info
  3. // @description Shows image's rating above its thumbnail on Derpibooru.
  4. // @namespace derpibooru_ratinginfo
  5. // @include /^https?:\/\/(www\.)?(derpiboo(ru\.org|\.ru)|trixiebooru\.org).*$/
  6. // @version 20171120
  7. // ==/UserScript==
  8.  
  9. (function() {
  10. "use strict";
  11.  
  12. function addStyle(css) {
  13. var style = document.createElement('style');
  14. style.textContent = css;
  15. document.head.appendChild(style);
  16. }
  17.  
  18. let isRatingTag = tag => tags.includes(tag);
  19.  
  20. addStyle('.RI_rating > * {padding-right: 3px; font-weight: bold}');
  21.  
  22. const conf = [
  23. ['safe', 'S', '#67AF2B'],
  24. ['explicit', 'E', '#CF0001'],
  25. ['questionable', 'Q', '#C4B246'],
  26. ['suggestive', 'Sg', '#C4B246'],
  27. ['grimdark', 'GD', '#5E0000'],
  28. ['semi-grimdark', 'S-GD', '#5E0000'],
  29. ['grotesque', 'Gr', '#000000']
  30. ];
  31.  
  32. const tags = conf.map(value => value[0]);
  33.  
  34. for (const tag of conf) {
  35. addStyle('.RI_' + tag[0] + ':after {content: "' + tag[1] + '"; color:' + tag[2] + '}');
  36. }
  37.  
  38. for (const mediaBox of document.getElementsByClassName("media-box")) {
  39. const infoBoxEl = mediaBox.getElementsByClassName("media-box__header") [0];
  40. const imgTags = mediaBox.getElementsByClassName("image-container") [0].dataset.imageTagAliases.split(", ");
  41. const rTags = imgTags.filter(isRatingTag);
  42.  
  43. const ratingNode = document.createElement("span");
  44. ratingNode.className = "RI_rating";
  45.  
  46. for (const rTag of rTags) {
  47. const tagNode = document.createElement('span');
  48. tagNode.className = "RI_" + rTag;
  49. ratingNode.appendChild(tagNode);
  50. }
  51.  
  52. infoBoxEl.insertBefore(ratingNode, infoBoxEl.firstChild);
  53. }
  54. })();