// ==UserScript== // @name 显示youtube好评/差评比例(好评占比) // @namespace http://tampermonkey.net/ // @version 0.2 // @description 治好了我每次看到好评和差评时都忍不住心算一下好评占比的强迫症 // @author SSmJaE // @match https://www.youtube.com/watch?v=* // @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(',', '').replace('.',''); upCount = parseInt(upCount); downCount = downCount.replace(',', '').replace('.',''); downCount = parseInt(downCount); let ratio = Math.round(upCount * 1000 / (upCount + downCount)) / 10; shareButton.textContent = ratio + "%"; } function wait() { setInterval(change, 5000); } window.addEventListener("load", change, false); window.addEventListener('load', wait, false); window.addEventListener("focus", change, false); })();