Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2021
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Display dislike count
  3. // @namespace   Violentmonkey Scripts
  4. // @match       https://www.youtube.com/*
  5. // @icon        https://www.google.com/s2/favicons?domain=youtube.com
  6. // @grant       none
  7. // @version     0.1
  8. // @author      Anonymous
  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="この動画を低く評価する"]');
  22.         if (element) {
  23.             element.parentElement.parentElement.querySelector("#text").textContent = "...";
  24.         }
  25.      
  26.         let response = await fetch(location.href);
  27.         let text = await response.text();
  28.         let ratio = (text.match(/averageRating":([\d\.]*)/)[1] - 1) / 4;
  29.         console.log(ratio)
  30.         let likeCount = text.match(/label":"高評価 ([\d,]*)/)[1];
  31.         console.log(likeCount)
  32.         likeCount = likeCount.replace(/\D/g, '');
  33.         let dislikeCount = likeCount / ratio - likeCount;
  34.         document.querySelector('#button[aria-label="この動画を低く評価する"]').parentElement.parentElement.querySelector("#text").textContent = format(Math.round(dislikeCount));
  35.        
  36.     }
  37. }
  38.  
  39. document.addEventListener("yt-navigate-finish", updateDislikes);
  40. window.addEventListener("load", updateDislikes);
  41. setInterval(updateDislikes, 3 * 60 * 1000);
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement