mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 20:52:06 +00:00
feat: migration to TypeScript FINAL
Co-authored-by: Su-Yong <simssy2205@gmail.com>
This commit is contained in:
34
plugins/sponsorblock/segments.ts
Normal file
34
plugins/sponsorblock/segments.ts
Normal file
@ -0,0 +1,34 @@
|
||||
// Segments are an array [ [start, end], … ]
|
||||
import { Segment } from './types';
|
||||
|
||||
export const sortSegments = (segments: Segment[]) => {
|
||||
segments.sort((segment1, segment2) =>
|
||||
segment1[0] === segment2[0]
|
||||
? segment1[1] - segment2[1]
|
||||
: segment1[0] - segment2[0],
|
||||
);
|
||||
|
||||
const compiledSegments: Segment[] = [];
|
||||
let currentSegment: Segment | undefined;
|
||||
|
||||
for (const segment of segments) {
|
||||
if (!currentSegment) {
|
||||
currentSegment = segment;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentSegment[1] < segment[0]) {
|
||||
compiledSegments.push(currentSegment);
|
||||
currentSegment = segment;
|
||||
continue;
|
||||
}
|
||||
|
||||
currentSegment[1] = Math.max(currentSegment[1], segment[1]);
|
||||
}
|
||||
|
||||
if (currentSegment) {
|
||||
compiledSegments.push(currentSegment);
|
||||
}
|
||||
|
||||
return compiledSegments;
|
||||
};
|
||||
Reference in New Issue
Block a user