diff options
author | rafern <[email protected]> | 2020-05-13 17:29:34 +0100 |
---|---|---|
committer | rafern <[email protected]> | 2020-05-13 17:29:34 +0100 |
commit | 3a0d5221f643422b3f2979c13b6115f6e937867b (patch) | |
tree | 73acfaf49fc0b34cec930844a4d2cad48c8bd452 | |
parent | a72f571bd405277258965323c0adc43f9bfcd3de (diff) | |
download | SponsorBlock-3a0d5221f643422b3f2979c13b6115f6e937867b.tar.gz SponsorBlock-3a0d5221f643422b3f2979c13b6115f6e937867b.zip |
Don't skip ads, hide controls & bar when ad playing
-rw-r--r-- | src/content.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/content.ts b/src/content.ts index 78579023..241d1ac8 100644 --- a/src/content.ts +++ b/src/content.ts @@ -99,6 +99,9 @@ var popupInitialised = false; var submissionNotice: SubmissionNotice = null; +// If there is an advert playing (or about to be played), this is true +var isAdPlaying = false; + // Contains all of the functions and variables needed by the skip notice var skipNoticeContentContainer: ContentContainer = () => ({ vote, @@ -446,6 +449,7 @@ function createPreviewBar(): void { * This happens when the resolution changes or at random time to clear memory. */ function durationChangeListener() { + updateAdFlag(); updatePreviewBar(); } @@ -464,6 +468,16 @@ function cancelSponsorSchedule(): void { function startSponsorSchedule(includeIntersectingSegments: boolean = false, currentTime?: number): void { cancelSponsorSchedule(); + // Don't skip if advert playing and reset last checked time + if (document.getElementsByClassName('ad-showing').length > 0) { + // Reset lastCheckVideoTime + lastCheckVideoTime = -1; + lastCheckTime = 0; + + lastVideoTime = video.currentTime; + return; + } + if (video.paused) return; if (Config.config.disableSkipping || channelWhitelisted || (channelID === null && Config.config.forceChannelCheck)){ @@ -563,6 +577,8 @@ function sponsorsLookup(id: string) { startSponsorSchedule(); } + + updateAdFlag(); }); video.addEventListener('playing', () => { // Make sure it doesn't get double called with the play event @@ -783,6 +799,11 @@ function updatePreviewBarPositionMobile(parent: Element) { } function updatePreviewBar() { + if(isAdPlaying) { + previewBar.set([], [], 0); + return; + } + if (previewBar === null || video === null) return; let localSponsorTimes = sponsorTimes; @@ -1577,3 +1598,16 @@ function sendRequestToCustomServer(type, fullAddress, callback) { //submit this request xmlhttp.send(); } + +/** + * Update the isAdPlaying flag and hide preview bar/controls if ad is playing + */ +function updateAdFlag() { + let wasAdPlaying = isAdPlaying; + isAdPlaying = (document.getElementsByClassName('ad-showing').length > 0); + + if(wasAdPlaying != isAdPlaying) { + updatePreviewBar(); + updateVisibilityOfPlayerControlsButton(); + } +} |