Return YouTube Dislike

Display dislikes on YouTube videos

目前為 2024-09-28 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Return YouTube Dislike
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Display dislikes on YouTube videos
// @author       MrBlankCoding
// @match        https://www.youtube.com/**
// @match        *://*.youtube.com/*
// @match        *://www.youtube.com/watch**
// @license MIT
// @grant        GM_xmlhttpRequest
// @run-at       document-end
// @connect      returnyoutubedislikeapi.com
// ==/UserScript==

(function() {
    'use strict';
    window.addEventListener('yt-navigate-finish', fetchDislikeData);
    function fetchDislikeData() {
        let videoId = new URL(window.location.href).searchParams.get("v");
        if (!videoId) return;
        let apiUrl = `https://returnyoutubedislikeapi.com/votes?videoId=${videoId}`;
        GM_xmlhttpRequest({
            method: "GET",
            url: apiUrl,
            onload: function(response) {
                try {
                    let data = JSON.parse(response.responseText);
                    if (data && data.dislikes !== undefined) {
                        displayDislikeCount(data.dislikes);
                    }
                } catch (error) {
                    console.error('Error parsing API response:', error);
                }
            },
            onerror: function(error) {
                console.error('Error fetching data from API:', error);
            }
        });
    }
    function displayDislikeCount(dislikes) {
        let dislikeButton = document.querySelector('dislike-button-view-model');
        if (!dislikeButton) return;
        let iconElement = dislikeButton.querySelector('.yt-spec-button-shape-next__icon');
        if (iconElement) {
            iconElement.style.display = 'none';
        }
        let dislikeCountElement = document.createElement("span");
        dislikeCountElement.style.marginLeft = "5px";
        dislikeCountElement.style.color = "#ff0000";
        dislikeCountElement.style.fontSize = "14px";
        dislikeCountElement.innerText = `👎 ${dislikes.toLocaleString()}`;
        let button = dislikeButton.querySelector('button');
        if (button) {
            button.appendChild(dislikeCountElement);
        }
    }
})();