aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/js-components/previewBar.ts
diff options
context:
space:
mode:
authorAjay <[email protected]>2022-12-11 14:10:09 -0500
committerAjay <[email protected]>2022-12-11 14:10:09 -0500
commitcf0e91c4ff1eb513bfca6743fc66a316b17fde6b (patch)
tree5d9ea56de46a710d5e6084cf3851ffaeba1512e3 /src/js-components/previewBar.ts
parent41a25720d0db6cfd304a89f74d5fb9809063475c (diff)
downloadSponsorBlock-cf0e91c4ff1eb513bfca6743fc66a316b17fde6b.tar.gz
SponsorBlock-cf0e91c4ff1eb513bfca6743fc66a316b17fde6b.zip
Use fast time to decimal for non display calculations
Diffstat (limited to 'src/js-components/previewBar.ts')
-rw-r--r--src/js-components/previewBar.ts12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts
index f13a93cf..6e91fc0e 100644
--- a/src/js-components/previewBar.ts
+++ b/src/js-components/previewBar.ts
@@ -531,7 +531,7 @@ class PreviewBar {
const nextSegment = segments[index + 1];
const nextTime = nextSegment ? nextSegment.segment[0] : this.videoDuration;
const lastTime = result[result.length - 1]?.segment[1] || segment.segment[1];
- if (this.intervalToDecimal(lastTime, nextTime) > MIN_CHAPTER_SIZE) {
+ if (this.fastIntervalToDecimal(lastTime, nextTime) > MIN_CHAPTER_SIZE) {
result.push({
segment: [lastTime, nextTime],
originalDuration: 0,
@@ -866,7 +866,7 @@ class PreviewBar {
}
private chapterGroupFilter(segment: SegmentContainer): boolean {
- return segment.segment.length === 2 && this.intervalToDecimal(segment.segment[0], segment.segment[1]) > MIN_CHAPTER_SIZE;
+ return segment.segment.length === 2 && this.fastIntervalToDecimal(segment.segment[0], segment.segment[1]) > MIN_CHAPTER_SIZE;
}
intervalToPercentage(startTime: number, endTime: number) {
@@ -877,6 +877,10 @@ class PreviewBar {
return (this.timeToDecimal(endTime) - this.timeToDecimal(startTime));
}
+ fastIntervalToDecimal(startTime: number, endTime: number) {
+ return (this.fastTimeToDecimal(endTime) - this.fastTimeToDecimal(startTime));
+ }
+
timeToPercentage(time: number): string {
return `${this.timeToDecimal(time) * 100}%`
}
@@ -912,6 +916,10 @@ class PreviewBar {
}
}
+ return this.fastTimeToDecimal(time);
+ }
+
+ fastTimeToDecimal(time: number): number {
return Math.min(1, time / this.videoDuration);
}