From 089cd5845b08410af38d3bad420d7fd5da895504 Mon Sep 17 00:00:00 2001 From: Svallinn <41585298+Svallinn@users.noreply.github.com> Date: Thu, 20 May 2021 04:00:39 +0100 Subject: [PATCH] SponsorBlock: Prevent multiple notifications at the end of a video Closes: #1299 Previously, the app would notified the user (with a toast) of a sponsor segment skip repeatedly if the segment lasted until the end of a video. This commit fixes that behavior so that it's displayed only once. --- .../ft-video-player/ft-video-player.js | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/renderer/components/ft-video-player/ft-video-player.js b/src/renderer/components/ft-video-player/ft-video-player.js index 96c9cea3..fd9e07e8 100644 --- a/src/renderer/components/ft-video-player/ft-video-player.js +++ b/src/renderer/components/ft-video-player/ft-video-player.js @@ -241,6 +241,10 @@ export default Vue.extend({ }, 200) } + if (this.useSponsorBlock) { + this.initializeSponsorBlock() + } + $(document).on('keydown', this.keyboardShortcutHandler) this.player.on('mousemove', this.hideMouseTimeout) @@ -286,18 +290,22 @@ export default Vue.extend({ } }) } - setTimeout(() => { this.fetchSponsorBlockInfo() }, 100) }, - fetchSponsorBlockInfo() { - if (this.useSponsorBlock) { - this.$store.dispatch('sponsorBlockSkipSegments', { - videoId: this.videoId, - categories: ['sponsor'] - }).then((skipSegments) => { + initializeSponsorBlock() { + this.$store.dispatch('sponsorBlockSkipSegments', { + videoId: this.videoId, + categories: ['sponsor'] + }).then((skipSegments) => { + if (skipSegments.length === 0) { + return + } + + this.player.ready(() => { this.player.on('timeupdate', () => { this.skipSponsorBlocks(skipSegments) }) + skipSegments.forEach(({ category, segment: [startTime, endTime] @@ -309,11 +317,12 @@ export default Vue.extend({ }) }) }) - } + }) }, skipSponsorBlocks(skipSegments) { const currentTime = this.player.currentTime() + const duration = this.player.duration() let newTime = null let skippedCategory = null skipSegments.forEach(({ category, segment: [startTime, endTime] }) => { @@ -322,7 +331,7 @@ export default Vue.extend({ skippedCategory = category } }) - if (newTime !== null) { + if (newTime !== null && Math.abs(duration - currentTime) > 0.500) { if (this.sponsorBlockShowSkippedToast) { this.showSkippedSponsorSegmentInformation(skippedCategory) }