NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Youtube Percent Script // @namespace http://youtube.com // @version 1.61 // @description Shows like percentage of current video. // @author Ontake // @match https://www.youtube.com/* // @grant none // @copyright 2020, OnTake (https://openuserjs.org/users/OnTake) // @license MIT // ==/UserScript== /*Sleep Function*/ function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } /*Main Function*/ function displaypercent() { /*Trying Function Until Success*/ try { /*Get Likes and Dislikes from youtube page*/ var likesinput = document.getElementsByClassName("style-scope ytd-toggle-button-renderer style-text")[1].innerHTML; var dislikesinput = document.getElementsByClassName("style-scope ytd-toggle-button-renderer style-text")[3].innerHTML; console.log("Calculating..."); /*Remove Suffixes*/ var a = parseFloat(likesinput); var b = parseFloat(dislikesinput); console.log(a); console.log(b); /*Calculate Suffixes*/ if (likesinput.includes("K")) { a = a * 1000; } if (likesinput.includes("M")) { a = a * 1000000; } if (dislikesinput.includes("K")) { b = b * 1000; } if (dislikesinput.includes("M")) { b = b * 1000000; } console.log(a); console.log(b); /*Calculate Ratio*/ var ratio = Math.round(a / (a + b) * 100).toString() + "%"; console.log(ratio); /*Get Likes and Dislikes from youtube page*/ var color = "green"; if ((a / (a + b) * 100) < 75) { color = "orange"; } if ((a / (a + b) * 100) < 50) { color = "red"; } var spans = Array.from({ length: document.getElementsByClassName("ytd-video-primary-info-renderer").length }, (x, i) => i); for (var currentspan in spans) { if (document.getElementsByClassName("ytd-video-primary-info-renderer")[currentspan].innerHTML == "•") { document.getElementsByClassName("ytd-video-primary-info-renderer")[currentspan].innerHTML = " • <span style='color:" + color + ";'>" + ratio + "</span> • "; } } document.getElementById("info").style.paddingLeft = "1%"; document.getElementById("info").style.paddingRight = "1%"; console.log("Done") } catch (error) { console.log(error); setTimeout(displaypercent, 1000); } } displaypercent();