aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2021-08-26 18:20:33 -0400
committerAjay Ramachandran <[email protected]>2021-08-26 18:20:33 -0400
commit48a49e41360e4543cfbf294c928936082327fa73 (patch)
tree8daf4b2936063fd4984f08caf558f8e7f8fb6356
parent43a9ba0f9e62705c1a42de17a98687828f8ecd77 (diff)
downloadSponsorBlock-48a49e41360e4543cfbf294c928936082327fa73.tar.gz
SponsorBlock-48a49e41360e4543cfbf294c928936082327fa73.zip
Make highlight hover text work better on preview bar
-rw-r--r--src/content.ts2
-rw-r--r--src/js-components/previewBar.ts13
2 files changed, 12 insertions, 3 deletions
diff --git a/src/content.ts b/src/content.ts
index f022169a..d5365aae 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -578,7 +578,7 @@ function setupVideoListeners() {
const currentPoiSegment = sponsorTimes.find((segment) =>
getCategoryActionType(segment.category) === CategoryActionType.POI &&
video.currentTime - segment.segment[0] > 0 &&
- video.currentTime - segment.segment[0] < video.duration * 0.006); // Approximate size on preview bar
+ video.currentTime - segment.segment[0] < previewBar.getMinimumSize(true));
if (currentPoiSegment && !skipNotices.some((notice) => notice.segments.some((s) => s.UUID === currentPoiSegment.UUID))) {
skipToTime({
v: video,
diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts
index c71c3c81..191053b9 100644
--- a/src/js-components/previewBar.ts
+++ b/src/js-components/previewBar.ts
@@ -102,10 +102,12 @@ class PreviewBar {
let segment: PreviewBarSegment | null = null;
let currentSegmentLength = Infinity;
- for (const seg of this.segments) {
+ for (const seg of this.segments) {//
const segmentLength = seg.segment[1] - seg.segment[0];
+ const minSize = this.getMinimumSize(seg.showLarger);
+
const startTime = segmentLength !== 0 ? seg.segment[0] : Math.floor(seg.segment[0]);
- const endTime = segmentLength !== 0 ? seg.segment[1] : Math.ceil(seg.segment[1]);
+ const endTime = segmentLength > minSize ? seg.segment[1] : Math.ceil(seg.segment[0] + minSize);
if (startTime <= timeInSeconds && endTime >= timeInSeconds) {
if (segmentLength < currentSegmentLength) {
currentSegmentLength = segmentLength;
@@ -218,6 +220,13 @@ class PreviewBar {
timeToPercentage(time: number): string {
return Math.min(100, time / this.videoDuration * 100) + '%';
}
+
+ /*
+ * Approximate size on preview bar for smallest element (due to &nbsp)
+ */
+ getMinimumSize(showLarger = false): number {
+ return this.videoDuration * (showLarger ? 0.006 : 0.003);
+ }
}
export default PreviewBar;