// ==UserScript== // @name Return YouTube Dislike // @namespace https://www.returnyoutubedislike.com/ // @version 0.5 // @description Return of the YouTube Dislike, Based off https://www.returnyoutubedislike.com/ // @author Anarios & JRWR // @match *://*.youtube.com/watch* // @compatible chrome // @compatible firefox // @compatible opera // @compatible safari // @compatible edge // @grant GM.xmlHttpRequest // @downloadURL none // ==/UserScript== function cLog(text, subtext = '') { subtext = subtext.trim() === '' ? '' : `(${subtext})`; console.log(`[Return Youtube Dislikes] ${text} ${subtext}`); } function doXHR(opts) { if (typeof GM_xmlhttpRequest === 'function') { return GM_xmlhttpRequest(opts); } if (typeof GM !== 'undefined') /*This will prevent from throwing "Uncaught ReferenceError: GM is not defined"*/ { if (typeof GM.xmlHttpRequest === 'function') { return GM.xmlHttpRequest(opts); } } console.warn('Unable to detect UserScript plugin, falling back to native XHR.'); const xhr = new XMLHttpRequest(); xhr.open(opts.method, opts.url, true); xhr.onload = () => opts.onload({ response: JSON.parse(xhr.responseText), }); xhr.onerror = err => console.error('XHR Failed', err); xhr.send(); } function getButtons() { if (document.getElementById("menu-container").offsetParent === null) { return document.querySelector( "ytd-menu-renderer.ytd-watch-metadata > div" ); } else { return document .getElementById("menu-container") ?.querySelector("#top-level-buttons-computed"); } } function getLikeButton() { return getButtons().children[0]; } function getDislikeButton() { return getButtons().children[1]; } function isVideoLiked() { return getLikeButton().classList.contains("style-default-active"); } function isVideoDisliked() { return getDislikeButton().classList.contains("style-default-active"); } function isVideoNotLiked() { return getLikeButton().classList.contains("style-text"); } function isVideoNotDisliked() { return getDislikeButton().classList.contains("style-text"); } function getState() { if (isVideoLiked()) { return "liked"; } if (isVideoDisliked()) { return "disliked"; } return "neutral"; } function setLikes(likesCount) { getButtons().children[0].querySelector("#text").innerText = likesCount; } function setDislikes(dislikesCount) { getButtons().children[1].querySelector("#text").innerText = dislikesCount; } function createRateBar(likes, dislikes) { var rateBar = document.getElementById( "return-youtube-dislike-bar-container" ); const widthPx = getButtons().children[0].clientWidth + getButtons().children[1].clientWidth + 8; const widthPercent = likes + dislikes > 0 ? (likes / (likes + dislikes)) * 100 : 50; if (!rateBar) { document.getElementById("menu-container").insertAdjacentHTML( "beforeend", `