@@ -46,6 +46,8 @@ class PreviewBar {
4646 segments : PreviewBarSegment [ ] = [ ] ;
4747 existingChapters : PreviewBarSegment [ ] = [ ] ;
4848 videoDuration = 0 ;
49+ updateExistingChapters : ( ) => void ;
50+ lastChapterUpdate = 0 ;
4951
5052 // For chapter bar
5153 hoveredSection : HTMLElement ;
@@ -58,7 +60,7 @@ class PreviewBar {
5860 unfilteredChapterGroups : ChapterGroup [ ] ;
5961 chapterGroups : ChapterGroup [ ] ;
6062
61- constructor ( parent : HTMLElement , onMobileYouTube : boolean , onInvidious : boolean , chapterVote : ChapterVote , test = false ) {
63+ constructor ( parent : HTMLElement , onMobileYouTube : boolean , onInvidious : boolean , chapterVote : ChapterVote , updateExistingChapters : ( ) => void , test = false ) {
6264 if ( test ) return ;
6365 this . container = document . createElement ( 'ul' ) ;
6466 this . container . id = 'previewbar' ;
@@ -67,6 +69,7 @@ class PreviewBar {
6769 this . onMobileYouTube = onMobileYouTube ;
6870 this . onInvidious = onInvidious ;
6971 this . chapterVote = chapterVote ;
72+ this . updateExistingChapters = updateExistingChapters ;
7073
7174 this . updatePageElements ( ) ;
7275 this . createElement ( parent ) ;
@@ -647,6 +650,12 @@ class PreviewBar {
647650
648651 cursor += sectionWidthDecimal ;
649652 }
653+
654+ if ( sections . length !== 0 && sections . length !== this . existingChapters ?. length
655+ && Date . now ( ) - this . lastChapterUpdate > 3000 ) {
656+ this . lastChapterUpdate = Date . now ( ) ;
657+ this . updateExistingChapters ( ) ;
658+ }
650659 }
651660 }
652661
0 commit comments