mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 04:57:09 +03:00
Improved behavior of next chapter keybind with overlap
This commit is contained in:
@@ -2237,7 +2237,7 @@ function updateActiveSegment(currentTime: number): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function nextChapter(): void {
|
function nextChapter(): void {
|
||||||
const chapters = previewBar.chapterGroups?.filter((time) => [ActionType.Chapter, null].includes(time.actionType));
|
const chapters = previewBar.unfilteredChapterGroups?.filter((time) => [ActionType.Chapter, null].includes(time.actionType));
|
||||||
if (!chapters || chapters.length <= 0) return;
|
if (!chapters || chapters.length <= 0) return;
|
||||||
|
|
||||||
lastNextChapterKeybind.time = video.currentTime;
|
lastNextChapterKeybind.time = video.currentTime;
|
||||||
@@ -2258,7 +2258,7 @@ function previousChapter(): void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chapters = previewBar.chapterGroups?.filter((time) => [ActionType.Chapter, null].includes(time.actionType));
|
const chapters = previewBar.unfilteredChapterGroups?.filter((time) => [ActionType.Chapter, null].includes(time.actionType));
|
||||||
if (!chapters || chapters.length <= 0) {
|
if (!chapters || chapters.length <= 0) {
|
||||||
video.currentTime = 0;
|
video.currentTime = 0;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class PreviewBar {
|
|||||||
originalChapterBar: HTMLElement;
|
originalChapterBar: HTMLElement;
|
||||||
originalChapterBarBlocks: NodeListOf<HTMLElement>;
|
originalChapterBarBlocks: NodeListOf<HTMLElement>;
|
||||||
chapterMargin: number;
|
chapterMargin: number;
|
||||||
|
unfilteredChapterGroups: ChapterGroup[];
|
||||||
chapterGroups: ChapterGroup[];
|
chapterGroups: ChapterGroup[];
|
||||||
|
|
||||||
constructor(parent: HTMLElement, onMobileYouTube: boolean, onInvidious: boolean, chapterVote: ChapterVote, test=false) {
|
constructor(parent: HTMLElement, onMobileYouTube: boolean, onInvidious: boolean, chapterVote: ChapterVote, test=false) {
|
||||||
@@ -311,13 +312,19 @@ class PreviewBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Merge overlapping chapters
|
// Merge overlapping chapters
|
||||||
|
this.unfilteredChapterGroups = this.createChapterRenderGroups(segments);
|
||||||
const filteredSegments = segments?.filter((segment) => this.chapterFilter(segment));
|
const filteredSegments = segments?.filter((segment) => this.chapterFilter(segment));
|
||||||
this.chapterGroups = this.createChapterRenderGroups(filteredSegments).filter((segment) => this.chapterGroupFilter(segment));
|
if (filteredSegments && filteredSegments.length !== segments.length) {
|
||||||
// Fix missing sections due to filtered segments
|
this.chapterGroups = this.createChapterRenderGroups(filteredSegments).filter((segment) => this.chapterGroupFilter(segment));
|
||||||
for (let i = 1; i < this.chapterGroups.length; i++) {
|
|
||||||
if (this.chapterGroups[i].segment[0] !== this.chapterGroups[i - 1].segment[1]) {
|
// Fix missing sections due to filtered segments
|
||||||
this.chapterGroups[i - 1].segment[1] = this.chapterGroups[i].segment[0]
|
for (let i = 1; i < this.chapterGroups.length; i++) {
|
||||||
|
if (this.chapterGroups[i].segment[0] !== this.chapterGroups[i - 1].segment[1]) {
|
||||||
|
this.chapterGroups[i - 1].segment[1] = this.chapterGroups[i].segment[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.chapterGroups = this.unfilteredChapterGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (segments.every((segments) => segments.source === SponsorSourceType.YouTube)
|
if (segments.every((segments) => segments.source === SponsorSourceType.YouTube)
|
||||||
@@ -407,11 +414,13 @@ class PreviewBar {
|
|||||||
latestValidChapter = result[result.length - 1];
|
latestValidChapter = result[result.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const priorityActionType = this.getActionTypePrioritized([segment.actionType, latestChapter?.actionType]);
|
||||||
|
|
||||||
// Split the latest chapter if smaller
|
// Split the latest chapter if smaller
|
||||||
result.push({
|
result.push({
|
||||||
segment: [segment.segment[0], segment.segment[1]],
|
segment: [segment.segment[0], segment.segment[1]],
|
||||||
originalDuration: segmentDuration,
|
originalDuration: segmentDuration,
|
||||||
actionType: segment.actionType
|
actionType: priorityActionType
|
||||||
});
|
});
|
||||||
if (latestValidChapter?.segment[1] > segment.segment[1]) {
|
if (latestValidChapter?.segment[1] > segment.segment[1]) {
|
||||||
result.push({
|
result.push({
|
||||||
@@ -478,6 +487,16 @@ class PreviewBar {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getActionTypePrioritized(actionTypes: ActionType[]): ActionType {
|
||||||
|
if (actionTypes.includes(ActionType.Skip)) {
|
||||||
|
return ActionType.Skip;
|
||||||
|
} else if (actionTypes.includes(ActionType.Mute)) {
|
||||||
|
return ActionType.Mute;
|
||||||
|
} else {
|
||||||
|
return actionTypes.find(a => a) ?? actionTypes[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private setupChapterSection(section: HTMLElement, startTime: number, endTime: number, addMargin: boolean): void {
|
private setupChapterSection(section: HTMLElement, startTime: number, endTime: number, addMargin: boolean): void {
|
||||||
const sizePercent = this.intervalToPercentage(startTime, endTime);
|
const sizePercent = this.intervalToPercentage(startTime, endTime);
|
||||||
if (addMargin) {
|
if (addMargin) {
|
||||||
|
|||||||
Reference in New Issue
Block a user