Skip to content

Commit 7446ea7

Browse files
fix(maximize player): elements under player were overlapped by the player
1 parent e581c27 commit 7446ea7

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

src/features/maximizePlayerButton/index.css

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
.yte-maximized-video {
22
width: 100vw !important;
3-
height: auto !important;
3+
height: var(--yte-video-height) !important;
44
left: 0 !important;
55
top: 0 !important;
6-
max-height: 100vh !important;
76
object-fit: contain !important;
87
background: black !important;
98
}
@@ -22,16 +21,23 @@
2221
width: calc(99vw - 13px) !important;
2322
}
2423

24+
body[yte-maximized] #full-bleed-container {
25+
margin-top: calc(-1 * var(--yte-header-height)) !important;
26+
height: var(--yte-video-height) !important;
27+
}
28+
2529
body[yte-maximized] #columns {
2630
margin-top: var(--yte-columns-offset) !important;
2731
transition: margin-top 0.1s ease;
2832
}
33+
2934
body[yte-maximized] #masthead-container {
3035
transform: translateY(-100%);
3136
transition: transform 0.3s ease;
3237
position: fixed;
3338
z-index: 3000;
3439
}
40+
3541
body[yte-maximized] #masthead-container.yte-header-visible {
3642
transform: translateY(0);
37-
}
43+
}

src/features/maximizePlayerButton/utils.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ const headerMouseMoveHandler = (e: MouseEvent) => {
3232
}
3333
}
3434
if (!header) return;
35+
const navigateStartHandler = () => {
36+
showHeader();
37+
if (headerHoverTimeout) clearTimeout(headerHoverTimeout);
38+
document.removeEventListener("mousemove", headerMouseMoveHandler);
39+
document.removeEventListener("yt-navigate-start", navigateStartHandler);
40+
minimizePlayer();
41+
};
42+
document.addEventListener("yt-navigate-start", navigateStartHandler);
3543
const { height: headerHeight } = header.getBoundingClientRect();
3644
if (e.clientY <= headerHeight) {
3745
if (!headerHoverTimeout) {
@@ -49,13 +57,17 @@ const headerMouseMoveHandler = (e: MouseEvent) => {
4957
}
5058
};
5159
const handleResize = () => {
52-
document.body.style.setProperty("--yte-video-height", `${window.innerHeight}px`);
60+
const header = document.querySelector("#masthead-container");
61+
if (!header) return;
62+
const { height: headerHeight } = header.getBoundingClientRect();
63+
document.body.style.setProperty("--yte-video-height", `${window.innerHeight + headerHeight}px`);
64+
setTimeout(() => {
65+
updateColumnsOffset();
66+
}, 100);
5367
};
5468
export function maximizePlayer() {
5569
const videoPlayer = document.querySelector<HTMLVideoElement>("video.html5-main-video");
5670
if (!videoPlayer) return;
57-
document.body.style.setProperty("--yte-video-height", `${window.innerHeight}px`);
58-
document.body.addEventListener("resize", handleResize);
5971
const chromeBottom = document.querySelector<HTMLDivElement>("div.ytp-chrome-bottom");
6072
if (!chromeBottom) return;
6173
const leftControls = chromeBottom.querySelector<HTMLDivElement>("div.ytp-left-controls");
@@ -70,13 +82,17 @@ export function maximizePlayer() {
7082
document.querySelector<HTMLButtonElement>(`button.ytp-size-button svg path[d='${theaterModeButtonPathD[layoutType]}']`) !== null;
7183
const header = document.querySelector("#masthead-container");
7284
if (!header) return;
85+
if (!inTheaterMode) clickAndRestore(sizeElement);
86+
adjustPlayer("add");
7387
const { height: headerHeight } = header.getBoundingClientRect();
7488
document.body.style.setProperty("--yte-header-height", `${headerHeight}px`);
7589
document.body.setAttribute("yte-size-button-state", inTheaterMode ? "theater" : "default");
76-
if (!inTheaterMode && sizeElement) clickAndRestore(sizeElement);
77-
adjustPlayer("add");
90+
document.body.style.setProperty("--yte-video-height", `${window.innerHeight + headerHeight}px`);
91+
document.body.addEventListener("resize", handleResize, { passive: true });
7892
document.addEventListener("mousemove", headerMouseMoveHandler);
79-
updateColumnsOffset();
93+
setTimeout(() => {
94+
updateColumnsOffset();
95+
}, 100);
8096
if (!listenersInitialized) {
8197
listenersInitialized = true;
8298
[pipElement, sizeElement, miniPlayerElement].forEach((element) => {
@@ -87,19 +103,14 @@ export function maximizePlayer() {
87103
async () => {
88104
if (isProgrammaticClick) return;
89105
minimizePlayer();
90-
const maximizePlayerButton = getFeatureButton("maximizePlayerButton");
91-
if (!maximizePlayerButton) return;
92-
maximizePlayerButton.ariaChecked = "false";
93106
const button = getFeatureButton("maximizePlayerButton");
107+
if (!button || !(button instanceof HTMLButtonElement)) return;
108+
button.ariaChecked = "false";
94109
const icon = getFeatureIcon("maximizePlayerButton", "player_controls_left");
95-
if (button && button instanceof HTMLButtonElement) {
96-
if (typeof icon === "object" && "off" in icon && "on" in icon)
97-
updateFeatureButtonIcon(button, await modifyIconForLightTheme(icon.off, true));
98-
updateFeatureButtonTitle(
99-
"maximizePlayerButton",
100-
window.i18nextInstance.t("pages.content.features.maximizePlayerButton.button.toggle.off")
101-
);
110+
if (icon && typeof icon === "object" && "off" in icon) {
111+
updateFeatureButtonIcon(button, await modifyIconForLightTheme(icon.off, true));
102112
}
113+
updateFeatureButtonTitle("maximizePlayerButton", window.i18nextInstance.t("pages.content.features.maximizePlayerButton.button.toggle.off"));
103114
},
104115
"maximizePlayerButton"
105116
);
@@ -114,7 +125,9 @@ export function minimizePlayer() {
114125
document.body.removeAttribute("yte-size-button-state");
115126
adjustPlayer("remove");
116127
document.body.removeEventListener("resize", handleResize);
117-
document.body.style.setProperty("--yte-columns-offset", "0px");
128+
document.body.style.removeProperty("--yte-columns-offset");
129+
document.body.style.removeProperty("--yte-header-height");
130+
document.body.style.removeProperty("--yte-video-height");
118131
}
119132

120133
function adjustPlayer(action: ModifyElementAction) {

0 commit comments

Comments
 (0)