aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/js-components/previewBar.ts
diff options
context:
space:
mode:
authorAjay <[email protected]>2024-12-08 14:48:32 -0500
committerAjay <[email protected]>2024-12-08 14:48:32 -0500
commit6bfc66740e50f2597dcef25365ebf68c255e5e43 (patch)
treedd5706fa0e321277520d8051525cbe966bad19f4 /src/js-components/previewBar.ts
parent7e824df73dfb7465d3fd63108d98be5bd625aa74 (diff)
downloadSponsorBlock-6bfc66740e50f2597dcef25365ebf68c255e5e43.tar.gz
SponsorBlock-6bfc66740e50f2597dcef25365ebf68c255e5e43.zip
Hide video uploader chapters if there is a sponsorblock chapter to replace it at almost the same time
Diffstat (limited to 'src/js-components/previewBar.ts')
-rw-r--r--src/js-components/previewBar.ts19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/js-components/previewBar.ts b/src/js-components/previewBar.ts
index 001de564..5dc5fefe 100644
--- a/src/js-components/previewBar.ts
+++ b/src/js-components/previewBar.ts
@@ -233,6 +233,17 @@ class PreviewBar {
this.segments = segments ?? [];
this.videoDuration = videoDuration ?? 0;
+ // Remove unnecessary original chapters if submitted replacements exist
+ for (const chapter of this.segments.filter((s) => s.actionType === ActionType.Chapter && s.source === SponsorSourceType.Server)) {
+ const duplicate = this.segments.find((s) => s.actionType === ActionType.Chapter
+ && s.source === SponsorSourceType.YouTube
+ && Math.abs(s.segment[0] - chapter.segment[0]) < 3 && Math.abs(s.segment[1] - chapter.segment[1]) < 3);
+
+ if (duplicate) {
+ const index = this.segments.indexOf(duplicate);
+ this.segments.splice(index, 1);
+ }
+ }
this.updatePageElements();
// Sometimes video duration is inaccurate, pull from accessibility info
@@ -813,8 +824,14 @@ class PreviewBar {
return -1;
} else if (a.actionType !== ActionType.Chapter && b.actionType === ActionType.Chapter) {
return 1;
+ } else if (a.actionType === ActionType.Chapter && b.actionType === ActionType.Chapter
+ && a.source === SponsorSourceType.Server && b.source !== SponsorSourceType.Server) {
+ return -0.5;
+ } else if (a.actionType === ActionType.Chapter && b.actionType === ActionType.Chapter
+ && a.source !== SponsorSourceType.Server && b.source === SponsorSourceType.Server) {
+ return 0.5;
} else {
- return (b.segment[0] - a.segment[0]);
+ return (b.segment[0] - a.segment[0]) * 4;
}
})[0];