Advertisement
Guest User

See Disliokes Fix

a guest
Nov 23rd, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Display dislike count
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @author Anonymous
  6. // @match https://www.youtube.com/*
  7. // @icon https://www.google.com/s2/favicons?domain=youtube.com
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function format(number) {
  12. if (number < 1000)
  13. return number;
  14. if (number < 10000)
  15. return Math.floor(number/100)/10 + "k";
  16. return Math.floor(number/1000) + "k";
  17. }
  18.  
  19. async function updateDislikes() {
  20. if (location.href.search(/v=[0-9a-zA-Z_-]{11}/)){
  21. let element = document.querySelector('#button[aria-label="Dislike this video"]');
  22. if (element) {
  23. element.parentElement.parentElement.querySelector("#text").textContent = "...";
  24. }
  25. let response = await fetch(location.href);
  26. let text = await response.text();
  27. let ratio = (text.match(/averageRating":([\d\.]*)/)[1] - 1) / 4;
  28. let likeCount = text.match(/label":"([\d,]*) likes/)[1];
  29. likeCount = likeCount.replace(/\D/g, '');
  30. let dislikeCount = likeCount / ratio - likeCount;
  31. let imageList = document.querySelectorAll('path[d="M17,4h-1H6.57C5.5,4,4.59,4.67,4.38,5.61l-1.34,6C2.77,12.85,3.82,14,5.23,14h4.23l-1.52,4.94C7.62,19.97,8.46,21,9.62,21 c0.58,0,1.14-0.24,1.52-0.65L17,14h4V4H17z M10.4,19.67C10.21,19.88,9.92,20,9.62,20c-0.26,0-0.5-0.11-0.63-0.3 c-0.07-0.1-0.15-0.26-0.09-0.47l1.52-4.94l0.4-1.29H9.46H5.23c-0.41,0-0.8-0.17-1.03-0.46c-0.12-0.15-0.25-0.4-0.18-0.72l1.34-6 C5.46,5.35,5.97,5,6.57,5H16v8.61L10.4,19.67z M20,13h-3V5h3V13z"]')
  32.  
  33. if (imageList.length > 1){
  34. imageList[0].parentNode.parentNode.parentNode.parentNode.parentElement.parentElement.querySelector("#text").textContent = format(Math.round(dislikeCount));
  35. }
  36. else{
  37. document.querySelector('path[d="M18,4h3v10h-3V4z M5.23,14h4.23l-1.52,4.94C7.62,19.97,8.46,21,9.62,21c0.58,0,1.14-0.24,1.52-0.65L17,14V4H6.57 C5.5,4,4.59,4.67,4.38,5.61l-1.34,6C2.77,12.85,3.82,14,5.23,14z"]').parentNode.parentNode.parentNode.parentNode.parentElement.parentElement.querySelector("#text").textContent = format(Math.round(dislikeCount));
  38. }
  39. }
  40. }
  41.  
  42. document.addEventListener("yt-navigate-finish", updateDislikes);
  43. window.addEventListener("load", updateDislikes);
  44. setInterval(updateDislikes, 3 * 60 * 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement