Cleanup & Prevent repeat of skip message. (#227)

* Cleanup & Prevent repeat of skip message.

* skip sponsorblock segments if not indexed

* disable onVideoProgress sb check if not indexed

Co-authored-by: simon <simobilleter@gmail.com>
This commit is contained in:
Nathan DeTar 2022-04-15 18:53:15 -07:00 committed by GitHub
parent 51ceffd58f
commit 1cf82bdbbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -333,7 +333,7 @@ function createPlayer(button) {
var videoData = getVideoData(videoId); var videoData = getVideoData(videoId);
var sponsorBlockElements = ''; var sponsorBlockElements = '';
if (videoData.data.sponsorblock.is_enabled) { if (videoData.data.sponsorblock && videoData.data.sponsorblock.is_enabled) {
sponsorBlock = videoData.data.sponsorblock; sponsorBlock = videoData.data.sponsorblock;
if (sponsorBlock.segments.length == 0) { if (sponsorBlock.segments.length == 0) {
sponsorBlockElements = ` sponsorBlockElements = `
@ -505,20 +505,22 @@ function getVideoPlayerWatchStatus() {
return watched; return watched;
} }
// Runs on video playback, marks video as watched if video gets to 90% or higher, sends position to api // Runs on video playback, marks video as watched if video gets to 90% or higher, sends position to api, SB skipping
function onVideoProgress() { function onVideoProgress() {
var videoId = getVideoPlayerVideoId(); var videoId = getVideoPlayerVideoId();
var currentTime = getVideoPlayerCurrentTime(); var currentTime = getVideoPlayerCurrentTime();
var duration = getVideoPlayerDuration(); var duration = getVideoPlayerDuration();
var videoElement = getVideoPlayer(); var videoElement = getVideoPlayer();
// var sponsorBlockElement = document.getElementById("sponsorblock");
var notificationsElement = document.getElementById("notifications"); var notificationsElement = document.getElementById("notifications");
if (sponsorBlock.segments.length > 0) { if (sponsorBlock && sponsorBlock.segments) {
for(let i in sponsorBlock.segments) { for(let i in sponsorBlock.segments) {
if(sponsorBlock.segments[i].segment[0] <= currentTime + 0.3 && sponsorBlock.segments[i].segment[0] >= currentTime) { if(currentTime >= sponsorBlock.segments[i].segment[0] && currentTime <= sponsorBlock.segments[i].segment[0] + 0.3) {
videoElement.currentTime = sponsorBlock.segments[i].segment[1]; videoElement.currentTime = sponsorBlock.segments[i].segment[1];
var notificationElement = document.getElementById("notification-" + sponsorBlock.segments[i].UUID);
if (!notificationElement) {
notificationsElement.innerHTML += `<h3 id="notification-${sponsorBlock.segments[i].UUID}">Skipped sponsor segment from ${formatTime(sponsorBlock.segments[i].segment[0])} to ${formatTime(sponsorBlock.segments[i].segment[1])}.</h3>`; notificationsElement.innerHTML += `<h3 id="notification-${sponsorBlock.segments[i].UUID}">Skipped sponsor segment from ${formatTime(sponsorBlock.segments[i].segment[0])} to ${formatTime(sponsorBlock.segments[i].segment[1])}.</h3>`;
} }
}
if(currentTime > sponsorBlock.segments[i].segment[1] + 10) { if(currentTime > sponsorBlock.segments[i].segment[1] + 10) {
var notificationsElementUUID = document.getElementById("notification-" + sponsorBlock.segments[i].UUID); var notificationsElementUUID = document.getElementById("notification-" + sponsorBlock.segments[i].UUID);
if(notificationsElementUUID) { if(notificationsElementUUID) {