Greasy Fork is available in English.
治好了我每次看到好评和差评时都忍不住心算一下好评占比的强迫症
当前为
// ==UserScript==
// @name 显示youtube好评/差评比例(好评占比)
// @name:en Show likes/dislikes ratio of YouTube video
// @namespace http://tampermonkey.net/
// @version 0.4.2
// @description 治好了我每次看到好评和差评时都忍不住心算一下好评占比的强迫症
// @description:en Show likes/dislikes ratio of YouTube video.
// @author SSmJaE
// @match https://www.youtube.com/*
// @grant none
// @license MIT
// ==/UserScript==
(function () {
'use strict';
setInterval(() => {
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 = parseInt(upCount.replace(/[^0-9]/ig, ""));
downCount = parseInt(downCount.replace(/[^0-9]/ig, ""));
let ratio = Math.round(upCount * 1000 / (upCount + downCount)) / 10;
if (upCount > 0 && !downCount) ratio = 100; //只有0/0会为NaN,1/0没问题
if (isNaN(ratio)) ratio = 0;
shareButton.textContent = ratio + "%";
}, 5000);
})();