mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-11 14:07:13 +03:00
Makes sure the playing and play listener both don't get called at the same time.
This led to double notices.
This commit is contained in:
@@ -45,7 +45,12 @@ var lastPreviewBarUpdate;
|
|||||||
var durationListenerSetUp = false;
|
var durationListenerSetUp = false;
|
||||||
|
|
||||||
// Is the video currently being switched
|
// Is the video currently being switched
|
||||||
var switchingVideos = false;
|
var switchingVideos = null;
|
||||||
|
|
||||||
|
// Used by the play and playing listeners to make sure two aren't
|
||||||
|
// called at the same time
|
||||||
|
var lastCheckTime = 0;
|
||||||
|
var lastCheckVideoTime = -1;
|
||||||
|
|
||||||
//the channel this video is about
|
//the channel this video is about
|
||||||
var channelURL;
|
var channelURL;
|
||||||
@@ -238,6 +243,9 @@ document.onkeydown = function(e: KeyboardEvent){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resetValues() {
|
function resetValues() {
|
||||||
|
lastCheckTime = 0;
|
||||||
|
lastCheckVideoTime = -1;
|
||||||
|
|
||||||
//reset sponsor times
|
//reset sponsor times
|
||||||
sponsorTimes = null;
|
sponsorTimes = null;
|
||||||
UUIDs = [];
|
UUIDs = [];
|
||||||
@@ -250,6 +258,8 @@ function resetValues() {
|
|||||||
|
|
||||||
//reset sponsor data found check
|
//reset sponsor data found check
|
||||||
sponsorDataFound = false;
|
sponsorDataFound = false;
|
||||||
|
|
||||||
|
if (switchingVideos !== null || true) switchingVideos = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function videoIDChange(id) {
|
async function videoIDChange(id) {
|
||||||
@@ -264,8 +274,6 @@ async function videoIDChange(id) {
|
|||||||
//id is not valid
|
//id is not valid
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
|
|
||||||
switchingVideos = true;
|
|
||||||
|
|
||||||
// Wait for options to be ready
|
// Wait for options to be ready
|
||||||
await utils.wait(() => Config.config !== null, 5000, 1);
|
await utils.wait(() => Config.config !== null, 5000, 1);
|
||||||
|
|
||||||
@@ -501,9 +509,24 @@ function sponsorsLookup(id: string, channelIDPromise?) {
|
|||||||
|
|
||||||
video.addEventListener('play', () => {
|
video.addEventListener('play', () => {
|
||||||
switchingVideos = false;
|
switchingVideos = false;
|
||||||
startSponsorSchedule();
|
|
||||||
|
// Make sure it doesn't get double called with the playing event
|
||||||
|
if (lastCheckVideoTime !== video.currentTime && Date.now() - lastCheckTime > 2000) {
|
||||||
|
lastCheckTime = Date.now();
|
||||||
|
lastCheckVideoTime = video.currentTime;
|
||||||
|
|
||||||
|
startSponsorSchedule();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
video.addEventListener('playing', () => {
|
||||||
|
// Make sure it doesn't get double called with the play event
|
||||||
|
if (lastCheckVideoTime !== video.currentTime && Date.now() - lastCheckTime > 2000) {
|
||||||
|
lastCheckTime = Date.now();
|
||||||
|
lastCheckVideoTime = video.currentTime;
|
||||||
|
|
||||||
|
startSponsorSchedule();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
video.addEventListener('playing', () => startSponsorSchedule());
|
|
||||||
video.addEventListener('seeked', () => {
|
video.addEventListener('seeked', () => {
|
||||||
if (!video.paused) startSponsorSchedule();
|
if (!video.paused) startSponsorSchedule();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user