diff options
author | Ajay Ramachandran <[email protected]> | 2019-08-13 13:02:35 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2019-08-13 13:02:35 -0400 |
commit | 4a3d36b9520adf34f6b6ac6ba063948b774c5a0e (patch) | |
tree | c2d0103741f9e5455b1655c11cf6d2048ce200eb | |
parent | f9bd82db353313d1be2ef21efc0f685adcb78145 (diff) | |
download | SponsorBlock-4a3d36b9520adf34f6b6ac6ba063948b774c5a0e.tar.gz SponsorBlock-4a3d36b9520adf34f6b6ac6ba063948b774c5a0e.zip |
Fixed preview bar.
Made it reset when no sponsors are found.
Made it wait until the video metadata is loaded if necessary.
-rw-r--r-- | content.js | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -16,6 +16,8 @@ var youtubeVideoStartTime = null; //the video var v; +var listenerAdded; + //the channel this video is about var channelURL; @@ -241,6 +243,9 @@ function videoIDChange(id) { sponsorVideoID = id; sponsorLookupRetries = 0; + //empty the preview bar + previewBar.set([], [], 0); + //see if there is a video start time youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL); @@ -320,7 +325,14 @@ function sponsorsLookup(id) { //update the preview bar //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(); @@ -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() { //get channel id let channelContainers = document.querySelectorAll("#owner-name"); |