declare function require ( arg ) ; import { Intent , IRecentlyWatched , IRuntimeResponse } from "./lib/common" ; import { isUrl , loadSettings } from "./lib/utils" ; let recentlyWatched = $ ( "#recently-watched" ) ; let noItemsOverlay = $ ( "#no-items" ) ; $ ( ".setting" ) . on ( "click" , ( ) => { chrome . runtime . sendMessage ( { intent : Intent . Open_Options , } ) ; } ) ; loadSettings ( [ "quickLink" ] ) . then ( res => { $ ( ".logo" ) . on ( "click" , ( ) => { chrome . tabs . create ( { url : res . quickLink || "https://9anime.to" , } ) ; } ) ; } ) ; $ ( ".integrate-mal" ) . on ( "click" , ( ) => { chrome . runtime . sendMessage ( { intent : Intent . Open_Options , params : { goto : "MyAnimeList" , } , } ) ; } ) ; function showOverlay ( ) { noItemsOverlay . show ( ) ; recentlyWatched . hide ( ) ; } function removeListItem ( el , animeId ) { chrome . runtime . sendMessage ( { animeId , intent : Intent . Recently_Watched_Remove , } , ( r ) => { if ( r . success ) { let target = $ ( el ) ; if ( ( r . data as number ) > 0 ) { target . parents ( ".item" ) . addClass ( "fade-out" ) ; setTimeout ( ( ) => { target . parents ( ".item" ) . remove ( ) ; } , 500 ) ; } else { target . parents ( ".item" ) . remove ( ) ; showOverlay ( ) ; } } } ) ; } function generateListItem ( item ) { let display = "flex" ; let listItem = $ ( `<div class="item" style="display: ${ display }">
            <div class="item-body">
                <span class="name"></span>
                <span class="label" style="display: none;"></span>
            </div>
            <img src="images/remove-icon.png" class="remove" alt="Remove Item">
        </div>` ) ; if ( item . epNum && item . epId ) { listItem . find ( ".label" ) . text ( `E${ item . epNum }` ) . show ( ) ; item . url += `/${ item . epId }` ; } listItem . find ( ".name" ) . text ( item . animeName ) ; if ( isUrl ( item . url ) ) { listItem . find ( ".item-body" ) . on ( "click" , ( ) => { chrome . tabs . create ( { url : item . url , } ) ; } ) ; } listItem . find ( ".remove" ) . on ( "click" , e => { removeListItem ( e . currentTarget , item . animeId ) ; } ) ; return listItem ; } /**
 * Returns a html string for the list items.
 */ function generateList ( items ) { for ( let item of items ) { recentlyWatched . append ( generateListItem ( item ) ) ; } } chrome . runtime . sendMessage ( { intent : Intent . Recently_Watched_List , } , ( resp ) => { if ( ( resp . data as IRecentlyWatched [ ] ) . length > 0 ) { generateList ( resp . data ) ; } else { showOverlay ( ) ; } } ) ; $ ( ".version" ) . text ( chrome . runtime . getManifest ( ) . version ) ;