mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 14:41:20 -08:00
chore: Refactor artplayer-plugin-chapter to sort chapters before processing
This commit is contained in:
1 parent
5edf5af672
commit
d8ff61acf7
3 files changed
+15
-3
No files matched your search
@@ -44,12 +44,21 @@ export default function artplayerPluginChapter(option = {}) {
|
||||
function update(chapters = []) {
|
||||
if (!chapters.length) return;
|
||||
if (!art.duration) return;
|
||||
$control.innerText = '';
|
||||
|
||||
chapters = chapters.sort((a, b) => a.start - b.start);
|
||||
|
||||
for (let i = 0; i < chapters.length; i++) {
|
||||
const chapter = chapters[i];
|
||||
const nextChapter = chapters[i + 1];
|
||||
|
||||
if (
|
||||
typeof chapter.start !== 'number' ||
|
||||
typeof chapter.end !== 'number' ||
|
||||
typeof chapter.title !== 'string'
|
||||
) {
|
||||
throw new Error('Illegal chapter data type');
|
||||
}
|
||||
|
||||
if (chapter.start < 0 || chapter.end > art.duration || chapter.start >= chapter.end) {
|
||||
throw new Error('Illegal chapter time point');
|
||||
}
|
||||
@@ -77,6 +86,7 @@ export default function artplayerPluginChapter(option = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
$control.innerText = '';
|
||||
$chapters = chapters.map((chapter) => {
|
||||
const $chapter = append($control, html);
|
||||
const start = clamp(chapter.start, 0, art.duration);
|
||||
|
||||
Reference in new issue
Block a user