11import Config from "./config" ;
22
33import Utils from "./utils" ;
4- import { SponsorTime , SponsorHideType , ActionType , SegmentUUID , SponsorSourceType , StorageChangesObject } from "./types" ;
5- import { Message , MessageResponse , IsInfoFoundMessageResponse , ImportSegmentsResponse , PopupMessage } from "./messageTypes" ;
4+ import {
5+ ActionType ,
6+ SegmentUUID ,
7+ SponsorHideType ,
8+ SponsorSourceType ,
9+ SponsorTime ,
10+ StorageChangesObject ,
11+ } from "./types" ;
12+ import {
13+ ImportSegmentsResponse ,
14+ IsInfoFoundMessageResponse ,
15+ Message ,
16+ MessageResponse ,
17+ PopupMessage ,
18+ } from "./messageTypes" ;
619import { showDonationLink } from "./utils/configUtils" ;
720import { AnimationUtils } from "./utils/animationUtils" ;
821import { GenericUtils } from "./utils/genericUtils" ;
@@ -11,6 +24,7 @@ import { localizeHtmlPage } from "./utils/pageUtils";
1124import { exportTimes } from "./utils/exporter" ;
1225import GenericNotice from "./render/GenericNotice" ;
1326import { noRefreshFetchingChaptersAllowed } from "./utils/licenseKey" ;
27+
1428const utils = new Utils ( ) ;
1529
1630interface MessageListener {
@@ -188,7 +202,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
188202 }
189203
190204 PageElements . exportSegmentsButton . addEventListener ( "click" , exportSegments ) ;
191- PageElements . importSegmentsButton . addEventListener ( "click" ,
205+ PageElements . importSegmentsButton . addEventListener ( "click" ,
192206 ( ) => PageElements . importSegmentsMenu . classList . toggle ( "hidden" ) ) ;
193207 PageElements . importSegmentsSubmit . addEventListener ( "click" , importSegments ) ;
194208
@@ -260,7 +274,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
260274 if ( dontShowNotice != undefined && dontShowNotice ) {
261275 PageElements . showNoticeAgain . style . display = "unset" ;
262276 }
263-
277+
264278 const values = [ "userName" , "viewCount" , "minutesSaved" , "vip" , "permissions" ] ;
265279 if ( ! Config . config . payments . freeAccess && ! noRefreshFetchingChaptersAllowed ( ) ) values . push ( "freeChaptersAccess" ) ;
266280
@@ -427,13 +441,10 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
427441 PageElements . loadingIndicator . style . display = "none" ;
428442
429443 downloadedTimes = request . sponsorTimes ?? [ ] ;
444+ displayDownloadedSponsorTimes ( downloadedTimes , request . time ) ;
430445 if ( request . found ) {
431446 PageElements . videoFound . innerHTML = chrome . i18n . getMessage ( "sponsorFound" ) ;
432-
433447 PageElements . issueReporterImportExport . classList . remove ( "hidden" ) ;
434- if ( request . sponsorTimes ) {
435- displayDownloadedSponsorTimes ( request . sponsorTimes , request . time ) ;
436- }
437448 } else if ( request . status == 404 || request . status == 200 ) {
438449 PageElements . videoFound . innerHTML = chrome . i18n . getMessage ( "sponsor404" ) ;
439450 PageElements . issueReporterImportExport . classList . remove ( "hidden" ) ;
@@ -514,7 +525,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
514525 PageElements . issueReporterTabs . classList . add ( "hidden" ) ;
515526 currentSegmentTab = SegmentTab . Segments ;
516527 } else {
517- if ( currentSegmentTab === SegmentTab . Segments
528+ if ( currentSegmentTab === SegmentTab . Segments
518529 && sponsorTimes . every ( ( segment ) => segment . actionType === ActionType . Chapter ) ) {
519530 PageElements . issueReporterTabs . classList . add ( "hidden" ) ;
520531 currentSegmentTab = SegmentTab . Chapters ;
@@ -529,7 +540,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
529540 if ( currentSegmentTab === SegmentTab . Segments ) {
530541 return segment . actionType !== ActionType . Chapter ;
531542 } else if ( currentSegmentTab === SegmentTab . Chapters ) {
532- return segment . actionType === ActionType . Chapter
543+ return segment . actionType === ActionType . Chapter
533544 && segment . source !== SponsorSourceType . YouTube ;
534545 } else {
535546 return true ;
@@ -546,7 +557,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
546557
547558 if ( downloadedTimes . length > 0 ) {
548559 PageElements . exportSegmentsButton . classList . remove ( "hidden" ) ;
549- } else {
560+ } else {
550561 PageElements . exportSegmentsButton . classList . add ( "hidden" ) ;
551562 }
552563
@@ -590,7 +601,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
590601 if ( downloadedTimes [ i ] . actionType === ActionType . Full ) {
591602 segmentTimeFromToNode . innerText = chrome . i18n . getMessage ( "full" ) ;
592603 } else {
593- segmentTimeFromToNode . innerText = GenericUtils . getFormattedTime ( downloadedTimes [ i ] . segment [ 0 ] , true ) +
604+ segmentTimeFromToNode . innerText = GenericUtils . getFormattedTime ( downloadedTimes [ i ] . segment [ 0 ] , true ) +
594605 ( actionType !== ActionType . Poi
595606 ? " " + chrome . i18n . getMessage ( "to" ) + " " + GenericUtils . getFormattedTime ( downloadedTimes [ i ] . segment [ 1 ] , true )
596607 : "" ) ;
@@ -695,7 +706,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
695706 skipButton . id = "sponsorTimesSkipButtonContainer" + UUID ;
696707 skipButton . className = "voteButton" ;
697708 skipButton . src = chrome . runtime . getURL ( "icons/skip.svg" ) ;
698- skipButton . title = actionType === ActionType . Chapter ? chrome . i18n . getMessage ( "playChapter" )
709+ skipButton . title = actionType === ActionType . Chapter ? chrome . i18n . getMessage ( "playChapter" )
699710 : chrome . i18n . getMessage ( "skipSegment" ) ;
700711 skipButton . addEventListener ( "click" , ( ) => skipSegment ( actionType , UUID , skipButton ) ) ;
701712 votingButtons . addEventListener ( "dblclick" , ( ) => skipSegment ( actionType , UUID ) ) ;
@@ -1022,7 +1033,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
10221033 UUID : UUID
10231034 } ) ;
10241035 }
1025-
1036+
10261037 if ( element ) {
10271038 const stopAnimation = AnimationUtils . applyLoadingAnimation ( element , 0.3 ) ;
10281039 stopAnimation ( ) ;
@@ -1141,6 +1152,9 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
11411152 case "time" :
11421153 displayDownloadedSponsorTimes ( downloadedTimes , msg . time ) ;
11431154 break ;
1155+ case "infoUpdated" :
1156+ infoFound ( msg ) ;
1157+ break ;
11441158 }
11451159 }
11461160}
0 commit comments