Fix player detection when top-layer is being used

This commit is contained in:
Tamius Han 2026-01-12 01:03:13 +01:00
parent 8268c7a7af
commit 17dc69f87a
2 changed files with 31 additions and 24 deletions

View File

@ -50,7 +50,11 @@ export class UwuiWindow {
this.background = options.background ?? 'blur';
this.extraStyles = options.extraStyles;
document.body.appendChild(this.host);
if (document.fullscreenElement) {
document.fullscreenElement.appendChild(this.host);
} else {
document.body.appendChild(this.host);
}
this.shadow = this.host.attachShadow({ mode: 'closed' });
this.shadow.innerHTML = this.template(options);

View File

@ -1,4 +1,5 @@
import ExtensionMode from '@src/common/enums/ExtensionMode.enum';
import { PlayerDetectionMode } from '@src/common/enums/PlayerDetectionMode.enum';
import { ExtensionEnvironment } from '@src/common/interfaces/SettingsInterface';
import { collectionHas, equalish } from '@src/common/utils/comparators';
import { RunLevel } from '@src/ext/enum/run-level.enum';
@ -597,6 +598,8 @@ class PlayerData {
* Finds and returns HTML element of the player
*/
private getPlayer(options?: {verbose?: boolean}): HTMLElement {
const detectionMode = this.siteSettings.data.currentDOMConfig?.elements?.player?.detectionMode;
const videoWidth = this.videoElement.offsetWidth;
const videoHeight = this.videoElement.offsetHeight;
let playerCandidate;
@ -616,31 +619,16 @@ class PlayerData {
}
}
// if mode is given, we follow the preference
if (this.siteSettings.data.currentDOMConfig?.elements?.player?.manual && this.siteSettings.data.currentDOMConfig?.elements?.player?.mode) {
if (this.siteSettings.data.currentDOMConfig?.elements?.player?.mode === 'qs') {
playerCandidate = this.getPlayerQs(playerQs, elementStack, videoWidth, videoHeight);
} else {
playerCandidate = elementStack[playerIndex];
playerCandidate.heuristics['manualElementByParentIndex'] = true;
}
} else {
// try to figure it out based on what we have, with playerQs taking priority
if (playerQs) {
playerCandidate = this.getPlayerQs(playerQs, elementStack, videoWidth, videoHeight);
} else if (playerIndex) { // btw 0 is not a valid index for player
playerCandidate = elementStack[playerIndex];
playerCandidate.heuristics['manualElementByParentIndex'] = true;
}
if (detectionMode === PlayerDetectionMode.AncestorIndex) {
playerCandidate = elementStack[playerIndex];
playerCandidate.heuristics['manualElementByParentIndex'] = true;
} else if (detectionMode === PlayerDetectionMode.QuerySelectors) {
playerCandidate = this.getPlayerQs(playerQs, elementStack, videoWidth, videoHeight);
}
if (playerCandidate) {
if (options?.verbose) {
this.getPlayerAuto(elementStack, videoWidth, videoHeight);
playerCandidate.heuristics['activePlayer'] = true;
}
return playerCandidate.element;
} else {
// we fall back to automatic player detection even if detectionMode is
// not set to auto.
if (detectionMode === PlayerDetectionMode.Auto || !playerCandidate) {
const playerCandidate = this.getPlayerAuto(elementStack, videoWidth, videoHeight);
if (playerCandidate === null) {
console.warn('[uw::getPlayer] getPlayerAuto returned null — no player detected?');
@ -648,6 +636,12 @@ class PlayerData {
playerCandidate.heuristics['activePlayer'] = true;
return playerCandidate.element;
}
} else {
if (options?.verbose) {
this.getPlayerAuto(elementStack, videoWidth, videoHeight);
playerCandidate.heuristics['activePlayer'] = true;
}
return playerCandidate.element;
}
}
@ -700,6 +694,15 @@ class PlayerData {
continue;
}
// when in full screen, we need to worry about top-layer shenanigans
if (!!fullscreenElement) {
console.log('we are in full screen — checking for top layer shenanigans. Is this element visible from top layer?', fullscreenElement.contains(elementData.element))
if (!fullscreenElement.contains(elementData.element)) {
elementData.heuristics['notVisibleInTopLayer'] = true;
continue;
}
}
if (elementData.element === fullscreenElement) {
// reset penalty multiplier if current element is full screen element
// penaltyMultiplier here must be smaller than initial penalty multiplier,