mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 13:37:04 +03:00
Fixed preview bar.
Made it reset when no sponsors are found. Made it wait until the video metadata is loaded if necessary.
This commit is contained in:
21
content.js
21
content.js
@@ -16,6 +16,8 @@ var youtubeVideoStartTime = null;
|
|||||||
//the video
|
//the video
|
||||||
var v;
|
var v;
|
||||||
|
|
||||||
|
var listenerAdded;
|
||||||
|
|
||||||
//the channel this video is about
|
//the channel this video is about
|
||||||
var channelURL;
|
var channelURL;
|
||||||
|
|
||||||
@@ -241,6 +243,9 @@ function videoIDChange(id) {
|
|||||||
sponsorVideoID = id;
|
sponsorVideoID = id;
|
||||||
sponsorLookupRetries = 0;
|
sponsorLookupRetries = 0;
|
||||||
|
|
||||||
|
//empty the preview bar
|
||||||
|
previewBar.set([], [], 0);
|
||||||
|
|
||||||
//see if there is a video start time
|
//see if there is a video start time
|
||||||
youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
|
youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
|
||||||
|
|
||||||
@@ -320,7 +325,14 @@ function sponsorsLookup(id) {
|
|||||||
|
|
||||||
//update the preview bar
|
//update the preview bar
|
||||||
//leave the type blank for now until categories are added
|
//leave the type blank for now until categories are added
|
||||||
previewBar.set(sponsorTimes, [], v.duration);
|
console.log(v.duration)
|
||||||
|
if (isNaN(v.duration)) {
|
||||||
|
//wait until it is loaded
|
||||||
|
v.addEventListener('durationchange', updatePreviewBar);
|
||||||
|
} else {
|
||||||
|
//set it now
|
||||||
|
updatePreviewBar();
|
||||||
|
}
|
||||||
|
|
||||||
getChannelID();
|
getChannelID();
|
||||||
|
|
||||||
@@ -356,6 +368,13 @@ function sponsorsLookup(id) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updatePreviewBar() {
|
||||||
|
previewBar.set(sponsorTimes, [], v.duration);
|
||||||
|
|
||||||
|
//the listener is only needed once
|
||||||
|
v.removeEventListener('durationchange', updatePreviewBar);
|
||||||
|
}
|
||||||
|
|
||||||
function getChannelID() {
|
function getChannelID() {
|
||||||
//get channel id
|
//get channel id
|
||||||
let channelContainers = document.querySelectorAll("#owner-name");
|
let channelContainers = document.querySelectorAll("#owner-name");
|
||||||
|
|||||||
Reference in New Issue
Block a user