mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-12-01 18:31:24 +01:00
1 parent
3d3c7ef60c
commit
c0c3a2ea5f
4 files changed
+125
-34
No files matched your search
@@ -9,35 +9,105 @@ initPatreonFeatures();
|
|||||||
|
|
||||||
let jsInitChecktimer = null;
|
let jsInitChecktimer = null;
|
||||||
let isSetInitialStateDone = false;
|
let isSetInitialStateDone = false;
|
||||||
|
let isStorageListenerRegistered = false;
|
||||||
|
let shortsNavigationObserver = null;
|
||||||
|
let shortsNavigationObserverTarget = null;
|
||||||
|
|
||||||
async function setEventListeners(evt) {
|
function ensureShortsNavigationObserver() {
|
||||||
async function checkForJS_Finish() {
|
if (!isShorts()) {
|
||||||
try {
|
return;
|
||||||
if ((isShorts() && isVideoLoaded()) || (getButtons()?.offsetParent && isVideoLoaded())) {
|
|
||||||
clearInterval(jsInitChecktimer);
|
|
||||||
jsInitChecktimer = null;
|
|
||||||
createSmartimationObserver();
|
|
||||||
addLikeDislikeEventListener();
|
|
||||||
await setInitialState();
|
|
||||||
isSetInitialStateDone = true;
|
|
||||||
getBrowser().storage.onChanged.addListener(storageChangeHandler);
|
|
||||||
}
|
|
||||||
} catch (exception) {
|
|
||||||
if (!isSetInitialStateDone) {
|
|
||||||
console.log("error");
|
|
||||||
await setInitialState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsInitChecktimer !== null) clearInterval(jsInitChecktimer);
|
const shortsRoot = document.querySelector("ytd-shorts");
|
||||||
jsInitChecktimer = setInterval(await checkForJS_Finish, 111);
|
if (!shortsRoot) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shortsNavigationObserver) {
|
||||||
|
shortsNavigationObserver = new MutationObserver((mutations) => {
|
||||||
|
for (const mutation of mutations) {
|
||||||
|
if (
|
||||||
|
mutation.type === "attributes" &&
|
||||||
|
mutation.attributeName === "is-active" &&
|
||||||
|
mutation.target.tagName === "YTD-REEL-VIDEO-RENDERER" &&
|
||||||
|
mutation.target.hasAttribute("is-active")
|
||||||
|
) {
|
||||||
|
triggerInitializationCycle();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shortsNavigationObserverTarget !== shortsRoot) {
|
||||||
|
shortsNavigationObserver.disconnect();
|
||||||
|
shortsNavigationObserver.observe(shortsRoot, {
|
||||||
|
attributes: true,
|
||||||
|
subtree: true,
|
||||||
|
attributeFilter: ["is-active"],
|
||||||
|
});
|
||||||
|
shortsNavigationObserverTarget = shortsRoot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkForInitialization() {
|
||||||
|
try {
|
||||||
|
if (isShorts()) {
|
||||||
|
ensureShortsNavigationObserver();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((isShorts() && isVideoLoaded()) || (getButtons()?.offsetParent && isVideoLoaded())) {
|
||||||
|
if (jsInitChecktimer !== null) {
|
||||||
|
clearInterval(jsInitChecktimer);
|
||||||
|
jsInitChecktimer = null;
|
||||||
|
}
|
||||||
|
createSmartimationObserver();
|
||||||
|
addLikeDislikeEventListener();
|
||||||
|
await setInitialState();
|
||||||
|
isSetInitialStateDone = true;
|
||||||
|
if (!isStorageListenerRegistered) {
|
||||||
|
getBrowser().storage.onChanged.addListener(storageChangeHandler);
|
||||||
|
isStorageListenerRegistered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (exception) {
|
||||||
|
if (!isSetInitialStateDone) {
|
||||||
|
console.log("error");
|
||||||
|
await setInitialState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function triggerInitializationCycle() {
|
||||||
|
isSetInitialStateDone = false;
|
||||||
|
|
||||||
|
if (jsInitChecktimer !== null) {
|
||||||
|
clearInterval(jsInitChecktimer);
|
||||||
|
jsInitChecktimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
await checkForInitialization();
|
||||||
|
|
||||||
|
if (!isSetInitialStateDone) {
|
||||||
|
jsInitChecktimer = setInterval(() => {
|
||||||
|
checkForInitialization();
|
||||||
|
}, 111);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!isSetInitialStateDone) {
|
||||||
|
checkForInitialization();
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setEventListeners() {
|
||||||
|
await triggerInitializationCycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
await setEventListeners();
|
await setEventListeners();
|
||||||
|
|
||||||
document.addEventListener("yt-navigate-finish", async function (event) {
|
document.addEventListener("yt-navigate-finish", async function (event) {
|
||||||
if (jsInitChecktimer !== null) clearInterval(jsInitChecktimer);
|
|
||||||
await setEventListeners();
|
await setEventListeners();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ function getButtons() {
|
|||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (elements.length > 0) {
|
||||||
|
return elements[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//--- If Watching On Mobile: ---//
|
//--- If Watching On Mobile: ---//
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
@@ -48,19 +52,33 @@ function getLikeTextContainer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDislikeButton() {
|
function getDislikeButton() {
|
||||||
return getButtons().children[0].tagName ===
|
if (
|
||||||
|
getButtons().children[0].tagName ===
|
||||||
"YTD-SEGMENTED-LIKE-DISLIKE-BUTTON-RENDERER"
|
"YTD-SEGMENTED-LIKE-DISLIKE-BUTTON-RENDERER"
|
||||||
? querySelector(extConfig.selectors.buttons.dislikeButton.segmented) ??
|
) {
|
||||||
querySelector(
|
return (
|
||||||
extConfig.selectors.buttons.dislikeButton.segmentedGetButtons,
|
querySelector(extConfig.selectors.buttons.dislikeButton.segmented) ??
|
||||||
getButtons(),
|
querySelector(
|
||||||
)
|
extConfig.selectors.buttons.dislikeButton.segmentedGetButtons,
|
||||||
: isShorts()
|
getButtons(),
|
||||||
? querySelector(["#dislike-button"], getButtons())
|
)
|
||||||
: querySelector(
|
);
|
||||||
extConfig.selectors.buttons.dislikeButton.notSegmented,
|
}
|
||||||
getButtons(),
|
|
||||||
);
|
const notSegmentedMatch = querySelector(
|
||||||
|
extConfig.selectors.buttons.dislikeButton.notSegmented,
|
||||||
|
getButtons(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (notSegmentedMatch != null) {
|
||||||
|
return notSegmentedMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isShorts()) {
|
||||||
|
return querySelector(["#dislike-button"], getButtons());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createDislikeTextContainer() {
|
function createDislikeTextContainer() {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const DEV_API_URL = "https://returnyoutubedislikeapi.com";
|
const DEV_API_URL = "https://localhost:7258";
|
||||||
const PROD_API_URL = "https://returnyoutubedislikeapi.com";
|
const PROD_API_URL = "https://returnyoutubedislikeapi.com";
|
||||||
|
|
||||||
const runtime = typeof chrome !== "undefined" ? chrome.runtime : null;
|
const runtime = typeof chrome !== "undefined" ? chrome.runtime : null;
|
||||||
|
|||||||
@@ -238,6 +238,9 @@ function displayError(error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setState(storedData) {
|
async function setState(storedData) {
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
window.__rydSetStateCalls = (window.__rydSetStateCalls || 0) + 1;
|
||||||
|
}
|
||||||
storedData.previousState = isVideoDisliked() ? DISLIKED_STATE : isVideoLiked() ? LIKED_STATE : NEUTRAL_STATE;
|
storedData.previousState = isVideoDisliked() ? DISLIKED_STATE : isVideoLiked() ? LIKED_STATE : NEUTRAL_STATE;
|
||||||
let statsSet = false;
|
let statsSet = false;
|
||||||
console.log("Video is loaded. Adding buttons...");
|
console.log("Video is loaded. Adding buttons...");
|
||||||
|
|||||||
Reference in new issue
Block a user