mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-24 07:13:02 +01:00
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:
1 parent
3657de9b2c
commit
e500088e65
196 files changed
+39706
-2694
No files matched your search
@@ -29,6 +29,15 @@
|
||||
min-width: 96px;
|
||||
}
|
||||
|
||||
/* Model YouTube's overlaid Shorts next control without causing a document scroll on activation. */
|
||||
#short-next {
|
||||
margin: 0;
|
||||
position: fixed;
|
||||
right: 4px;
|
||||
top: 4px;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
ytd-watch-flexy,
|
||||
ytd-menu-renderer,
|
||||
segmented-like-dislike-button-view-model,
|
||||
@@ -49,6 +58,19 @@
|
||||
}
|
||||
|
||||
segmented-like-dislike-button-view-model {
|
||||
display: block;
|
||||
min-height: 48px;
|
||||
width: 320px;
|
||||
}
|
||||
|
||||
segmented-like-dislike-button-view-model > yt-smartimation,
|
||||
[data-fixture-smartimation-content-shell] {
|
||||
display: block;
|
||||
min-height: 48px;
|
||||
width: 320px;
|
||||
}
|
||||
|
||||
[data-fixture-smartimation-content] {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
min-height: 48px;
|
||||
@@ -60,10 +82,26 @@
|
||||
min-width: 96px;
|
||||
}
|
||||
|
||||
[data-fixture-watch-icon] {
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
[data-fixture-touch-feedback] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
ytd-reel-video-renderer {
|
||||
display: block;
|
||||
min-height: 640px;
|
||||
width: 420px;
|
||||
width: min(420px, 100%);
|
||||
}
|
||||
|
||||
.reel-video-in-sequence-new,
|
||||
.reel-video-in-sequence-thumbnail {
|
||||
display: block;
|
||||
min-height: 1px;
|
||||
min-width: 1px;
|
||||
}
|
||||
|
||||
ytd-reel-video-renderer[hidden] {
|
||||
@@ -155,11 +193,27 @@
|
||||
(() => {
|
||||
const firstVideoId = "__VIDEO_ID__";
|
||||
const secondVideoId = "__SECOND_VIDEO_ID__";
|
||||
const nativeLikesByVideo = new Map([
|
||||
[firstVideoId, Number("__VIDEO_LIKES__")],
|
||||
[secondVideoId, Number("__SECOND_VIDEO_LIKES__")],
|
||||
]);
|
||||
const marker = "rydNavigationFixture=1";
|
||||
const navigation = document.getElementById("fixture-navigation");
|
||||
const page = document.getElementById("fixture-page");
|
||||
const isMobile = location.hostname === "m.youtube.com";
|
||||
const fixtureBaseline = {
|
||||
renderedDesktopShortsNativeDislikes: null,
|
||||
renderedMobileShortsNativeDislikes: null,
|
||||
renderedWatchNativeDislikeTextCount: null,
|
||||
};
|
||||
const nativeReactionStats = {
|
||||
activations: 0,
|
||||
dislikeActivations: 0,
|
||||
likeActivations: 0,
|
||||
};
|
||||
globalThis.__navigationFixtureBaseline = fixtureBaseline;
|
||||
let pendingDelayedRender = null;
|
||||
let pendingStartedWatchRender = null;
|
||||
|
||||
if (!customElements.get("like-button-view-model")) {
|
||||
customElements.define(
|
||||
@@ -178,6 +232,55 @@
|
||||
return `/@FixtureChannel?${marker}`;
|
||||
};
|
||||
|
||||
const nativeLikes = (videoId) => nativeLikesByVideo.get(videoId) ?? 100;
|
||||
|
||||
function setNativeLikeCount(root, videoId) {
|
||||
const count = nativeLikes(videoId);
|
||||
const like = root?.querySelector('[data-fixture-role="like"]');
|
||||
like?.querySelector("button")?.setAttribute("aria-label", `${count} likes`);
|
||||
const text = like?.querySelector("#text, [role='text']");
|
||||
if (text) text.textContent = String(count);
|
||||
}
|
||||
|
||||
function setNativeReactionPressed(control, pressed) {
|
||||
control?.classList.toggle("style-default-active", pressed);
|
||||
control?.classList.toggle("style-text", !pressed);
|
||||
control?.querySelector("button")?.setAttribute("aria-pressed", String(pressed));
|
||||
}
|
||||
|
||||
function adjustNativeLikeCount(like, delta) {
|
||||
const text = like?.querySelector("#text, [role='text']");
|
||||
const count = Number.parseInt(text?.textContent, 10);
|
||||
if (!text || !Number.isFinite(count)) return;
|
||||
text.textContent = String(Math.max(0, count + delta));
|
||||
}
|
||||
|
||||
document.addEventListener(
|
||||
"click",
|
||||
(event) => {
|
||||
const nativeButton = event.target.closest("button");
|
||||
const control = nativeButton?.closest('[data-fixture-role="like"], [data-fixture-role="dislike"]');
|
||||
if (!control || control.querySelector("button") !== nativeButton) return;
|
||||
|
||||
const controls = control.closest('[data-fixture-role="buttons"]');
|
||||
const role = control.getAttribute("data-fixture-role");
|
||||
const like = controls?.querySelector('[data-fixture-role="like"]');
|
||||
const dislike = controls?.querySelector('[data-fixture-role="dislike"]');
|
||||
const wasPressed = nativeButton.getAttribute("aria-pressed") === "true";
|
||||
const counterpart = role === "like" ? dislike : like;
|
||||
const counterpartWasPressed = counterpart?.querySelector("button")?.getAttribute("aria-pressed") === "true";
|
||||
|
||||
nativeReactionStats.activations += 1;
|
||||
nativeReactionStats[`${role}Activations`] += 1;
|
||||
|
||||
setNativeReactionPressed(control, !wasPressed);
|
||||
if (!wasPressed) setNativeReactionPressed(counterpart, false);
|
||||
if (role === "like") adjustNativeLikeCount(like, wasPressed ? -1 : 1);
|
||||
if (role === "dislike" && !wasPressed && counterpartWasPressed) adjustNativeLikeCount(like, -1);
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
const linkMarkup = (id, label, pageKind, videoId, options = {}) => `
|
||||
<a
|
||||
id="${id}"
|
||||
@@ -192,13 +295,13 @@
|
||||
const decoyControls = isMobile
|
||||
? `
|
||||
<div class="slim-video-action-bar-actions" data-fixture-decoy-controls>
|
||||
<div class="segmented-buttons" data-ryd-role="buttons">
|
||||
<like-button-view-model class="style-text" data-ryd-role="like">
|
||||
<div class="segmented-buttons" data-fixture-role="buttons">
|
||||
<like-button-view-model class="style-text" data-fixture-role="like">
|
||||
<button type="button" aria-label="Channel preview likes" aria-pressed="false">
|
||||
<span id="text" role="text">100</span>
|
||||
</button>
|
||||
</like-button-view-model>
|
||||
<dislike-button-view-model class="style-text" data-ryd-role="dislike">
|
||||
<dislike-button-view-model class="style-text" data-fixture-role="dislike">
|
||||
<button type="button" aria-label="Channel preview dislike" aria-pressed="false">
|
||||
<span id="text" role="text"></span>
|
||||
</button>
|
||||
@@ -210,13 +313,13 @@
|
||||
<div id="menu-container" style="display: none"></div>
|
||||
<ytd-menu-renderer class="ytd-watch-metadata" data-fixture-decoy-controls>
|
||||
<div id="top-level-buttons-computed">
|
||||
<segmented-like-dislike-button-view-model data-ryd-role="buttons">
|
||||
<like-button-view-model class="style-text" data-ryd-role="like">
|
||||
<segmented-like-dislike-button-view-model data-fixture-role="buttons">
|
||||
<like-button-view-model class="style-text" data-fixture-role="like">
|
||||
<button type="button" aria-label="Channel preview likes" aria-pressed="false">
|
||||
<span id="text" role="text">100</span>
|
||||
</button>
|
||||
</like-button-view-model>
|
||||
<dislike-button-view-model class="style-text" data-ryd-role="dislike">
|
||||
<dislike-button-view-model class="style-text" data-fixture-role="dislike">
|
||||
<button type="button" aria-label="Channel preview dislike" aria-pressed="false">
|
||||
<span id="text" role="text"></span>
|
||||
</button>
|
||||
@@ -237,32 +340,57 @@
|
||||
|
||||
function watchMarkup(videoId) {
|
||||
const nextVideoId = videoId === firstVideoId ? secondVideoId : firstVideoId;
|
||||
const likeCount = nativeLikes(videoId);
|
||||
return `
|
||||
<section data-fixture-page-kind="watch" data-fixture-video-id="${videoId}">
|
||||
<div id="menu-container" style="display: none"></div>
|
||||
<div id="player" loading="false"></div>
|
||||
<ytd-watch-flexy video-id="${videoId}"></ytd-watch-flexy>
|
||||
<div id="top-row">
|
||||
<ytd-menu-renderer class="ytd-watch-metadata">
|
||||
<div id="top-level-buttons-computed">
|
||||
<segmented-like-dislike-button-view-model
|
||||
data-ryd-role="buttons"
|
||||
data-fixture-control-video-id="${videoId}"
|
||||
>
|
||||
<like-button-view-model class="style-text" data-ryd-role="like">
|
||||
<button type="button" aria-label="100 likes" aria-pressed="false">
|
||||
<span id="text" role="text">100</span>
|
||||
</button>
|
||||
</like-button-view-model>
|
||||
<dislike-button-view-model class="style-text" data-ryd-role="dislike">
|
||||
<button type="button" aria-label="Dislike this video" aria-pressed="false">
|
||||
<span id="text" role="text"></span>
|
||||
</button>
|
||||
</dislike-button-view-model>
|
||||
</segmented-like-dislike-button-view-model>
|
||||
</div>
|
||||
</ytd-menu-renderer>
|
||||
</div>
|
||||
<ytd-watch-flexy video-id="${videoId}">
|
||||
<div id="menu-container" style="display: none"></div>
|
||||
<div id="player" loading="false"></div>
|
||||
<div id="top-row">
|
||||
<ytd-menu-renderer class="ytd-watch-metadata">
|
||||
<div id="top-level-buttons-computed">
|
||||
<segmented-like-dislike-button-view-model
|
||||
data-fixture-role="buttons"
|
||||
data-fixture-control-video-id="${videoId}"
|
||||
>
|
||||
<yt-smartimation>
|
||||
<div id="content" data-fixture-smartimation-content-shell>
|
||||
<div id="wrapper" data-fixture-smartimation-content>
|
||||
<like-button-view-model class="style-text" data-fixture-role="like">
|
||||
<toggle-button-view-model>
|
||||
<button-view-model>
|
||||
<button type="button" aria-label="${likeCount} likes" aria-pressed="false">
|
||||
<svg data-fixture-watch-icon="like" aria-hidden="true" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M8 21H5V9h3v12Zm2 0V9l4-7 2 1v5h5v5l-3 8h-8Z"></path>
|
||||
</svg>
|
||||
<div class="ytSpecButtonShapeNextButtonTextContent" data-fixture-provided-native-text>
|
||||
<span id="text" role="text">${likeCount}</span>
|
||||
</div>
|
||||
<span data-fixture-touch-feedback aria-hidden="true"></span>
|
||||
</button>
|
||||
</button-view-model>
|
||||
</toggle-button-view-model>
|
||||
</like-button-view-model>
|
||||
<dislike-button-view-model class="style-text" data-fixture-role="dislike">
|
||||
<toggle-button-view-model>
|
||||
<button-view-model>
|
||||
<button type="button" aria-label="Dislike this video" aria-pressed="false">
|
||||
<svg data-fixture-watch-icon="dislike" aria-hidden="true" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M16 3h3v12h-3V3Zm-2 0v12l-4 7-2-1v-5H3v-5l3-8h8Z"></path>
|
||||
</svg>
|
||||
<span data-fixture-touch-feedback aria-hidden="true"></span>
|
||||
</button>
|
||||
</button-view-model>
|
||||
</toggle-button-view-model>
|
||||
</dislike-button-view-model>
|
||||
</div>
|
||||
</div>
|
||||
</yt-smartimation>
|
||||
</segmented-like-dislike-button-view-model>
|
||||
</div>
|
||||
</ytd-menu-renderer>
|
||||
</div>
|
||||
</ytd-watch-flexy>
|
||||
${linkMarkup("watch-to-short", "Open Short", "shorts", nextVideoId, { controlDelay: 200 })}
|
||||
${linkMarkup("watch-related", "Open related video", "watch", nextVideoId)}
|
||||
${linkMarkup("watch-next", "Play next video", "watch", nextVideoId)}
|
||||
@@ -272,38 +400,75 @@
|
||||
}
|
||||
|
||||
function shortRendererMarkup(videoId, active) {
|
||||
const likeCount = nativeLikes(videoId);
|
||||
return `
|
||||
<div class="reel-video-in-sequence-new" data-fixture-sequence-video-id="${videoId}">
|
||||
<div class="reel-video-in-sequence-thumbnail"></div>
|
||||
<ytd-reel-video-renderer video-id="${videoId}" ${active ? "is-active" : "hidden"}>
|
||||
<a href="/shorts/${videoId}" aria-label="Short ${videoId}"></a>
|
||||
<reel-action-bar-view-model data-ryd-role="buttons">
|
||||
<div id="experiment-overlay"><span>Ready</span></div>
|
||||
<a class="ytp-title-link" href="/shorts/${videoId}" aria-label="Short ${videoId}"></a>
|
||||
<reel-action-bar-view-model data-fixture-role="buttons">
|
||||
<like-button-view-model
|
||||
class="ytLikeButtonViewModelHost ytwReelActionBarViewModelHostDesktopActionButton"
|
||||
data-ryd-role="like"
|
||||
data-fixture-role="like"
|
||||
>
|
||||
<label class="ytSpecButtonShapeWithLabelHost">
|
||||
<button class="ytSpecButtonShapeNextHost" type="button" aria-label="100 likes" aria-pressed="false">
|
||||
<button class="ytSpecButtonShapeNextHost" type="button" aria-label="${likeCount} likes" aria-pressed="false">
|
||||
<span class="ytSpecButtonShapeNextIcon" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24"><path d="M12 21"></path></svg>
|
||||
<svg viewBox="0 0 24 24"><path d="M8 21H5V9h3v12Zm2 0V9l4-7 2 1v5h5v5l-3 8h-8Z"></path></svg>
|
||||
</span>
|
||||
</button>
|
||||
<div class="ytSpecButtonShapeWithLabelLabel"><span id="text" role="text">100</span></div>
|
||||
<div class="ytSpecButtonShapeWithLabelLabel"><span id="text" role="text">${likeCount}</span></div>
|
||||
</label>
|
||||
</like-button-view-model>
|
||||
<button-view-model data-fixture-control="comments">
|
||||
<button type="button" aria-label="View comments"><span role="text">12</span></button>
|
||||
<label class="ytSpecButtonShapeWithLabelHost">
|
||||
<button type="button" aria-label="View comments">
|
||||
<span class="ytSpecButtonShapeNextIcon" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24"><path d="M3 4h18v14H8l-5 3Z"></path></svg>
|
||||
</span>
|
||||
</button>
|
||||
<div class="ytSpecButtonShapeWithLabelLabel"><span role="text">12</span></div>
|
||||
</label>
|
||||
</button-view-model>
|
||||
<button-view-model data-fixture-control="share">
|
||||
<button type="button" aria-label="Share">Share</button>
|
||||
<label class="ytSpecButtonShapeWithLabelHost">
|
||||
<button type="button" aria-label="Share">
|
||||
<span class="ytSpecButtonShapeNextIcon" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24"><path d="M14 4l7 7-7 7v-4H3V8h11Z"></path></svg>
|
||||
</span>
|
||||
</button>
|
||||
<div class="ytSpecButtonShapeWithLabelLabel"><span role="text">Share</span></div>
|
||||
</label>
|
||||
</button-view-model>
|
||||
<button-view-model data-fixture-control="remix">
|
||||
<button type="button" aria-label="Remix">Remix</button>
|
||||
<label class="ytSpecButtonShapeWithLabelHost">
|
||||
<button type="button" aria-label="Remix">
|
||||
<span class="ytSpecButtonShapeNextIcon" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24"><path d="M4 7h10l-2-2 2-2 6 6-6 6-2-2 2-2H4Z"></path></svg>
|
||||
</span>
|
||||
</button>
|
||||
<div class="ytSpecButtonShapeWithLabelLabel"><span role="text">Remix</span></div>
|
||||
</label>
|
||||
</button-view-model>
|
||||
<button-view-model data-fixture-control="sound">
|
||||
<label class="ytSpecButtonShapeWithLabelHost">
|
||||
<button type="button" aria-label="Sound">
|
||||
<span class="ytSpecButtonShapeNextIcon" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24"><path d="M4 9v6h4l5 4V5L8 9H4Zm12.5 3a3.5 3.5 0 0 0-2-3.16v6.32a3.5 3.5 0 0 0 2-3.16Z"></path></svg>
|
||||
</span>
|
||||
</button>
|
||||
<div class="ytSpecButtonShapeWithLabelLabel"><span role="text">Sound</span></div>
|
||||
</label>
|
||||
</button-view-model>
|
||||
</reel-action-bar-view-model>
|
||||
</ytd-reel-video-renderer>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function mobileShortRendererMarkup(videoId, active) {
|
||||
const likeCount = nativeLikes(videoId);
|
||||
return `
|
||||
<ytm-reel-video-renderer
|
||||
data-fixture-mobile-short="${videoId}"
|
||||
@@ -313,13 +478,13 @@
|
||||
<a href="/shorts/${videoId}" aria-label="Short ${videoId}"></a>
|
||||
<ytm-reel-player-overlay-renderer>
|
||||
<div id="like-button">
|
||||
<ytm-like-button-renderer data-ryd-role="buttons">
|
||||
<like-button-view-model class="style-text" data-ryd-role="like">
|
||||
<button type="button" aria-label="100 likes" aria-pressed="false">
|
||||
<span id="text" class="button-renderer-text" role="text">100</span>
|
||||
<ytm-like-button-renderer data-fixture-role="buttons">
|
||||
<like-button-view-model class="style-text" data-fixture-role="like">
|
||||
<button type="button" aria-label="${likeCount} likes" aria-pressed="false">
|
||||
<span id="text" class="button-renderer-text" role="text">${likeCount}</span>
|
||||
</button>
|
||||
</like-button-view-model>
|
||||
<dislike-button-view-model class="style-text" data-ryd-role="dislike">
|
||||
<dislike-button-view-model class="style-text" data-fixture-role="dislike">
|
||||
<button type="button" aria-label="Dislike this video" aria-pressed="false">
|
||||
<span id="text" class="button-renderer-text" role="text"></span>
|
||||
</button>
|
||||
@@ -367,6 +532,24 @@
|
||||
|
||||
function render(pageKind, videoId) {
|
||||
page.innerHTML = pageMarkup(pageKind, videoId);
|
||||
fixtureBaseline.renderedWatchNativeDislikeTextCount =
|
||||
pageKind === "watch"
|
||||
? page.querySelectorAll(
|
||||
'[data-fixture-page-kind="watch"] [data-fixture-role="dislike"] .ytSpecButtonShapeNextButtonTextContent',
|
||||
).length
|
||||
: null;
|
||||
fixtureBaseline.renderedDesktopShortsNativeDislikes =
|
||||
pageKind === "shorts" && !isMobile
|
||||
? page.querySelectorAll(
|
||||
"ytd-reel-video-renderer[is-active] > reel-action-bar-view-model > dislike-button-view-model",
|
||||
).length
|
||||
: null;
|
||||
fixtureBaseline.renderedMobileShortsNativeDislikes =
|
||||
pageKind === "shorts" && isMobile
|
||||
? page.querySelectorAll(
|
||||
"ytm-reel-video-renderer[is-active] ytm-like-button-renderer > dislike-button-view-model",
|
||||
).length
|
||||
: null;
|
||||
navigation.innerHTML =
|
||||
pageKind === "channel"
|
||||
? ""
|
||||
@@ -475,6 +658,28 @@
|
||||
dispatchNavigation();
|
||||
}
|
||||
|
||||
function navigateWatchAfterStartWithoutFinish(videoId) {
|
||||
const watchPage = page.querySelector('[data-fixture-page-kind="watch"]');
|
||||
const watch = watchPage?.querySelector("ytd-watch-flexy");
|
||||
if (!watchPage || !watch) return;
|
||||
document.dispatchEvent(new Event("yt-navigate-start", { bubbles: true }));
|
||||
history.pushState({}, "", hrefFor("watch", videoId));
|
||||
watchPage.setAttribute("data-fixture-video-id", videoId);
|
||||
watch.setAttribute("video-id", videoId);
|
||||
page.dataset.fixtureTransitionPending = "watch-start-without-finish";
|
||||
pendingStartedWatchRender = () => {
|
||||
delete page.dataset.fixtureTransitionPending;
|
||||
render("watch", videoId);
|
||||
};
|
||||
}
|
||||
|
||||
function finishWatchAfterStartWithoutFinish() {
|
||||
if (!pendingStartedWatchRender) throw new Error("No start-only Watch navigation is pending");
|
||||
const finish = pendingStartedWatchRender;
|
||||
pendingStartedWatchRender = null;
|
||||
finish();
|
||||
}
|
||||
|
||||
function beginSameNodeWatchNavigation(videoId) {
|
||||
const watch = page.querySelector("ytd-watch-flexy");
|
||||
if (!watch) return;
|
||||
@@ -488,7 +693,7 @@
|
||||
}
|
||||
|
||||
function mutateOutgoingWatchDescendant() {
|
||||
const dislike = page.querySelector('[data-fixture-page-kind="watch"] [data-ryd-role="dislike"]');
|
||||
const dislike = page.querySelector('[data-fixture-page-kind="watch"] [data-fixture-role="dislike"]');
|
||||
if (!dislike) return;
|
||||
const countMarker = document.createElement("span");
|
||||
countMarker.hidden = true;
|
||||
@@ -502,7 +707,7 @@
|
||||
}
|
||||
|
||||
function replaceDelayedWatchControl(role) {
|
||||
const control = page.querySelector(`[data-fixture-page-kind="watch"] [data-ryd-role="${role}"]`);
|
||||
const control = page.querySelector(`[data-fixture-page-kind="watch"] [data-fixture-role="${role}"]`);
|
||||
if (!control) return;
|
||||
const replacement = control.cloneNode(true);
|
||||
replacement.setAttribute("data-fixture-watch-replacement", role);
|
||||
@@ -516,7 +721,7 @@
|
||||
control.replaceWith(replacement);
|
||||
}
|
||||
|
||||
function replaceCurrentWatchActions({ retainOutgoing = false } = {}) {
|
||||
function replaceCurrentWatchActions({ nativeHydrationDelay = 0, retainOutgoing = false } = {}) {
|
||||
const section = page.querySelector('[data-fixture-page-kind="watch"]');
|
||||
const currentActions = section?.querySelector("#top-level-buttons-computed");
|
||||
const videoId = section?.dataset.fixtureVideoId;
|
||||
@@ -526,10 +731,10 @@
|
||||
replacement.setAttribute("data-fixture-watch-actions-replacement", videoId);
|
||||
replacement.querySelectorAll(".ryd-tooltip").forEach((tooltip) => tooltip.remove());
|
||||
|
||||
const controls = replacement.querySelector('[data-ryd-role="buttons"]');
|
||||
const controls = replacement.querySelector('[data-fixture-role="buttons"]');
|
||||
controls?.setAttribute("data-fixture-control-video-id", videoId);
|
||||
for (const role of ["like", "dislike"]) {
|
||||
const control = controls?.querySelector(`[data-ryd-role="${role}"]`);
|
||||
const control = controls?.querySelector(`[data-fixture-role="${role}"]`);
|
||||
control?.classList.remove("style-default-active");
|
||||
control?.classList.add("style-text");
|
||||
const button = control?.querySelector("button");
|
||||
@@ -537,8 +742,24 @@
|
||||
button?.removeAttribute("disabled");
|
||||
button?.setAttribute("aria-disabled", "false");
|
||||
}
|
||||
const dislikeCount = controls?.querySelector('[data-ryd-role="dislike"] #text');
|
||||
if (dislikeCount) dislikeCount.textContent = "";
|
||||
controls
|
||||
?.querySelectorAll(
|
||||
'[data-fixture-role="dislike"] .ytSpecButtonShapeNextButtonTextContent, [data-fixture-role="dislike"] #text',
|
||||
)
|
||||
.forEach((element) => element.remove());
|
||||
|
||||
const delayedNativeButtons = [];
|
||||
if (nativeHydrationDelay > 0) {
|
||||
for (const role of ["like", "dislike"]) {
|
||||
const control = controls?.querySelector(`[data-fixture-role="${role}"]`);
|
||||
const button = control?.querySelector("button");
|
||||
if (control && button) {
|
||||
control.setAttribute("data-fixture-native-hydration-pending", role);
|
||||
delayedNativeButtons.push({ button, control });
|
||||
button.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentActions.replaceWith(replacement);
|
||||
globalThis.__fixtureReplacedWatchActions = currentActions;
|
||||
@@ -549,17 +770,28 @@
|
||||
retained.appendChild(currentActions);
|
||||
document.body.appendChild(retained);
|
||||
}
|
||||
if (delayedNativeButtons.length > 0) {
|
||||
setTimeout(() => {
|
||||
for (const { button, control } of delayedNativeButtons) {
|
||||
if (replacement.isConnected && control.isConnected && !control.querySelector("button")) {
|
||||
control.appendChild(button);
|
||||
control.removeAttribute("data-fixture-native-hydration-pending");
|
||||
}
|
||||
}
|
||||
}, nativeHydrationDelay);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function refreshReusedWatchControl(role, videoId) {
|
||||
const control = page.querySelector(`[data-fixture-page-kind="watch"] [data-ryd-role="${role}"]`);
|
||||
const control = page.querySelector(`[data-fixture-page-kind="watch"] [data-fixture-role="${role}"]`);
|
||||
if (!control) return;
|
||||
setNativeReactionPressed(control, false);
|
||||
control.querySelector("button")?.setAttribute("aria-label", `${role} refreshed for ${videoId}`);
|
||||
}
|
||||
|
||||
function driftWatchControlBeforeNavigation(role, videoId) {
|
||||
const button = page.querySelector(`[data-fixture-page-kind="watch"] [data-ryd-role="${role}"] button`);
|
||||
const button = page.querySelector(`[data-fixture-page-kind="watch"] [data-fixture-role="${role}"] button`);
|
||||
if (!button) return;
|
||||
button.setAttribute("aria-label", `${role} drift while ${videoId}`);
|
||||
button.setAttribute("title", `${role} title drift while ${videoId}`);
|
||||
@@ -571,7 +803,7 @@
|
||||
if (!overlay) return;
|
||||
const replacement = overlay.cloneNode(true);
|
||||
replacement.setAttribute("data-fixture-replacement", "true");
|
||||
const dislike = replacement.querySelector('[data-ryd-role="dislike"]');
|
||||
const dislike = replacement.querySelector('[data-fixture-role="dislike"]');
|
||||
dislike?.classList.remove("style-default-active");
|
||||
dislike?.classList.add("style-text");
|
||||
dislike?.querySelector("button")?.setAttribute("aria-pressed", "false");
|
||||
@@ -624,18 +856,24 @@
|
||||
},
|
||||
finishDelayedNavigation,
|
||||
finishSameNodeWatchNavigation,
|
||||
finishWatchAfterStartWithoutFinish,
|
||||
driftWatchControlBeforeNavigation,
|
||||
navigate,
|
||||
navigateDelayedAnonymousShort,
|
||||
navigateDelayedShort,
|
||||
navigateDelayedWatch,
|
||||
navigateToShortsDescendant,
|
||||
navigateWatchAfterStartWithoutFinish,
|
||||
mutateOutgoingWatchDescendant,
|
||||
nativeReactionSnapshot() {
|
||||
return { ...nativeReactionStats };
|
||||
},
|
||||
recycleShort,
|
||||
replaceActiveMobileOverlay,
|
||||
replaceCurrentWatchActions,
|
||||
replaceDelayedWatchControl,
|
||||
refreshReusedWatchControl,
|
||||
setNativeLikeCount,
|
||||
};
|
||||
|
||||
render("__INITIAL_PAGE_KIND__", "__VIDEO_ID__");
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
.slim-video-action-bar-actions,
|
||||
.segmented-buttons,
|
||||
segmented-like-dislike-button-view-model,
|
||||
yt-smartimation,
|
||||
toggle-button-view-model,
|
||||
button-view-model,
|
||||
like-button-view-model,
|
||||
dislike-button-view-model {
|
||||
display: block;
|
||||
@@ -32,17 +35,33 @@
|
||||
|
||||
ytd-menu-renderer.ytd-watch-metadata > div {
|
||||
display: block;
|
||||
width: min(320px, 100%);
|
||||
min-height: 36px;
|
||||
}
|
||||
|
||||
#top-row {
|
||||
width: min(320px, 100%);
|
||||
width: min(500px, 100%);
|
||||
}
|
||||
|
||||
ytd-menu-renderer.ytd-watch-metadata {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
width: min(500px, 100%);
|
||||
}
|
||||
|
||||
#top-level-buttons-computed {
|
||||
position: relative;
|
||||
width: 192px;
|
||||
}
|
||||
|
||||
segmented-like-dislike-button-view-model {
|
||||
display: block;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
[data-fixture-smartimation-content] {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
width: 192px;
|
||||
}
|
||||
|
||||
.segmented-buttons {
|
||||
@@ -56,8 +75,8 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
[data-ryd-role="like"],
|
||||
[data-ryd-role="dislike"] {
|
||||
[__FIXTURE_ROLE_ATTRIBUTE__="like"],
|
||||
[__FIXTURE_ROLE_ATTRIBUTE__="dislike"] {
|
||||
box-sizing: border-box;
|
||||
flex: 0 0 96px;
|
||||
height: 36px;
|
||||
@@ -66,8 +85,8 @@
|
||||
width: 96px;
|
||||
}
|
||||
|
||||
[data-ryd-role="like"] button,
|
||||
[data-ryd-role="dislike"] button {
|
||||
[__FIXTURE_ROLE_ATTRIBUTE__="like"] button,
|
||||
[__FIXTURE_ROLE_ATTRIBUTE__="dislike"] button {
|
||||
align-items: center;
|
||||
background: rgb(39, 39, 39);
|
||||
border: 0;
|
||||
@@ -88,7 +107,7 @@
|
||||
width: 96px;
|
||||
}
|
||||
|
||||
[data-ryd-role].style-default-active button {
|
||||
[__FIXTURE_ROLE_ATTRIBUTE__].style-default-active button {
|
||||
background: rgb(241, 241, 241);
|
||||
color: rgb(15, 15, 15);
|
||||
}
|
||||
@@ -102,7 +121,8 @@
|
||||
width: 20px;
|
||||
}
|
||||
|
||||
[data-ryd-role] #text {
|
||||
[__FIXTURE_ROLE_ATTRIBUTE__] #text,
|
||||
[__FIXTURE_ROLE_ATTRIBUTE__] .ytSpecButtonShapeNextButtonTextContent {
|
||||
display: block;
|
||||
font:
|
||||
500 14px/20px Arial,
|
||||
@@ -110,6 +130,32 @@
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#flexible-item-buttons {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
width: 172px;
|
||||
}
|
||||
|
||||
#flexible-item-buttons button {
|
||||
background: rgb(39, 39, 39);
|
||||
border: 0;
|
||||
border-radius: 18px;
|
||||
color: rgb(241, 241, 241);
|
||||
height: 36px;
|
||||
min-width: 82px;
|
||||
}
|
||||
|
||||
#fixture-comment-action-surfaces #top-level-buttons-computed {
|
||||
height: 0;
|
||||
overflow: hidden;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
[data-fixture-touch-feedback] {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -117,12 +163,22 @@
|
||||
<div id="menu-container" style="display: none"></div>
|
||||
<div id="fixture-account"></div>
|
||||
<div id="player" loading="false"></div>
|
||||
<ytd-watch-flexy id="fixture-watch" video-id="__VIDEO_ID__"></ytd-watch-flexy>
|
||||
<div id="top-row" data-fixture-shell="desktop">
|
||||
<ytd-menu-renderer class="ytd-watch-metadata">
|
||||
<div id="top-level-buttons-computed"></div>
|
||||
</ytd-menu-renderer>
|
||||
</div>
|
||||
<ytd-watch-flexy id="fixture-watch" video-id="__VIDEO_ID__">
|
||||
<div id="top-row" data-fixture-shell="desktop">
|
||||
<ytd-menu-renderer class="ytd-watch-metadata">
|
||||
<div id="top-level-buttons-computed"></div>
|
||||
<div id="flexible-item-buttons" data-fixture-unrelated-actions>
|
||||
<button-view-model
|
||||
><button type="button"><span role="text">Save</span></button></button-view-model
|
||||
>
|
||||
<button-view-model
|
||||
><button type="button"><span role="text">Download</span></button></button-view-model
|
||||
>
|
||||
</div>
|
||||
</ytd-menu-renderer>
|
||||
</div>
|
||||
</ytd-watch-flexy>
|
||||
<div id="fixture-comment-action-surfaces"></div>
|
||||
<div class="slim-video-action-bar-actions" data-fixture-shell="mobile">
|
||||
<div id="fixture-mobile-buttons-host" class="segmented-buttons"></div>
|
||||
</div>
|
||||
@@ -147,51 +203,67 @@
|
||||
|
||||
function desktopButtonMarkup() {
|
||||
return `
|
||||
<segmented-like-dislike-button-view-model data-ryd-role="buttons">
|
||||
<like-button-view-model class="style-text" data-ryd-role="like">
|
||||
<button type="button" aria-label="100 likes" aria-pressed="false">
|
||||
<svg data-fixture-icon="like" aria-hidden="true" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M8 21H5V9h3v12Zm2 0V9l4-7 2 1v5h5v5l-3 8h-8Z"></path>
|
||||
</svg>
|
||||
<span id="text" role="text">100</span>
|
||||
</button>
|
||||
</like-button-view-model>
|
||||
<dislike-button-view-model class="style-text" data-ryd-role="dislike">
|
||||
<button type="button" aria-label="Dislike this video" aria-pressed="false">
|
||||
<svg data-fixture-icon="dislike" aria-hidden="true" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M16 3h3v12h-3V3Zm-2 0v12l-4 7-2-1v-5H3v-5l3-8h8Z"></path>
|
||||
</svg>
|
||||
<span id="text" role="text"></span>
|
||||
</button>
|
||||
</dislike-button-view-model>
|
||||
<segmented-like-dislike-button-view-model __FIXTURE_ROLE_ATTRIBUTE__="buttons">
|
||||
<yt-smartimation>
|
||||
<div id="content" data-fixture-smartimation-content-shell>
|
||||
<div id="wrapper" data-fixture-smartimation-content>
|
||||
<like-button-view-model class="style-text" __FIXTURE_ROLE_ATTRIBUTE__="like">
|
||||
<toggle-button-view-model>
|
||||
<button-view-model>
|
||||
<button type="button" aria-label="__VIDEO_LIKES__ likes" aria-pressed="false">
|
||||
<svg data-fixture-icon="like" aria-hidden="true" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M8 21H5V9h3v12Zm2 0V9l4-7 2 1v5h5v5l-3 8h-8Z"></path>
|
||||
</svg>
|
||||
<div class="ytSpecButtonShapeNextButtonTextContent"><span id="text" role="text">__VIDEO_LIKES__</span></div>
|
||||
<span data-fixture-touch-feedback aria-hidden="true"></span>
|
||||
</button>
|
||||
</button-view-model>
|
||||
</toggle-button-view-model>
|
||||
</like-button-view-model>
|
||||
<dislike-button-view-model class="style-text" __FIXTURE_ROLE_ATTRIBUTE__="dislike">
|
||||
<toggle-button-view-model>
|
||||
<button-view-model>
|
||||
<button type="button" aria-label="Dislike this video" aria-pressed="false">
|
||||
<svg data-fixture-icon="dislike" aria-hidden="true" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M16 3h3v12h-3V3Zm-2 0v12l-4 7-2-1v-5H3v-5l3-8h8Z"></path>
|
||||
</svg>
|
||||
__DISLIKE_TEXT_MARKUP__
|
||||
<span data-fixture-touch-feedback aria-hidden="true"></span>
|
||||
</button>
|
||||
</button-view-model>
|
||||
</toggle-button-view-model>
|
||||
</dislike-button-view-model>
|
||||
</div>
|
||||
</div>
|
||||
</yt-smartimation>
|
||||
</segmented-like-dislike-button-view-model>
|
||||
`;
|
||||
}
|
||||
|
||||
function mobileButtonMarkup() {
|
||||
return `
|
||||
<like-button-view-model class="style-text" data-ryd-role="like">
|
||||
<button type="button" aria-label="100 likes" aria-pressed="false">
|
||||
<like-button-view-model class="style-text" __FIXTURE_ROLE_ATTRIBUTE__="like">
|
||||
<button type="button" aria-label="__VIDEO_LIKES__ likes" aria-pressed="false">
|
||||
<svg data-fixture-icon="like" aria-hidden="true" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M8 21H5V9h3v12Zm2 0V9l4-7 2 1v5h5v5l-3 8h-8Z"></path>
|
||||
</svg>
|
||||
<span id="text" class="button-renderer-text" role="text">100</span>
|
||||
<div class="ytSpecButtonShapeNextButtonTextContent"><span id="text" class="button-renderer-text" role="text">__VIDEO_LIKES__</span></div>
|
||||
</button>
|
||||
</like-button-view-model>
|
||||
<dislike-button-view-model class="style-text" data-ryd-role="dislike">
|
||||
<dislike-button-view-model class="style-text" __FIXTURE_ROLE_ATTRIBUTE__="dislike">
|
||||
<button type="button" aria-label="Dislike this video" aria-pressed="false">
|
||||
<svg data-fixture-icon="dislike" aria-hidden="true" viewBox="0 0 24 24">
|
||||
<path fill="currentColor" d="M16 3h3v12h-3V3Zm-2 0v12l-4 7-2-1v-5H3v-5l3-8h8Z"></path>
|
||||
</svg>
|
||||
<span id="text" class="button-renderer-text" role="text"></span>
|
||||
__DISLIKE_TEXT_MARKUP__
|
||||
</button>
|
||||
</dislike-button-view-model>
|
||||
`;
|
||||
}
|
||||
|
||||
function applyNativeState(state) {
|
||||
const like = host.querySelector('[data-ryd-role="like"]');
|
||||
const dislike = host.querySelector('[data-ryd-role="dislike"]');
|
||||
const like = host.querySelector('[__FIXTURE_ROLE_ATTRIBUTE__="like"]');
|
||||
const dislike = host.querySelector('[__FIXTURE_ROLE_ATTRIBUTE__="dislike"]');
|
||||
if (!like || !dislike) return;
|
||||
|
||||
like.classList.toggle("style-default-active", state === "liked");
|
||||
@@ -203,6 +275,17 @@
|
||||
host.dataset.nativeState = state;
|
||||
}
|
||||
|
||||
function applyNativeLikeDelta(delta) {
|
||||
const button = host.querySelector('[__FIXTURE_ROLE_ATTRIBUTE__="like"] button');
|
||||
const text = button?.querySelector("#text, [role='text']");
|
||||
if (!button || !text) return;
|
||||
|
||||
const current = Number(text.textContent.replace(/[^\d]/g, "")) || 0;
|
||||
const next = Math.max(0, current + delta);
|
||||
text.textContent = String(next);
|
||||
button.setAttribute("aria-label", `${next} likes`);
|
||||
}
|
||||
|
||||
function insertButtons(state = "neutral") {
|
||||
host.innerHTML = isMobile ? mobileButtonMarkup() : desktopButtonMarkup();
|
||||
applyNativeState(state);
|
||||
@@ -213,6 +296,28 @@
|
||||
host.dataset.nativeState = "neutral";
|
||||
}
|
||||
|
||||
function installCommentActionSurfaces() {
|
||||
const comments = document.getElementById("fixture-comment-action-surfaces");
|
||||
for (let index = 0; index < 20; index += 1) {
|
||||
const duplicate = document.createElement("div");
|
||||
duplicate.id = "top-level-buttons-computed";
|
||||
duplicate.setAttribute("data-fixture-comment-action-surface", String(index));
|
||||
duplicate.innerHTML = `
|
||||
<like-button-view-model data-fixture-comment-like>
|
||||
<button type="button" aria-label="Like comment" aria-pressed="false">
|
||||
<span role="text">1</span>
|
||||
</button>
|
||||
</like-button-view-model>
|
||||
<dislike-button-view-model data-fixture-comment-dislike>
|
||||
<button type="button" aria-label="Dislike comment" aria-pressed="false">
|
||||
<span data-fixture-touch-feedback aria-hidden="true"></span>
|
||||
</button>
|
||||
</dislike-button-view-model>
|
||||
`;
|
||||
comments.appendChild(duplicate);
|
||||
}
|
||||
}
|
||||
|
||||
function navigate(videoId, { state = "neutral", buttons = true } = {}) {
|
||||
history.pushState({}, "", `/watch?v=${videoId}`);
|
||||
watch.setAttribute("video-id", videoId);
|
||||
@@ -225,11 +330,22 @@
|
||||
host.addEventListener(
|
||||
"click",
|
||||
(event) => {
|
||||
const like = event.target.closest('[data-ryd-role="like"]');
|
||||
const dislike = event.target.closest('[data-ryd-role="dislike"]');
|
||||
const like = event.target.closest('[__FIXTURE_ROLE_ATTRIBUTE__="like"]');
|
||||
const dislike = event.target.closest('[__FIXTURE_ROLE_ATTRIBUTE__="dislike"]');
|
||||
const current = host.dataset.nativeState || "neutral";
|
||||
if (like) applyNativeState(current === "liked" ? "neutral" : "liked");
|
||||
if (dislike) applyNativeState(current === "disliked" ? "neutral" : "disliked");
|
||||
const next = like
|
||||
? current === "liked"
|
||||
? "neutral"
|
||||
: "liked"
|
||||
: dislike
|
||||
? current === "disliked"
|
||||
? "neutral"
|
||||
: "disliked"
|
||||
: current;
|
||||
if (next !== current) {
|
||||
applyNativeLikeDelta(Number(next === "liked") - Number(current === "liked"));
|
||||
applyNativeState(next);
|
||||
}
|
||||
},
|
||||
true,
|
||||
);
|
||||
@@ -243,7 +359,11 @@
|
||||
};
|
||||
|
||||
setSignedIn(__SIGNED_IN__);
|
||||
installCommentActionSurfaces();
|
||||
if (__INITIAL_BUTTONS__) insertButtons("__INITIAL_STATE__");
|
||||
window.__youtubeFixture.initialDislikeTextContainers = host.querySelectorAll(
|
||||
'[__FIXTURE_ROLE_ATTRIBUTE__="dislike"] #text, [__FIXTURE_ROLE_ATTRIBUTE__="dislike"] .ytSpecButtonShapeNextButtonTextContent',
|
||||
).length;
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in new issue
Block a user