// ==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 // @downloadURL none // ==/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); })();