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.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Youtube Dislike Viewer (USE YOUR OWN API, READ BEFORE DOWNLOADING!)
// @namespace    http://tampermonkey.net/
// @version      1
// @description  A script to add Youtube dislikes back. Use your own API, the extensions don't update the dislikes instantly so I made this.
// @license MIT
// @author       Dildoer the Cocknight
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// @grant        none
// ==/UserScript==

(function() {

//MAKE SURE YOU ENTER YOUR OWN API IN HERE! I'M NOT LETTING ANYONE USE MINE!
let api = "";

let lastUrl = location.href;
new MutationObserver(() => {
  const url = location.href;
  if (url !== lastUrl) {
    lastUrl = url;
    onUrlChange();

  }
}).observe(document, {subtree: true, childList: true});

    function getInfo(){
if(window.location.href.split('/')[3].substring(0, 5) == "watch"){
                    console.log('yes');
    fetch(`https://www.googleapis.com/youtube/v3/videos?id=${location.href.split("?v=")[1]}&key=${api}&part=statistics`)
    .then(res => res.json())
    .then((out) => {

    console.log(out);

let dislikeTimer = setInterval(() => {
    if(document.querySelectorAll('ytd-toggle-button-renderer a yt-formatted-string')[1] != undefined){

    let dislikes = out.items[0].statistics.dislikeCount;
        console.log(`the dislikes are ${dislikes}`)
    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" }

        document.querySelectorAll('ytd-toggle-button-renderer a yt-formatted-string')[1].innerText = dislikes;

        if(document.querySelector('.ratioBar') != undefined){
  document.querySelector('.likesBar').style.width = `${(parseInt(out.items[0].statistics.likeCount) / (parseInt(out.items[0].statistics.likeCount) + parseInt(out.items[0].statistics.dislikeCount))) * 100}%`;
} else{
document.querySelector('#menu-container ytd-menu-renderer').insertAdjacentHTML('beforeend', `
<div class="ratioBar" style="
    width: 34%;
    background-color: red;
    height: 3px;
    margin-top: 35px;
    position: absolute;
            "><div class="likesBar" style="
    background-color: green;
    width: ${(parseInt(out.items[0].statistics.likeCount) / (parseInt(out.items[0].statistics.likeCount) + parseInt(out.items[0].statistics.dislikeCount))) * 100}%;
    height: 100%;
"></div></div>
`
                                                 );


}

        clearInterval(dislikeTimer);
} else{ console.log('waiting for dislike button to spawn before proceeding...')}
}, 100);


}).catch(err => console.error(err));
                }
}


function onUrlChange() {

console.log('url changed');
 getInfo();

}

   getInfo();


})();