derpi_only_show_upvotes

25/06/2023 Replaces images' score with only upvotes, instead of the usual combined upvotes+downvotes. The upvotes are taken from the HTML data-attributes already loaded on the page. Also hides downvotes via CSS rules. You might still see the downvotes for a split second.

  1. // ==UserScript==
  2. // @name derpi_only_show_upvotes
  3. // @namespace Violentmonkey Scripts
  4. // @match https://derpibooru.org/*
  5. // @grant none
  6. // @version 1.5
  7. // @license MIT
  8. // @author Saphkey
  9. // @run-at document-end
  10. // @description 25/06/2023 Replaces images' score with only upvotes, instead of the usual combined upvotes+downvotes. The upvotes are taken from the HTML data-attributes already loaded on the page. Also hides downvotes via CSS rules. You might still see the downvotes for a split second.
  11. // ==/UserScript==
  12.  
  13.  
  14. (function() {
  15.  
  16. function hideScores(){
  17. let scoreEls = document.getElementsByClassName('score');
  18. for (let i = 0; i < scoreEls.length; i++) {
  19. scoreEls[i].innerHTML = '?';
  20. }
  21. }
  22.  
  23. function hideDownvotes() {
  24. let downvoteEls = document.getElementsByClassName('downvotes');
  25. for (let i = 0; i < downvoteEls.length; i++) {
  26. downvoteEls[i].innerHTML = '?';
  27. }
  28. }
  29.  
  30.  
  31. function displaySingleUpvote(upvotes, imageId) {
  32. let scoreEls = document.getElementsByClassName('score');
  33.  
  34. for (let i = 0; i < scoreEls.length; i++) {
  35. let scoreEl = scoreEls.item(i);
  36.  
  37. if (scoreEl.getAttribute(`data-image-id`) == imageId){
  38. scoreEl.innerHTML = upvotes;
  39. }
  40. }
  41. }
  42.  
  43. function replaceScoresWithUpvotes(imageIds){
  44. let dataContainers = document.getElementsByClassName('image-container');
  45. for (let i = 0; i < dataContainers.length; i++) {
  46. let dataContainer = dataContainers[i];
  47. let imageId = dataContainer.getAttribute('data-image-id');
  48. let upvote = dataContainer.getAttribute('data-upvotes');
  49. displaySingleUpvote(upvote, imageId);
  50. }
  51. }
  52.  
  53.  
  54.  
  55. function addStyleRulesThatHideScoresAndDownvotes(){
  56. // Check if stylesheets exist yet, if not try again in a bit
  57. if( !document.styleSheets[0] ) return setTimeout( addStyleRulesThatHideScoresAndDownvotes,1 );
  58.  
  59. var ss = document.styleSheets[0];
  60.  
  61. // Add style rules
  62. if(ss.addRule) {
  63. ss.addRule('.score', 'display: none', 0);
  64. ss.addRule('.downvotes', 'display: none !important', 0);
  65. }
  66. else
  67. {
  68. ss.insertRule('.score{display: none}', 0);
  69. ss.insertRule('.downvotes{display: none !important}', 0);
  70. }
  71. }
  72. function addStyleRulesThatShowScores(){
  73. // Check if stylesheets exist yet, if not try again in a bit
  74. if( !document.styleSheets[0] ) return setTimeout( addStyleRulesThatShowScores,1 );
  75.  
  76. var ss = document.styleSheets[0];
  77.  
  78. // Add style rules
  79. if(ss.addRule)
  80. ss.addRule( '.score','display: inline !important',0);
  81. else
  82. ss.insertRule('.score{display: inline !important}',0);
  83. }
  84.  
  85. addStyleRulesThatHideScoresAndDownvotes();
  86.  
  87. hideScores();
  88. hideDownvotes();
  89.  
  90. replaceScoresWithUpvotes();
  91.  
  92. addStyleRulesThatShowScores();
  93. })();