/**
 * Konichiwa~
 *
 * This file contains small enhancements like keyboard shortcuts
 * and tiny utilities like scroll to top which dramatically improves
 * the usability of 9anime.
 */ declare function require ( arg ) ; import { Intent , IRuntimeResponse } from "./common" ; export function globalShortcuts ( ) { $ ( document ) . on ( "keydown" , e => { if ( ! ( e . target . tagName === "INPUT" || e . target . tagName === "TEXTAREA" ) ) { switch ( e . keyCode ) { case 83 : e . preventDefault ( ) ; $ ( "#nac__enhancedSearch" ) . show ( ) ; $ ( "#nac__enhancedSearch__searchBox" ) . focus ( ) ; break ; case 84 : $ ( "html, body" ) . animate ( { scrollTop : 0 , } , 1000 ) ; break ; default : break ; } } } ) ; } /**
 * Adds a scroll to player arrow at the bottom right corner.
 */ export function scrollToTop ( ) { let upArrowIcon = chrome . extension . getURL ( "images/up-arrow.png" ) ; $ ( "body" ) . append ( `<span id='nac__scrollTop'>
            <img src="${ upArrowIcon }" height="25px" width="25px">
        </span>` ) ; let scrollTopIcon = $ ( "#nac__scrollTop" ) ; scrollTopIcon . on ( "click" , ( ) => { $ ( "html, body" ) . animate ( { scrollTop : 0 , } , 1000 ) ; } ) ; let scrollVisible = false ; $ ( window ) . on ( "scroll" , ( ) => { let scrollPos = $ ( window ) . scrollTop ( ) || 0 ; if ( scrollPos >= 300 && ! scrollVisible ) { scrollVisible = true ; scrollTopIcon . animate ( { bottom : "5px" , } ) ; } else if ( scrollPos < 300 && scrollVisible ) { scrollVisible = false ; scrollTopIcon . animate ( { bottom : "-25px" , } ) ; } else { } } ) ; } export function enhancedSearch ( ) { const template = require ( "html-loader!../templates/enhancedSearchOverlay.html" ) ; $ ( "body" ) . append ( template ) ; let search = $ ( "#nac__enhancedSearch" ) ; let searchTimeout = 0 ; let startSearch = ( ) => { let searchText = $ ( "#nac__enhancedSearch__searchBox" ) . val ( ) ; if ( searchText ) { chrome . runtime . sendMessage ( { baseUrl : window . location . origin , intent : Intent . Search_Anime , searchText , } , ( resp ) => { if ( resp . success ) { $ ( "#nac__enhancedSearch__results" ) . empty ( ) . append ( resp . data . html ) ; } } ) ; } } ; search . on ( "keydown" , e => { e . stopPropagation ( ) ; if ( e . keyCode ) { if ( e . keyCode === 27 ) { search . hide ( ) ; } else if ( e . keyCode === 8 || ( e . keyCode >= 48 && e . keyCode <= 90 ) ) { clearTimeout ( searchTimeout ) ; searchTimeout = setTimeout ( startSearch , 250 ) ; } else { } } } ) ; $ ( "#nac__enhancedSearch__close" ) . on ( "click" , ( ) => { search . hide ( ) ; } ) ; }