Don't skip ads, hide controls & bar when ad playing

This commit is contained in:
rafern 2020-05-13 17:29:34 +01:00
parent a72f571bd4
commit 3a0d5221f6

View file

@ -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();
}
}