Greasy Fork

Greasy Fork is available in English.

显示youtube好评/差评比例(好评占比)

治好了我每次看到好评和差评时都忍不住心算一下好评占比的强迫症

当前为 2020-04-03 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name      显示youtube好评/差评比例(好评占比)
// @name:en      Show positive / negative ratio of YouTube video
// @namespace    http://tampermonkey.net/
// @version      0.4.1
// @description  治好了我每次看到好评和差评时都忍不住心算一下好评占比的强迫症
// @description:en  Show positive / negative ratio of YouTube video.
// @author       SSmJaE
// @match        https://www.youtube.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    function change() {
        let menuBar = document.querySelector('div#info div#menu div#top-level-buttons');
        let up = menuBar.childNodes[0].querySelector('[id="text"]');
        let down = menuBar.childNodes[1].querySelector('[id="text"]');
        let shareButton = menuBar.childNodes[2].querySelector('[id="text"]');

        let upCount = up.getAttribute('aria-label');
        let downCount = down.getAttribute('aria-label');

        upCount = upCount.replace(/[^0-9]/ig, "");
        upCount = parseInt(upCount) ? parseInt(upCount) : 0;
        downCount = downCount.replace(/[^0-9]/ig, "");
        downCount = parseInt(downCount) ? parseInt(downCount) : 0;

        let ratio = Math.round(upCount * 1000 / (upCount + downCount)) / 10;
        shareButton.textContent = ratio + "%";
    }

    setInterval(change, 5000);
    top.addEventListener("load", change, false);
    top.addEventListener("focus", change, false);
})();