Fix player detection when top-layer is being used
This commit is contained in:
parent
8268c7a7af
commit
17dc69f87a
@ -50,7 +50,11 @@ export class UwuiWindow {
|
|||||||
this.background = options.background ?? 'blur';
|
this.background = options.background ?? 'blur';
|
||||||
this.extraStyles = options.extraStyles;
|
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 = this.host.attachShadow({ mode: 'closed' });
|
||||||
this.shadow.innerHTML = this.template(options);
|
this.shadow.innerHTML = this.template(options);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import ExtensionMode from '@src/common/enums/ExtensionMode.enum';
|
import ExtensionMode from '@src/common/enums/ExtensionMode.enum';
|
||||||
|
import { PlayerDetectionMode } from '@src/common/enums/PlayerDetectionMode.enum';
|
||||||
import { ExtensionEnvironment } from '@src/common/interfaces/SettingsInterface';
|
import { ExtensionEnvironment } from '@src/common/interfaces/SettingsInterface';
|
||||||
import { collectionHas, equalish } from '@src/common/utils/comparators';
|
import { collectionHas, equalish } from '@src/common/utils/comparators';
|
||||||
import { RunLevel } from '@src/ext/enum/run-level.enum';
|
import { RunLevel } from '@src/ext/enum/run-level.enum';
|
||||||
@ -597,6 +598,8 @@ class PlayerData {
|
|||||||
* Finds and returns HTML element of the player
|
* Finds and returns HTML element of the player
|
||||||
*/
|
*/
|
||||||
private getPlayer(options?: {verbose?: boolean}): HTMLElement {
|
private getPlayer(options?: {verbose?: boolean}): HTMLElement {
|
||||||
|
const detectionMode = this.siteSettings.data.currentDOMConfig?.elements?.player?.detectionMode;
|
||||||
|
|
||||||
const videoWidth = this.videoElement.offsetWidth;
|
const videoWidth = this.videoElement.offsetWidth;
|
||||||
const videoHeight = this.videoElement.offsetHeight;
|
const videoHeight = this.videoElement.offsetHeight;
|
||||||
let playerCandidate;
|
let playerCandidate;
|
||||||
@ -616,31 +619,16 @@ class PlayerData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if mode is given, we follow the preference
|
if (detectionMode === PlayerDetectionMode.AncestorIndex) {
|
||||||
if (this.siteSettings.data.currentDOMConfig?.elements?.player?.manual && this.siteSettings.data.currentDOMConfig?.elements?.player?.mode) {
|
playerCandidate = elementStack[playerIndex];
|
||||||
if (this.siteSettings.data.currentDOMConfig?.elements?.player?.mode === 'qs') {
|
playerCandidate.heuristics['manualElementByParentIndex'] = true;
|
||||||
playerCandidate = this.getPlayerQs(playerQs, elementStack, videoWidth, videoHeight);
|
} else if (detectionMode === PlayerDetectionMode.QuerySelectors) {
|
||||||
} else {
|
playerCandidate = this.getPlayerQs(playerQs, elementStack, videoWidth, videoHeight);
|
||||||
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 (playerCandidate) {
|
// we fall back to automatic player detection even if detectionMode is
|
||||||
if (options?.verbose) {
|
// not set to auto.
|
||||||
this.getPlayerAuto(elementStack, videoWidth, videoHeight);
|
if (detectionMode === PlayerDetectionMode.Auto || !playerCandidate) {
|
||||||
playerCandidate.heuristics['activePlayer'] = true;
|
|
||||||
}
|
|
||||||
return playerCandidate.element;
|
|
||||||
} else {
|
|
||||||
const playerCandidate = this.getPlayerAuto(elementStack, videoWidth, videoHeight);
|
const playerCandidate = this.getPlayerAuto(elementStack, videoWidth, videoHeight);
|
||||||
if (playerCandidate === null) {
|
if (playerCandidate === null) {
|
||||||
console.warn('[uw::getPlayer] getPlayerAuto returned null — no player detected?');
|
console.warn('[uw::getPlayer] getPlayerAuto returned null — no player detected?');
|
||||||
@ -648,6 +636,12 @@ class PlayerData {
|
|||||||
playerCandidate.heuristics['activePlayer'] = true;
|
playerCandidate.heuristics['activePlayer'] = true;
|
||||||
return playerCandidate.element;
|
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;
|
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) {
|
if (elementData.element === fullscreenElement) {
|
||||||
// reset penalty multiplier if current element is full screen element
|
// reset penalty multiplier if current element is full screen element
|
||||||
// penaltyMultiplier here must be smaller than initial penalty multiplier,
|
// penaltyMultiplier here must be smaller than initial penalty multiplier,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user