Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Display dislike count
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @author Anonymous
- // @match https://www.youtube.com/*
- // @icon https://www.google.com/s2/favicons?domain=youtube.com
- // @grant none
- // ==/UserScript==
- function format(number) {
- if (number < 1000)
- return number;
- if (number < 10000)
- return Math.floor(number/100)/10 + "k";
- return Math.floor(number/1000) + "k";
- }
- async function updateDislikes() {
- if (location.href.search(/v=[0-9a-zA-Z_-]{11}/)){
- let element = document.querySelector('#button[aria-label="Dislike this video"]');
- if (element) {
- element.parentElement.parentElement.querySelector("#text").textContent = "...";
- }
- let response = await fetch(location.href);
- let text = await response.text();
- let ratio = (text.match(/averageRating":([\d\.]*)/)[1] - 1) / 4;
- let likeCount = text.match(/label":"([\d,]*) likes/)[1];
- likeCount = likeCount.replace(/\D/g, '');
- let dislikeCount = likeCount / ratio - likeCount;
- 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"]')
- if (imageList.length > 1){
- imageList[0].parentNode.parentNode.parentNode.parentNode.parentElement.parentElement.querySelector("#text").textContent = format(Math.round(dislikeCount));
- }
- else{
- 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));
- }
- }
- }
- document.addEventListener("yt-navigate-finish", updateDislikes);
- window.addEventListener("load", updateDislikes);
- setInterval(updateDislikes, 3 * 60 * 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement