Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Anarios/return-youtube-dislike.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDARKDRAGON532 <69623818+DARKDRAGON532@users.noreply.github.com>2021-11-27 00:17:04 +0300
committerDARKDRAGON532 <69623818+DARKDRAGON532@users.noreply.github.com>2021-11-27 00:17:04 +0300
commitdc79f7bfc5855f16d2dada859e0ad512d42cb5eb (patch)
tree7b26e2d19928cf5c1ac5619ae1d215fa705a2a5d
parent76729c594575ee0703548c4070445780bb886a50 (diff)
updated userscript to work with new ui
-rw-r--r--Extensions/UserScript/Return Youtube Dislike.user.js70
1 files changed, 63 insertions, 7 deletions
diff --git a/Extensions/UserScript/Return Youtube Dislike.user.js b/Extensions/UserScript/Return Youtube Dislike.user.js
index ec64dfe..9dea9a6 100644
--- a/Extensions/UserScript/Return Youtube Dislike.user.js
+++ b/Extensions/UserScript/Return Youtube Dislike.user.js
@@ -23,8 +23,10 @@ function doXHR(opts) {
if (typeof GM_xmlhttpRequest === 'function') {
return GM_xmlhttpRequest(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.');
@@ -40,9 +42,15 @@ function doXHR(opts) {
}
function getButtons() {
- return document
- .getElementById("menu-container")
- ?.querySelector("#top-level-buttons-computed");
+ 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() {
@@ -88,6 +96,54 @@ 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",
+ `
+ <div class="ryd-tooltip" style="width: ${widthPx}px">
+ <div class="ryd-tooltip-bar-container">
+ <div
+ id="return-youtube-dislike-bar-container"
+ style="width: 100%; height: 2px;"
+ >
+ <div
+ id="return-youtube-dislike-bar"
+ style="width: ${widthPercent}%; height: 100%"
+ ></div>
+ </div>
+ </div>
+ <tp-yt-paper-tooltip position="top" id="ryd-dislike-tooltip" class="style-scope ytd-sentiment-bar-renderer" role="tooltip" tabindex="-1">
+ <!--css-build:shady-->${likes.toLocaleString()}&nbsp;/&nbsp;${dislikes.toLocaleString()}
+ </tp-yt-paper-tooltip>
+ </div>
+`
+ );
+ } else {
+ document.getElementById(
+ "return-youtube-dislike-bar-container"
+ ).style.width = widthPx + "px";
+ document.getElementById("return-youtube-dislike-bar").style.width =
+ widthPercent + "%";
+
+ document.querySelector(
+ "#ryd-dislike-tooltip > #tooltip"
+ ).innerHTML = `${likes.toLocaleString()}&nbsp;/&nbsp;${dislikes.toLocaleString()}`;
+ }
+}
+
function setState() {
cLog('Fetching votes...');
@@ -99,10 +155,10 @@ function setState() {
getVideoId(),
onload: function (xhr) {
if (xhr != undefined) {
- const { dislikes } = xhr.response;
-
+ const { dislikes, likes } = xhr.response;
cLog(`Received count: ${dislikes}`);
setDislikes(numberFormat(dislikes));
+ createRateBar(likes, dislikes);
}
},
});