mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-03 03:11:23 +01:00
Merge branch 'main' of https://github.com/Anarios/return-youtube-dislike
This commit is contained in:
commit
ddc36d8c01
1 file changed
+35
-8
@@ -14,7 +14,24 @@
|
|||||||
// @downloadURL https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
|
// @downloadURL https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
|
||||||
// @updateURL https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
|
// @updateURL https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
|
||||||
// @grant GM_xmlhttpRequest
|
// @grant GM_xmlhttpRequest
|
||||||
|
// @grant GM.xmlHttpRequest
|
||||||
// ==/UserScript==
|
// ==/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.xmlHttpRequest === 'function') {
|
||||||
|
return GM.xmlHttpRequest(opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error('Unable to detect UserScript plugin.');
|
||||||
|
}
|
||||||
|
|
||||||
function getButtons() {
|
function getButtons() {
|
||||||
return document
|
return document
|
||||||
.getElementById("menu-container")
|
.getElementById("menu-container")
|
||||||
@@ -52,6 +69,7 @@ function getState() {
|
|||||||
if (isVideoDisliked()) {
|
if (isVideoDisliked()) {
|
||||||
return "disliked";
|
return "disliked";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "neutral";
|
return "neutral";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,29 +82,32 @@ function setDislikes(dislikesCount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setState() {
|
function setState() {
|
||||||
GM_xmlhttpRequest({
|
cLog('Fetching votes...');
|
||||||
|
|
||||||
|
doXHR({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
url:
|
url:
|
||||||
"https://return-youtube-dislike-api.azurewebsites.net/votes?videoId=" +
|
"https://return-youtube-dislike-api.azurewebsites.net/votes?videoId=" +
|
||||||
getVideoId(),
|
getVideoId(),
|
||||||
onload: function (response) {
|
onload: function (xhr) {
|
||||||
if (response != undefined) {
|
if (xhr != undefined) {
|
||||||
const formattedDislike = numberFormat(response.response.dislikes);
|
const { dislikes } = xhr.response;
|
||||||
console.log(response);
|
|
||||||
setDislikes(formattedDislike);
|
cLog(`Received count: ${dislikes}`);
|
||||||
|
setDislikes(numberFormat(dislikes));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function likeClicked() {
|
function likeClicked() {
|
||||||
console.log("like" + getState());
|
cLog('Like clicked', getState());
|
||||||
setState();
|
setState();
|
||||||
}
|
}
|
||||||
|
|
||||||
function dislikeClicked() {
|
function dislikeClicked() {
|
||||||
console.log("dislike" + getState());
|
cLog('Dislike clicked', getState());
|
||||||
setState();
|
setState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,11 +118,13 @@ function setInitalState() {
|
|||||||
function getVideoId() {
|
function getVideoId() {
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const videoId = urlParams.get("v");
|
const videoId = urlParams.get("v");
|
||||||
|
|
||||||
return videoId;
|
return videoId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVideoLoaded() {
|
function isVideoLoaded() {
|
||||||
const videoId = getVideoId();
|
const videoId = getVideoId();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null
|
document.querySelector(`ytd-watch-flexy[video-id='${videoId}']`) !== null
|
||||||
);
|
);
|
||||||
@@ -110,6 +133,7 @@ function isVideoLoaded() {
|
|||||||
function numberFormat(numberState) {
|
function numberFormat(numberState) {
|
||||||
const userLocales = navigator.language;
|
const userLocales = navigator.language;
|
||||||
const formatter = Intl.NumberFormat(userLocales, { notation: "compact" });
|
const formatter = Intl.NumberFormat(userLocales, { notation: "compact" });
|
||||||
|
|
||||||
return formatter.format(numberState);
|
return formatter.format(numberState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +142,9 @@ function setEventListeners(evt) {
|
|||||||
if (getButtons()?.offsetParent && isVideoLoaded()) {
|
if (getButtons()?.offsetParent && isVideoLoaded()) {
|
||||||
clearInterval(jsInitChecktimer);
|
clearInterval(jsInitChecktimer);
|
||||||
const buttons = getButtons();
|
const buttons = getButtons();
|
||||||
|
|
||||||
if (!window.returnDislikeButtonlistenersSet) {
|
if (!window.returnDislikeButtonlistenersSet) {
|
||||||
|
cLog('Registering button listeners...');
|
||||||
buttons.children[0].addEventListener("click", likeClicked);
|
buttons.children[0].addEventListener("click", likeClicked);
|
||||||
buttons.children[1].addEventListener("click", dislikeClicked);
|
buttons.children[1].addEventListener("click", dislikeClicked);
|
||||||
window.returnDislikeButtonlistenersSet = true;
|
window.returnDislikeButtonlistenersSet = true;
|
||||||
@@ -128,6 +154,7 @@ function setEventListeners(evt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (window.location.href.indexOf("watch?") >= 0) {
|
if (window.location.href.indexOf("watch?") >= 0) {
|
||||||
|
cLog('Setting up...');
|
||||||
var jsInitChecktimer = setInterval(checkForJS_Finish, 111);
|
var jsInitChecktimer = setInterval(checkForJS_Finish, 111);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user