mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 17:17:45 +01:00
Don't skip ads, hide controls & bar when ad playing
This commit is contained in:
parent
a72f571bd4
commit
3a0d5221f6
1 changed files with 34 additions and 0 deletions
|
@ -99,6 +99,9 @@ var popupInitialised = false;
|
||||||
|
|
||||||
var submissionNotice: SubmissionNotice = null;
|
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
|
// Contains all of the functions and variables needed by the skip notice
|
||||||
var skipNoticeContentContainer: ContentContainer = () => ({
|
var skipNoticeContentContainer: ContentContainer = () => ({
|
||||||
vote,
|
vote,
|
||||||
|
@ -446,6 +449,7 @@ function createPreviewBar(): void {
|
||||||
* This happens when the resolution changes or at random time to clear memory.
|
* This happens when the resolution changes or at random time to clear memory.
|
||||||
*/
|
*/
|
||||||
function durationChangeListener() {
|
function durationChangeListener() {
|
||||||
|
updateAdFlag();
|
||||||
updatePreviewBar();
|
updatePreviewBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,6 +468,16 @@ function cancelSponsorSchedule(): void {
|
||||||
function startSponsorSchedule(includeIntersectingSegments: boolean = false, currentTime?: number): void {
|
function startSponsorSchedule(includeIntersectingSegments: boolean = false, currentTime?: number): void {
|
||||||
cancelSponsorSchedule();
|
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 (video.paused) return;
|
||||||
|
|
||||||
if (Config.config.disableSkipping || channelWhitelisted || (channelID === null && Config.config.forceChannelCheck)){
|
if (Config.config.disableSkipping || channelWhitelisted || (channelID === null && Config.config.forceChannelCheck)){
|
||||||
|
@ -563,6 +577,8 @@ function sponsorsLookup(id: string) {
|
||||||
|
|
||||||
startSponsorSchedule();
|
startSponsorSchedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateAdFlag();
|
||||||
});
|
});
|
||||||
video.addEventListener('playing', () => {
|
video.addEventListener('playing', () => {
|
||||||
// Make sure it doesn't get double called with the play event
|
// Make sure it doesn't get double called with the play event
|
||||||
|
@ -783,6 +799,11 @@ function updatePreviewBarPositionMobile(parent: Element) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePreviewBar() {
|
function updatePreviewBar() {
|
||||||
|
if(isAdPlaying) {
|
||||||
|
previewBar.set([], [], 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (previewBar === null || video === null) return;
|
if (previewBar === null || video === null) return;
|
||||||
|
|
||||||
let localSponsorTimes = sponsorTimes;
|
let localSponsorTimes = sponsorTimes;
|
||||||
|
@ -1577,3 +1598,16 @@ function sendRequestToCustomServer(type, fullAddress, callback) {
|
||||||
//submit this request
|
//submit this request
|
||||||
xmlhttp.send();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue