diff options
author | Ajay Ramachandran <[email protected]> | 2023-03-31 13:07:12 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2023-03-31 13:07:12 -0400 |
commit | e1521e983755e6b2bcb79460ae55b80644cb81d9 (patch) | |
tree | e4cc881582bb5638fda9f454e83fdf2e2c79f092 | |
parent | 7b5303b1d8d028686bec65ce16f6d484730f8d8f (diff) | |
parent | 1ef6c1977facd3085942ab941b545d807da3f4bd (diff) | |
download | SponsorBlock-e1521e983755e6b2bcb79460ae55b80644cb81d9.tar.gz SponsorBlock-e1521e983755e6b2bcb79460ae55b80644cb81d9.zip |
Merge pull request #1710 from mini-bomba/controls-skip-inline-players
Don't attach controls to inline preview players
-rw-r--r-- | src/utils/pageUtils.ts | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/utils/pageUtils.ts b/src/utils/pageUtils.ts index 5462fde4..38bf4748 100644 --- a/src/utils/pageUtils.ts +++ b/src/utils/pageUtils.ts @@ -14,9 +14,9 @@ export function getControls(): HTMLElement { ]; for (const controlsSelector of controlsSelectors) { - const controls = document.querySelectorAll(controlsSelector); + const controls = Array.from(document.querySelectorAll(controlsSelector)).filter(el => !isInPreviewPlayer(el)); - if (controls && controls.length > 0) { + if (controls.length > 0) { return <HTMLElement> controls[controls.length - 1]; } } @@ -24,6 +24,10 @@ export function getControls(): HTMLElement { return null; } +export function isInPreviewPlayer(element: Element): boolean { + return !!element.closest("#inline-preview-player"); +} + export function isVisible(element: HTMLElement): boolean { return element && element.offsetWidth > 0 && element.offsetHeight > 0; } @@ -65,12 +69,12 @@ export function getExistingChapters(currentVideoID: VideoID, duration: number): if (timeElement && description?.innerText?.length > 0 && link.getAttribute("href")?.includes(currentVideoID)) { const time = getFormattedTimeToSeconds(timeElement.innerText.replace(".", ":")); if (time === null) return []; - + if (lastSegment) { lastSegment.segment[1] = time; chapters.push(lastSegment); } - + lastSegment = { segment: [time, null], category: "chapter" as Category, @@ -112,4 +116,4 @@ export function getLocalizedMessage(text: string): string | false { } else { return false; } -}
\ No newline at end of file +} |