[skip ci] tweak sponsorblock notification timing

This commit is contained in:
Brahim Hadriche committed 2025-06-01 16:43:51 -04:00
1 parent c2b6b75f94
commit 7ab98024c1
1 file changed
+8 -9
@@ -99,7 +99,7 @@ namespace SponsorBlock
function UpdateSponsorBlockChapter(time as double) as void
segments = m.skipSegments
segment = FindSegmentByTime(segments, time, 0)
segment = FindSegmentByTime(segments, time)
if segment = invalid
m.top.chapter = ""
return
@@ -107,7 +107,7 @@ namespace SponsorBlock
m.top.chapter = segment.title
end function
function FindSegmentByTime(segments as object, time as dynamic, endOffset as integer) as dynamic
function FindSegmentByTime(segments as object, time as dynamic) as dynamic
' Binary search for the segment that contains the time.
' This search sometimes fails if the segments overlap.
' For most cases, this is acceptable, since it is not common for segments to overlap.
@@ -118,7 +118,7 @@ namespace SponsorBlock
segment = segments[middle]
if time < segment.start
high = middle - 1
else if time > (segment.end + endOffset)
else if time > segment.end
low = middle + 1
else
return segment
@@ -131,18 +131,17 @@ namespace SponsorBlock
segments = m.skipSegments
position = m.top.position
' We add a small offset to the end position of the segment.
' This is so that when we skip a segment, we don't get
' another notification to skip it.
' Seeking accuracy is not perfect, so we need to account for that.
segment = FindSegmentByTime(segments, position, -1)
segment = FindSegmentByTime(segments, position)
if segment = invalid
return
end if
action = segment.option
if segment.showNotification
' If we're close to the end of the segment, we don't want to show
' a notification, since it is possible this is where we skipped to.
' Seeking is not super accurate.
if segment.showNotification and Abs(segment.end - position) >= 1
SponsorBlock.ShowNotifcation(m.notifications, segment, action)
if action = SegmentAction.ManualSkip