Youtube Dislike Viewer (USE YOUR OWN API, READ BEFORE DOWNLOADING!)

A script to add Youtube dislikes back. Use your own API, the extensions don't update the dislikes instantly so I made this.

  1. // ==UserScript==
  2. // @name Youtube Dislike Viewer (USE YOUR OWN API, READ BEFORE DOWNLOADING!)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  5. // @description A script to add Youtube dislikes back. Use your own API, the extensions don't update the dislikes instantly so I made this.
  6. // @license MIT
  7. // @author Dildoer the Cocknight
  8. // @match https://www.youtube.com/*
  9. // @icon https://www.google.com/s2/favicons?domain=youtube.com
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.  
  15. //MAKE SURE YOU ENTER YOUR OWN API IN HERE! I'M NOT LETTING ANYONE USE MINE!
  16. let api = "";
  17.  
  18. let lastUrl = location.href;
  19. new MutationObserver(() => {
  20. const url = location.href;
  21. if (url !== lastUrl) {
  22. lastUrl = url;
  23. onUrlChange();
  24.  
  25. }
  26. }).observe(document, {subtree: true, childList: true});
  27.  
  28. function getInfo(){
  29. if(window.location.href.split('/')[3].substring(0, 5) == "watch"){
  30. console.log('yes');
  31. fetch(`https://www.googleapis.com/youtube/v3/videos?id=${location.href.split("?v=")[1]}&key=${api}&part=statistics`)
  32. .then(res => res.json())
  33. .then((out) => {
  34.  
  35. console.log(out);
  36.  
  37. let dislikeTimer = setInterval(() => {
  38. if(document.querySelectorAll('ytd-toggle-button-renderer a yt-formatted-string')[1] != undefined){
  39.  
  40. let dislikes = out.items[0].statistics.dislikeCount;
  41. console.log(`the dislikes are ${dislikes}`)
  42. if (dislikes > 99999999) { dislikes = Math.round(dislikes / 10000000) + "M" } else if (dislikes > 999999) { dislikes = Math.round(dislikes / 100000) / 10 + "M" } else if (dislikes > 9999) { dislikes = Math.round(dislikes / 10000) + "K" } else if (dislikes > 999) { dislikes = Math.round(dislikes / 100) / 10 + "K" }
  43.  
  44. document.querySelectorAll('ytd-toggle-button-renderer a yt-formatted-string')[1].innerText = dislikes;
  45.  
  46. if(document.querySelector('.ratioBar') != undefined){
  47. document.querySelector('.likesBar').style.width = `${(parseInt(out.items[0].statistics.likeCount) / (parseInt(out.items[0].statistics.likeCount) + parseInt(out.items[0].statistics.dislikeCount))) * 100}%`;
  48. } else{
  49. document.querySelector('#menu-container ytd-menu-renderer').insertAdjacentHTML('beforeend', `
  50. <div class="ratioBar" style="
  51. width: 34%;
  52. background-color: red;
  53. height: 3px;
  54. margin-top: 35px;
  55. position: absolute;
  56. "><div class="likesBar" style="
  57. background-color: green;
  58. width: ${(parseInt(out.items[0].statistics.likeCount) / (parseInt(out.items[0].statistics.likeCount) + parseInt(out.items[0].statistics.dislikeCount))) * 100}%;
  59. height: 100%;
  60. "></div></div>
  61. `
  62. );
  63.  
  64.  
  65. }
  66.  
  67. clearInterval(dislikeTimer);
  68. } else{ console.log('waiting for dislike button to spawn before proceeding...')}
  69. }, 100);
  70.  
  71.  
  72. }).catch(err => console.error(err));
  73. }
  74. }
  75.  
  76.  
  77. function onUrlChange() {
  78.  
  79. console.log('url changed');
  80. getInfo();
  81.  
  82. }
  83.  
  84. getInfo();
  85.  
  86.  
  87. })();