Skip to content

Commit

Permalink
Hide video uploader chapters if there is a sponsorblock chapter to re…
Browse files Browse the repository at this point in the history
…place it at almost the same time
  • Loading branch information
ajayyy committed Dec 8, 2024
1 parent 7e824df commit 6bfc667
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/js-components/previewBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];

Expand Down

0 comments on commit 6bfc667

Please sign in to comment.