diff options
author | Ajay Ramachandran <[email protected]> | 2020-12-22 01:10:57 -0500 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2020-12-22 01:10:57 -0500 |
commit | 979e7e7629176d860bbdfe74a108af3c70e96b0f (patch) | |
tree | ed17c8d9e9b9411433627fec4d960a8515bfe5bd | |
parent | cba0fc0a87eb48ad0541d68cd6142794505653ed (diff) | |
download | SponsorBlock-979e7e7629176d860bbdfe74a108af3c70e96b0f.tar.gz SponsorBlock-979e7e7629176d860bbdfe74a108af3c70e96b0f.zip |
Fix mobile support
-rw-r--r-- | src/content.ts | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/content.ts b/src/content.ts index 1e3ba42c..91295952 100644 --- a/src/content.ts +++ b/src/content.ts @@ -293,12 +293,18 @@ async function videoIDChange(id) { if (onMobileYouTube) { // Mobile YouTube workaround const observer = new MutationObserver(handleMobileControlsMutations); - - observer.observe(document.getElementById("player-control-container"), { - attributes: true, - childList: true, - subtree: true - }); + let controlsContainer = null; + + utils.wait(() => { + controlsContainer = document.getElementById("player-control-container") + return controlsContainer !== null + }).then(() => { + observer.observe(document.getElementById("player-control-container"), { + attributes: true, + childList: true, + subtree: true + }); + }).catch(); } else { utils.wait(getControls).then(createPreviewBar); } @@ -354,18 +360,6 @@ async function videoIDChange(id) { function handleMobileControlsMutations(): void { const mobileYouTubeSelector = ".progress-bar-background"; - updateVisibilityOfPlayerControlsButton().then((createdButtons) => { - if (createdButtons) { - if (sponsorTimesSubmitting != null && sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment.length >= 2) { - changeStartSponsorButton(true, true); - } else if (sponsorTimesSubmitting != null && sponsorTimesSubmitting.length > 0 && sponsorTimesSubmitting[sponsorTimesSubmitting.length - 1].segment.length < 2) { - changeStartSponsorButton(false, true); - } else { - changeStartSponsorButton(true, false); - } - } - }); - if (previewBar !== null) { if (document.body.contains(previewBar.container)) { updatePreviewBarPositionMobile(document.getElementsByClassName(mobileYouTubeSelector)[0] as HTMLElement); @@ -1133,6 +1127,7 @@ async function updateVisibilityOfPlayerControlsButton(): Promise<boolean> { if (!sponsorVideoID) return false; const createdButtons = await createButtons(); + if (!createdButtons) return; if (Config.config.hideVideoPlayerControls || onInvidious) { document.getElementById("startSponsorButton").style.display = "none"; @@ -1226,7 +1221,7 @@ function updateSponsorTimesSubmitting(getFromConfig = true) { } async function changeStartSponsorButton(showStartSponsor: boolean, uploadButtonVisible: boolean): Promise<boolean> { - if(!sponsorVideoID) return false; + if(!sponsorVideoID || onMobileYouTube) return false; //if it isn't visible, there is no data const shouldHide = (uploadButtonVisible && !(Config.config.hideDeleteButtonPlayerControls || onInvidious)) ? "unset" : "none" |