Prepare 4.0.5 Firefox update and Shorts fixes

Add Firefox data consent, repair contributor sign-in, and introduce optional Hide clutter buttons. Harden video navigation, voting, and action layouts with shared browser regression coverage and reproducible release packaging.
This commit is contained in:
Anarios committed 2026-09-06 12:51:12 +02:00
1 parent 3657de9b2c
commit e500088e65
196 files changed
+39706 -2694

No files matched your search

@@ -30,8 +30,103 @@
// This file is generated by `npm run build:userscript`.
// Edit Extensions/UserScript/src instead of the generated file.
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ 26:
/***/ ((module) => {
const LIKED_STATE = "LIKED_STATE";
const DISLIKED_STATE = "DISLIKED_STATE";
const NEUTRAL_STATE = "NEUTRAL_STATE";
const LIKE_ACTION = "like";
const DISLIKE_ACTION = "dislike";
const TRANSITIONS = {
[NEUTRAL_STATE]: {
[LIKE_ACTION]: { nextState: LIKED_STATE, value: 1, likesDelta: 1, dislikesDelta: 0 },
[DISLIKE_ACTION]: { nextState: DISLIKED_STATE, value: -1, likesDelta: 0, dislikesDelta: 1 },
},
[LIKED_STATE]: {
[LIKE_ACTION]: { nextState: NEUTRAL_STATE, value: 0, likesDelta: -1, dislikesDelta: 0 },
[DISLIKE_ACTION]: { nextState: DISLIKED_STATE, value: -1, likesDelta: -1, dislikesDelta: 1 },
},
[DISLIKED_STATE]: {
[LIKE_ACTION]: { nextState: LIKED_STATE, value: 1, likesDelta: 1, dislikesDelta: -1 },
[DISLIKE_ACTION]: { nextState: NEUTRAL_STATE, value: 0, likesDelta: 0, dislikesDelta: -1 },
},
};
function resolveVoteTransition(previousState, action) {
const transition = TRANSITIONS[previousState]?.[action];
if (!transition) {
throw new TypeError(`Unsupported vote transition: ${previousState} -> ${action}`);
}
return { ...transition };
}
function applyVoteTransitionCounts(likes, dislikes, transition) {
if (!transition || !Number.isFinite(transition.likesDelta) || !Number.isFinite(transition.dislikesDelta)) {
throw new TypeError("A valid vote transition is required");
}
const normalizedLikes = Number.isFinite(likes) ? likes : 0;
const normalizedDislikes = Number.isFinite(dislikes) ? dislikes : 0;
return {
likes: Math.max(0, normalizedLikes + transition.likesDelta),
dislikes: Math.max(0, normalizedDislikes + transition.dislikesDelta),
};
}
function shouldSubmitVote({ disableVoteSubmission = false, signedOut = false } = {}) {
return disableVoteSubmission !== true && signedOut !== true;
}
module.exports = {
DISLIKED_STATE,
DISLIKE_ACTION,
LIKED_STATE,
LIKE_ACTION,
NEUTRAL_STATE,
applyVoteTransitionCounts,
resolveVoteTransition,
shouldSubmitVote,
};
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
"use strict";
;// CONCATENATED MODULE: ./Extensions/common/vote-client.js
const DEFAULT_API_BASE_URL = "https://returnyoutubedislikeapi.com";
@@ -352,54 +447,248 @@ function createVoteClient({
;// CONCATENATED MODULE: ./Extensions/common/vote-transition.js
const LIKED_STATE = "LIKED_STATE";
const DISLIKED_STATE = "DISLIKED_STATE";
const NEUTRAL_STATE = "NEUTRAL_STATE";
const LIKE_ACTION = "like";
const DISLIKE_ACTION = "dislike";
const TRANSITIONS = {
[NEUTRAL_STATE]: {
[LIKE_ACTION]: { nextState: LIKED_STATE, value: 1, likesDelta: 1, dislikesDelta: 0 },
[DISLIKE_ACTION]: { nextState: DISLIKED_STATE, value: -1, likesDelta: 0, dislikesDelta: 1 },
},
[LIKED_STATE]: {
[LIKE_ACTION]: { nextState: NEUTRAL_STATE, value: 0, likesDelta: -1, dislikesDelta: 0 },
[DISLIKE_ACTION]: { nextState: DISLIKED_STATE, value: -1, likesDelta: -1, dislikesDelta: 1 },
},
[DISLIKED_STATE]: {
[LIKE_ACTION]: { nextState: LIKED_STATE, value: 1, likesDelta: 1, dislikesDelta: -1 },
[DISLIKE_ACTION]: { nextState: NEUTRAL_STATE, value: 0, likesDelta: 0, dislikesDelta: -1 },
},
};
function resolveVoteTransition(previousState, action) {
const transition = TRANSITIONS[previousState]?.[action];
if (!transition) {
throw new TypeError(`Unsupported vote transition: ${previousState} -> ${action}`);
;// CONCATENATED MODULE: ./Extensions/common/delegated-vote-activation.js
function defaultGetActivationTarget(control) {
if (control?.matches?.("button, tp-yt-paper-button#button")) {
return control;
}
return { ...transition };
return control?.querySelector?.("button, tp-yt-paper-button#button") ?? control ?? null;
}
function applyVoteTransitionCounts(likes, dislikes, transition) {
if (!transition || !Number.isFinite(transition.likesDelta) || !Number.isFinite(transition.dislikesDelta)) {
throw new TypeError("A valid vote transition is required");
function isHiddenWithinButtons(activationTarget, buttons) {
let current = activationTarget;
while (current) {
if (
current.hidden === true ||
current.getAttribute?.("aria-hidden") === "true" ||
current.hasAttribute?.("inert") ||
current.style?.display === "none" ||
current.style?.visibility === "hidden"
) {
return true;
}
if (current === buttons) {
return false;
}
current = current.parentElement;
}
return true;
}
function eventActivatesTarget(event, activationTarget) {
const eventPath = typeof event?.composedPath === "function" ? event.composedPath() : [];
if (eventPath.includes(activationTarget)) {
return true;
}
const eventTarget = event?.target;
return Boolean(eventTarget && activationTarget?.contains?.(eventTarget));
}
function resolveDelegatedVoteActivation({
buttons,
dislikeButton,
event,
getActivationTarget = defaultGetActivationTarget,
likeButton,
}) {
if (!event || !buttons?.isConnected) {
return null;
}
const normalizedLikes = Number.isFinite(likes) ? likes : 0;
const normalizedDislikes = Number.isFinite(dislikes) ? dislikes : 0;
for (const [action, control] of [
["dislike", dislikeButton],
["like", likeButton],
]) {
if (!control?.isConnected || !buttons.contains(control)) {
continue;
}
const activationTarget = getActivationTarget(control);
if (
!activationTarget?.isConnected ||
!control.contains(activationTarget) ||
isHiddenWithinButtons(activationTarget, buttons) ||
activationTarget.disabled === true ||
activationTarget.getAttribute?.("aria-disabled") === "true"
) {
continue;
}
if (eventActivatesTarget(event, activationTarget)) {
return { action, activationTarget };
}
}
return null;
}
;// CONCATENATED MODULE: ./Extensions/common/shorts-control-readiness.js
const SHORTS_HYDRATED_SURFACE_STABILITY_MS = 250;
const SHORTS_UNHYDRATED_SURFACE_STABILITY_MS = 1500;
const SHORTS_LINK_SELECTOR = "a[href*='/shorts/']";
const SHORTS_CANONICAL_PLAYER_LINK_SELECTOR = "a.ytp-title-link[href*='/shorts/']";
const SHORTS_ICON_GRAPHIC_SELECTOR = "path, circle, ellipse, line, polygon, polyline, rect";
function getShortsIdentityLinkVideoIds(root, baseUrl = "https://www.youtube.com/") {
const identities = new Set();
if (!root?.querySelectorAll) {
return identities;
}
const links = Array.from(root.querySelectorAll(SHORTS_LINK_SELECTOR));
const canonicalPlayerLinks = links.filter((link) => link.matches(SHORTS_CANONICAL_PLAYER_LINK_SELECTOR));
// The player title link identifies the reel. Other /shorts/ links can be
// unrelated calls to action in the current Short's description/metapanel.
// Choose the canonical subset before parsing so malformed player metadata
// cannot make an unrelated description link look authoritative.
const identityLinks = canonicalPlayerLinks.length > 0 ? canonicalPlayerLinks : links;
for (const link of identityLinks) {
try {
const href = link.getAttribute("href");
if (!href) continue;
const videoId = new URL(href, baseUrl).pathname.match(/^\/shorts\/([^/]+)\/?$/)?.[1];
if (videoId) identities.add(videoId);
} catch {
// Ignore malformed or incomplete links while YouTube hydrates the reel.
}
}
return identities;
}
function getShortsControlSurfaceStabilityMs(isHydrated) {
return isHydrated ? SHORTS_HYDRATED_SURFACE_STABILITY_MS : SHORTS_UNHYDRATED_SURFACE_STABILITY_MS;
}
function isShortsControlSurfaceReadyForMutation({
allowUnhydratedFallback = false,
candidateVideoIds = [],
currentVideoId,
isConnected,
isHydrated,
isRendered,
isStable,
isViewportIntersecting,
visibleCandidateCount,
}) {
const uniqueCandidateVideoIds = new Set(Array.from(candidateVideoIds).filter(Boolean));
const hasExactIdentity = uniqueCandidateVideoIds.size === 1 && uniqueCandidateVideoIds.has(currentVideoId);
const isUnambiguousIdentitylessSurface = uniqueCandidateVideoIds.size === 0 && visibleCandidateCount === 1;
return Boolean(
currentVideoId &&
isConnected &&
(isHydrated || allowUnhydratedFallback) &&
isRendered &&
isStable &&
isViewportIntersecting &&
(hasExactIdentity || isUnambiguousIdentitylessSurface),
);
}
function actionBarHasHydratedData(actionBar) {
return Boolean(actionBar) && (!("data" in actionBar) || Boolean(actionBar.data));
}
function capturePaintedShortsIcon(button) {
const svg = button?.querySelector("svg") ?? null;
if (!svg?.isConnected) return null;
const graphic = Array.from(svg.querySelectorAll(SHORTS_ICON_GRAPHIC_SELECTOR)).find(
(candidate) => candidate.tagName.toLowerCase() !== "path" || (candidate.getAttribute("d") ?? "").trim().length > 0,
);
if (!graphic?.isConnected) return null;
const rect = svg.getBoundingClientRect();
if (!(rect.width > 0 && rect.height > 0)) return null;
return { graphic, svg };
}
function captureShortsNativeControlInventory(
actionBar,
{ syntheticSelector = "[data-ryd-synthetic-shorts-dislike]" } = {},
) {
const nativeChildren = Array.from(actionBar?.children ?? []).filter((child) => !child.matches(syntheticSelector));
const likeButton = actionBar?.querySelector("like-button-view-model") ?? null;
const nativeLikeButton = likeButton?.querySelector("button") ?? null;
const nativeLikeIcon = capturePaintedShortsIcon(nativeLikeButton);
const activationTargets = nativeChildren.map((child) =>
child.querySelector("button, a[href], a[role='button'][tabindex='0'], tp-yt-paper-button#button"),
);
if (
!likeButton?.isConnected ||
!nativeLikeButton?.isConnected ||
!nativeLikeIcon ||
nativeChildren.length < 4 ||
!nativeChildren.includes(likeButton) ||
activationTargets.some((target) => !target?.isConnected)
) {
return null;
}
return {
likes: Math.max(0, normalizedLikes + transition.likesDelta),
dislikes: Math.max(0, normalizedDislikes + transition.dislikesDelta),
activationTargets,
likeButton,
nativeChildren,
nativeLikeButton,
nativeLikeGraphic: nativeLikeIcon.graphic,
nativeLikeSvg: nativeLikeIcon.svg,
};
}
function shouldSubmitVote({ disableVoteSubmission = false, signedOut = false } = {}) {
return disableVoteSubmission !== true && signedOut !== true;
function shortsNativeControlInventoryMatches(left, right) {
return Boolean(
left &&
right &&
left.likeButton === right.likeButton &&
left.nativeLikeButton === right.nativeLikeButton &&
left.nativeLikeGraphic === right.nativeLikeGraphic &&
left.nativeLikeSvg === right.nativeLikeSvg &&
left.nativeChildren.length === right.nativeChildren.length &&
left.nativeChildren.every((child, index) => child === right.nativeChildren[index]) &&
left.activationTargets.every((target, index) => target === right.activationTargets[index]),
);
}
function shortsNativeControlInventoryIsReadyForFallback(
inventory,
{ getTopmostElement, isMeaningfullyInViewport, isRendered },
) {
if (
!inventory?.activationTargets?.length ||
typeof getTopmostElement !== "function" ||
typeof isMeaningfullyInViewport !== "function" ||
typeof isRendered !== "function"
) {
return false;
}
return inventory.activationTargets.every((target) => {
if (!target?.isConnected || !isRendered(target) || !isMeaningfullyInViewport(target)) {
return false;
}
const rect = target.getBoundingClientRect();
const topmostElement = getTopmostElement(rect.left + rect.width / 2, rect.top + rect.height / 2);
return Boolean(topmostElement && (topmostElement === target || target.contains(topmostElement)));
});
}
;// CONCATENATED MODULE: ./Extensions/common/vote-transition.js
const {
DISLIKED_STATE,
DISLIKE_ACTION,
LIKED_STATE,
LIKE_ACTION,
NEUTRAL_STATE,
applyVoteTransitionCounts,
resolveVoteTransition,
shouldSubmitVote,
} = __webpack_require__(26);
;// CONCATENATED MODULE: ./Extensions/UserScript/src/gm-credential-store.js
@@ -573,6 +862,8 @@ const userscript_version_namespaceObject = "3.2.0";
if (false) {}
const API_BASE_URL = "https://returnyoutubedislikeapi.com";
@@ -615,7 +906,6 @@ function getShortVideoIdFromPathname(pathname) {
let isShorts = () => getShortVideoIdFromPathname(location.pathname) !== null;
let mobileDislikes = 0;
let suppressNextLikeActivation = false;
const boundLikeButtons = new WeakSet();
const boundDislikeButtons = new WeakSet();
const boundActivationVideoIds = new WeakMap();
const suppressedStaleRefreshTargets = new WeakSet();
@@ -628,6 +918,7 @@ let shortsLifecycleObserver = null;
let shortsLifecycleObserverTarget = null;
let initializationGeneration = 0;
let initializationTimer = null;
let pendingShortsMutationSurface = null;
let activeCountRequest = null;
let countStateVideoId = null;
let countStateLoaded = false;
@@ -672,6 +963,16 @@ function intersectsViewport(element) {
);
}
function hasMeaningfulViewportPresence(element) {
const rect = element?.getBoundingClientRect?.();
if (!rect || rect.width <= 0 || rect.height <= 0) return false;
const height = innerHeight || document.documentElement.clientHeight;
const width = innerWidth || document.documentElement.clientWidth;
const visibleWidth = Math.max(0, Math.min(rect.right, width) - Math.max(rect.left, 0));
const visibleHeight = Math.max(0, Math.min(rect.bottom, height) - Math.max(rect.top, 0));
return (visibleWidth * visibleHeight) / (rect.width * rect.height) >= 0.5;
}
function hasRenderedBox(element) {
if (!element?.isConnected || element.closest("[hidden], [aria-hidden='true'], [inert]")) {
return false;
@@ -693,26 +994,22 @@ function hasRenderedBox(element) {
function getRendererShortVideoIds(renderer) {
const identities = new Set();
if (!renderer) {
return identities;
}
const attributeVideoId = renderer.getAttribute("video-id");
if (attributeVideoId) {
identities.add(attributeVideoId);
return identities;
}
for (const link of renderer.querySelectorAll('a[href*="/shorts/"]')) {
try {
const linkVideoId = getShortVideoIdFromPathname(new URL(link.getAttribute("href"), location.origin).pathname);
if (linkVideoId) {
identities.add(linkVideoId);
}
} catch {
// Ignore malformed or incomplete links while YouTube hydrates the reel.
}
for (const linkVideoId of getShortsIdentityLinkVideoIds(renderer, location.href)) {
identities.add(linkVideoId);
}
return identities;
}
function rendererMatchesShort(renderer, videoId) {
return Boolean(videoId) && getRendererShortVideoIds(renderer).has(videoId);
const videoIds = getRendererShortVideoIds(renderer);
return Boolean(videoId) && videoIds.size === 1 && videoIds.has(videoId);
}
function getControlOwnershipVideoIds(container) {
@@ -995,9 +1292,9 @@ function getActiveDesktopShortsActionBar() {
}))
.filter(({ actionBar }) => actionBar);
const matchingCandidate = candidates.find(({ renderer }) => rendererMatchesShort(renderer, videoId));
if (matchingCandidate) {
return matchingCandidate.actionBar;
const matchingCandidates = candidates.filter(({ renderer }) => rendererMatchesShort(renderer, videoId));
if (matchingCandidates.length === 1) {
return matchingCandidates[0].actionBar;
}
// During channel/watch -> Shorts SPA transitions, YouTube can render the active
@@ -1021,6 +1318,47 @@ function getActiveDesktopShortsActionBar() {
return fullyVisibleCandidates.length === 1 ? fullyVisibleCandidates[0].actionBar : null;
}
function getShortsControlSurfaceSignature(buttons) {
return (
Array.from(getRendererShortVideoIds(buttons?.closest("ytd-reel-video-renderer")))
.sort()
.join("|") || "identityless"
);
}
function getVisibleDesktopShortsControlSurfaceCount() {
return Array.from(document.querySelectorAll("reel-action-bar-view-model")).filter(
(candidate) => hasRenderedBox(candidate) && hasMeaningfulViewportPresence(candidate),
).length;
}
function shortsControlSurfaceIsReadyForMutation(
buttons,
currentVideoId,
{ allowUnhydratedFallback = false, isHydrated = false, isStable = false } = {},
) {
return isShortsControlSurfaceReadyForMutation({
allowUnhydratedFallback,
candidateVideoIds: getRendererShortVideoIds(buttons?.closest("ytd-reel-video-renderer")),
currentVideoId,
isConnected: buttons?.isConnected,
isHydrated,
isRendered: hasRenderedBox(buttons),
isStable,
isViewportIntersecting: hasMeaningfulViewportPresence(buttons),
visibleCandidateCount: getVisibleDesktopShortsControlSurfaceCount(),
});
}
function userscript_entry_shortsNativeControlInventoryIsReadyForFallback(inventory) {
return shortsNativeControlInventoryIsReadyForFallback(inventory, {
getTopmostElement:
typeof document.elementFromPoint === "function" ? (x, y) => document.elementFromPoint(x, y) : null,
isMeaningfullyInViewport: hasMeaningfulViewportPresence,
isRendered: hasRenderedBox,
});
}
function getActiveMobileShortsButtons() {
const videoId = getVideoId();
const candidates = Array.from(document.querySelectorAll("ytm-like-button-renderer"))
@@ -1043,18 +1381,7 @@ function getActiveMobileShortsButtons() {
}
function getExactShortLinkVideoIds(element) {
const identities = new Set();
for (const link of element.querySelectorAll('a[href*="/shorts/"]')) {
try {
const linkVideoId = getShortVideoIdFromPathname(new URL(link.getAttribute("href"), location.origin).pathname);
if (linkVideoId) {
identities.add(linkVideoId);
}
} catch {
// Ignore malformed or incomplete links while YouTube hydrates the reel.
}
}
return identities;
return getShortsIdentityLinkVideoIds(element, location.href);
}
function getMobileShortOwnership(buttons) {
@@ -1186,19 +1513,32 @@ function removeSyntheticShortsDislike(syntheticDislike) {
}
}
function ensureSyntheticShortsDislikeButton(buttons) {
function ensureSyntheticShortsDislikeButton(
buttons,
{ allowUnhydratedFallback = false, currentVideoId = getVideoId(), isHydrated = false, isStable = false } = {},
) {
if (!isShorts() || isMobile || !buttons) {
return;
}
const syntheticDislike = buttons.querySelector(SYNTHETIC_SHORTS_DISLIKE_SELECTOR);
const syntheticDislikes = Array.from(buttons.querySelectorAll(SYNTHETIC_SHORTS_DISLIKE_SELECTOR));
const syntheticDislike = syntheticDislikes[0];
const nativeDislike = buttons.querySelector("dislike-button-view-model, #dislike-button");
const readyForMutation = shortsControlSurfaceIsReadyForMutation(buttons, currentVideoId, {
allowUnhydratedFallback,
isHydrated: isHydrated && actionBarHasHydratedData(buttons),
isStable,
});
if (nativeDislike) {
removeSyntheticShortsDislike(syntheticDislike);
if (readyForMutation) syntheticDislikes.forEach(removeSyntheticShortsDislike);
return;
}
if (!readyForMutation) {
return;
}
if (syntheticDislike) {
const videoId = getVideoId();
syntheticDislikes.slice(1).forEach(removeSyntheticShortsDislike);
const videoId = currentVideoId;
if (videoId && syntheticDislike.getAttribute("data-ryd-video-id") !== videoId) {
syntheticDislike.setAttribute("data-ryd-video-id", videoId);
setSyntheticShortsPressed(false, syntheticDislike);
@@ -1272,9 +1612,7 @@ function ensureSyntheticShortsDislikeButton(buttons) {
likeButton.insertAdjacentElement("afterend", ownedDislike);
}
function getDislikeButton() {
const buttons = getButtons();
ensureSyntheticShortsDislikeButton(buttons);
function getDislikeButton(buttons = getButtons()) {
if (buttons?.tagName === "REEL-ACTION-BAR-VIEW-MODEL") {
return (
buttons.querySelector("dislike-button-view-model, #dislike-button") ??
@@ -1303,8 +1641,7 @@ function getDislikeButton() {
}
}
function getLikeButton() {
const buttons = getButtons();
function getLikeButton(buttons = getButtons()) {
const firstButton = buttons?.children?.[0];
if (!firstButton) {
return null;
@@ -1325,18 +1662,27 @@ function getLikeTextContainer() {
);
}
function getDislikeTextContainer() {
const dislikeButton = getDislikeButton();
function getDislikeTextContainer(dislikeButton = getDislikeButton()) {
if (!dislikeButton) {
return null;
}
let result =
dislikeButton?.querySelector("#text") ??
dislikeButton?.getElementsByTagName("yt-formatted-string")[0] ??
dislikeButton?.querySelector("span[role='text']");
if (result === null) {
let textSpan = document.createElement("span");
dislikeButton.querySelector("#text") ??
dislikeButton.getElementsByTagName("yt-formatted-string")[0] ??
dislikeButton.querySelector("span[role='text']");
if (result == null) {
const activationTarget = getActivationTarget(dislikeButton);
if (!activationTarget?.matches("button, tp-yt-paper-button#button")) {
return null;
}
const textSpan = document.createElement("span");
textSpan.id = "text";
textSpan.setAttribute("role", "text");
textSpan.style.marginLeft = "6px";
dislikeButton?.querySelector("button").appendChild(textSpan);
if (dislikeButton) dislikeButton.querySelector("button").style.width = "auto";
activationTarget.appendChild(textSpan);
activationTarget.style.width = "auto";
result = textSpan;
}
return result;
@@ -1391,6 +1737,9 @@ function createObserver(options, callback) {
observerWrapper.disconnect = function () {
this.observer.disconnect();
};
observerWrapper.takeRecords = function () {
return this.observer.takeRecords();
};
return observerWrapper;
}
@@ -1850,11 +2199,7 @@ function removeWatchRateBarArtifacts(buttons) {
}
}
function clearStaleWatchPresentation(buttons, dislikeButton, videoId) {
if (isMobile || isShorts() || !initializedVideoId || initializedVideoId === videoId) {
return;
}
function clearWatchPresentation(buttons, dislikeButton) {
removeWatchRateBarArtifacts(buttons);
const dislikeText =
dislikeButton?.querySelector("#text") ??
@@ -1865,6 +2210,14 @@ function clearStaleWatchPresentation(buttons, dislikeButton, videoId) {
}
}
function clearStaleWatchPresentation(buttons, dislikeButton, videoId) {
if (isMobile || isShorts() || !initializedVideoId || initializedVideoId === videoId) {
return;
}
clearWatchPresentation(buttons, dislikeButton);
}
function canRepairWatchRateBar(buttons, videoId) {
if (
isMobile ||
@@ -2022,8 +2375,14 @@ function setState() {
}
function updateDOMDislikes() {
const videoId = getVideoId();
if (!videoId || !countStateLoaded || countStateVideoId !== videoId) {
return false;
}
setDislikes(numberFormat(dislikesvalue));
createRateBar(likesvalue, dislikesvalue);
return true;
}
function reportVoteFailure(error) {
@@ -2208,6 +2567,49 @@ function dislikeClicked(event) {
handleVoteActivation(DISLIKE_ACTION);
}
function handleDelegatedVoteClick(event) {
const buttons = getButtons();
const likeButton = getLikeButton(buttons);
const dislikeButton = getDislikeButton(buttons);
const activation = resolveDelegatedVoteActivation({
buttons,
dislikeButton,
event,
getActivationTarget,
likeButton,
});
if (!activation) {
return;
}
const videoId = getVideoId();
if (!videoId) {
return;
}
const targetHydration = hydratingShortsActivationTargets.get(activation.activationTarget);
const hydration = targetHydration?.videoId === videoId ? targetHydration : null;
if (targetHydration && !hydration) {
hydratingShortsActivationTargets.delete(activation.activationTarget);
}
const targetIsBoundToCurrentVideo = boundActivationVideoIds.get(activation.activationTarget) === videoId;
const currentCountStateIsLoaded = countStateLoaded && countStateVideoId === videoId;
const isUnboundCurrentShortsActivation = isShorts() && !hydration && !targetIsBoundToCurrentVideo;
if (!hydration && !targetIsBoundToCurrentVideo && !currentCountStateIsLoaded && !isUnboundCurrentShortsActivation) {
return;
}
if (isUnboundCurrentShortsActivation) {
previousState = getState();
}
boundActivationVideoIds.set(activation.activationTarget, videoId);
const delegatedEvent = { currentTarget: activation.activationTarget };
if (activation.action === LIKE_ACTION) {
likeClicked(delegatedEvent);
} else {
dislikeClicked(delegatedEvent);
}
}
function refreshDislikesForBoundControl(event) {
if (boundActivationVideoIds.get(event.currentTarget) === getVideoId()) {
updateDOMDislikes();
@@ -2419,9 +2821,14 @@ function shortsControlsNeedInitialization() {
const buttons = getButtons();
const likeButton = getLikeButton();
const dislikeButton = getDislikeButton();
const syntheticDislikes = buttons?.querySelectorAll?.(SYNTHETIC_SHORTS_DISLIKE_SELECTOR).length ?? 0;
const hasNativeDislike = Boolean(buttons?.querySelector?.("dislike-button-view-model, #dislike-button"));
if (!buttons || !likeButton || !dislikeButton) {
return true;
}
if ((hasNativeDislike && syntheticDislikes > 0) || (!hasNativeDislike && syntheticDislikes !== 1)) {
return true;
}
if (
initializedVideoId !== videoId ||
initializedLikeButton !== likeButton ||
@@ -2573,12 +2980,7 @@ function bindVoteButtonListeners(likeButton, dislikeButton, { enableSynthetic =
const videoId = getVideoId();
boundActivationVideoIds.set(likeActivationTarget, videoId);
boundActivationVideoIds.set(dislikeActivationTarget, videoId);
if (!boundLikeButtons.has(likeActivationTarget)) {
likeActivationTarget.addEventListener("click", likeClicked);
boundLikeButtons.add(likeActivationTarget);
}
if (!boundDislikeButtons.has(dislikeActivationTarget)) {
dislikeActivationTarget.addEventListener("click", dislikeClicked);
dislikeActivationTarget.addEventListener("focusin", refreshDislikesForBoundControl);
dislikeActivationTarget.addEventListener("focusout", refreshDislikesForBoundControl);
boundDislikeButtons.add(dislikeActivationTarget);
@@ -2589,6 +2991,106 @@ function bindVoteButtonListeners(likeButton, dislikeButton, { enableSynthetic =
}
}
function getStableDesktopShortsControls(videoId, generation) {
const buttons = getButtons();
const inventory = captureShortsNativeControlInventory(buttons);
const isHydrated = actionBarHasHydratedData(buttons);
if (
!buttons ||
!inventory ||
(!isHydrated && !userscript_entry_shortsNativeControlInventoryIsReadyForFallback(inventory)) ||
!shortsControlSurfaceIsReadyForMutation(buttons, videoId, {
allowUnhydratedFallback: !isHydrated,
isHydrated,
isStable: true,
})
) {
pendingShortsMutationSurface = null;
return null;
}
const signature = getShortsControlSurfaceSignature(buttons);
const now = performance.now();
if (
pendingShortsMutationSurface?.buttons !== buttons ||
pendingShortsMutationSurface.generation !== generation ||
pendingShortsMutationSurface.videoId !== videoId ||
pendingShortsMutationSurface.signature !== signature ||
!shortsNativeControlInventoryMatches(pendingShortsMutationSurface.inventory, inventory)
) {
pendingShortsMutationSurface = {
buttons,
generation,
inventory,
observedAt: now,
signature,
unhydratedObservedAt: isHydrated ? null : now,
videoId,
};
return null;
}
if (isHydrated) {
pendingShortsMutationSurface.unhydratedObservedAt = null;
} else if (pendingShortsMutationSurface.unhydratedObservedAt == null) {
pendingShortsMutationSurface.unhydratedObservedAt = now;
}
const stabilityObservedAt = isHydrated
? pendingShortsMutationSurface.observedAt
: pendingShortsMutationSurface.unhydratedObservedAt;
if (now - stabilityObservedAt < getShortsControlSurfaceStabilityMs(isHydrated)) {
return null;
}
const allowUnhydratedFallback = !isHydrated;
const preMutationButtons = getButtons();
const preMutationInventory = captureShortsNativeControlInventory(preMutationButtons);
const preMutationIsHydrated = actionBarHasHydratedData(preMutationButtons);
const preMutationAllowsFallback = !preMutationIsHydrated && allowUnhydratedFallback;
if (
preMutationButtons !== buttons ||
!shortsNativeControlInventoryMatches(inventory, preMutationInventory) ||
(preMutationAllowsFallback && !userscript_entry_shortsNativeControlInventoryIsReadyForFallback(preMutationInventory)) ||
getShortsControlSurfaceSignature(preMutationButtons) !== signature ||
!shortsControlSurfaceIsReadyForMutation(preMutationButtons, videoId, {
allowUnhydratedFallback: preMutationAllowsFallback,
isHydrated: preMutationIsHydrated,
isStable: true,
})
) {
pendingShortsMutationSurface = null;
return null;
}
ensureSyntheticShortsDislikeButton(preMutationButtons, {
allowUnhydratedFallback: preMutationAllowsFallback,
currentVideoId: videoId,
isHydrated: preMutationIsHydrated,
isStable: true,
});
const confirmedButtons = getButtons();
const confirmedInventory = captureShortsNativeControlInventory(confirmedButtons);
const confirmedIsHydrated = actionBarHasHydratedData(confirmedButtons);
if (
confirmedButtons !== buttons ||
!shortsNativeControlInventoryMatches(inventory, confirmedInventory) ||
(preMutationAllowsFallback && !userscript_entry_shortsNativeControlInventoryIsReadyForFallback(confirmedInventory)) ||
getShortsControlSurfaceSignature(confirmedButtons) !== signature ||
!shortsControlSurfaceIsReadyForMutation(confirmedButtons, videoId, {
allowUnhydratedFallback: !confirmedIsHydrated && preMutationAllowsFallback,
isHydrated: confirmedIsHydrated,
isStable: true,
})
) {
pendingShortsMutationSurface = null;
return null;
}
pendingShortsMutationSurface = null;
return confirmedButtons;
}
async function initializeCurrentButtons(generation) {
const videoId = getVideoId();
if (!videoId) {
@@ -2602,15 +3104,31 @@ async function initializeCurrentButtons(generation) {
return false;
}
const buttons = getButtons();
const likeButton = getLikeButton();
const dislikeButton = getDislikeButton();
let buttons = getButtons();
const needsStableShortsControls =
isShorts() &&
!isMobile &&
buttons?.tagName === "REEL-ACTION-BAR-VIEW-MODEL" &&
(!buttons.querySelector("dislike-button-view-model, #dislike-button") ||
buttons.querySelector(SYNTHETIC_SHORTS_DISLIKE_SELECTOR) ||
!actionBarHasHydratedData(buttons));
if (needsStableShortsControls) {
buttons = getStableDesktopShortsControls(videoId, generation);
if (!buttons) {
return false;
}
}
const likeButton = getLikeButton(buttons);
const dislikeButton = getDislikeButton(buttons);
if (!buttons || !likeButton || !dislikeButton) {
return false;
}
if (!isShorts() && !watchControlsAreReadyForVideo(buttons, likeButton, dislikeButton, videoId)) {
return false;
}
if (!isShorts() && !getDislikeTextContainer(dislikeButton)) {
return false;
}
observeShortsLifecycle(buttons);
observeWatchRateBar(buttons, videoId);
@@ -2795,7 +3313,13 @@ function checkPageLifecycle() {
}
function handleNavigateStart() {
pendingShortsMutationSurface = null;
disconnectWatchRateBarObserver();
if (smartimationObserver) {
smartimationObserver.takeRecords();
smartimationObserver.disconnect();
smartimationObserver.container = null;
}
clearPendingWatchNavigationBoundary();
clearPendingWatchControlObservers();
if (isShorts()) {
@@ -2823,6 +3347,11 @@ function handleNavigateStart() {
return;
}
activeCountRequest = null;
countStateLoaded = false;
countStateEpoch += 1;
clearWatchPresentation(buttons, dislikeButton);
const boundary = {
buttons,
completedVideoId: null,
@@ -2874,6 +3403,7 @@ function handleNavigateFinish(event) {
(function () {
"use strict";
void voteClient.ensureRegistered().catch(reportVoteFailure);
document.addEventListener("click", handleDelegatedVoteClick, true);
window.addEventListener("yt-navigate-start", handleNavigateStart, true);
window.addEventListener("yt-navigate-finish", handleNavigateFinish, true);
window.addEventListener("popstate", checkPageLifecycle, true);
@@ -2892,5 +3422,7 @@ if (isMobile) {
}, 1000);
}
})();
/******/ })()
;