aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2020-05-15 21:25:30 -0400
committerGitHub <[email protected]>2020-05-15 21:25:30 -0400
commit856125f7fd3ecc6203319959e02748bd9cb29bbd (patch)
tree1c2d77f1e962be883171e994a14de6e850154450
parent3640463112e7940aeb82dc426e4addbcf219d995 (diff)
parent7b0488d068c49b8677e1187ae5193c111c354347 (diff)
downloadSponsorBlock-856125f7fd3ecc6203319959e02748bd9cb29bbd.tar.gz
SponsorBlock-856125f7fd3ecc6203319959e02748bd9cb29bbd.zip
Merge pull request #350 from rafern/master
Don't skip ads, hide controls & sponsor times preview bar when ads are playing
-rw-r--r--src/content.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/content.ts b/src/content.ts
index 6cb7a7ad..32e18a04 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 (isAdPlaying) {
+ // Reset lastCheckVideoTime
+ lastCheckVideoTime = -1;
+ lastCheckTime = 0;
+
+ lastVideoTime = video.currentTime;
+ return;
+ }
+
if (video.paused) return;
if (Config.config.disableSkipping || channelWhitelisted || (channelID === null && Config.config.forceChannelCheck)){
@@ -561,6 +575,8 @@ function sponsorsLookup(id: string) {
startSponsorSchedule();
}
+
+ updateAdFlag();
});
video.addEventListener('playing', () => {
// Make sure it doesn't get double called with the play event
@@ -781,6 +797,11 @@ function updatePreviewBarPositionMobile(parent: Element) {
}
function updatePreviewBar() {
+ if(isAdPlaying) {
+ previewBar.set([], [], 0);
+ return;
+ }
+
if (previewBar === null || video === null) return;
let localSponsorTimes = sponsorTimes;
@@ -1575,3 +1596,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();
+ }
+}