import { pageType } from './PageType' ; class TitleBar { private readonly status = [ '↑' , '→' , '▶' , '↓' , '║' , '■' , '√' , ' ' ] ; private timer : number = 0 ; private haveStatus ( status = '' ) { if ( ! status ) { for ( const status of this . status ) { const str = `[${ status }]` ; if ( document . title . includes ( str ) ) { return true ; } } } else { const str = `[${ status }]` ; return document . title . includes ( str ) ; } return false ; } public reset ( ) { const type = pageType . getPageType ( ) ; clearInterval ( this . timer ) ; const ogTitle = document . querySelector ( 'meta[property="og:title"]' ) ! as HTMLMetaElement ; if ( ogTitle && ( type == 1 || type === 2 ) ) { document . title = ogTitle . content ; } else { if ( this . haveStatus ( ) ) { const index = document . title . indexOf ( ']' ) ; document . title = document . title . substr ( index + 1 , document . title . length ) ; } } } public change ( string ) { const state = `[${ string }]` ; if ( ! this . haveStatus ( ) ) { document . title = `${ state } ${ document . title }` ; } else { document . title = document . title . replace ( /\[.?\]/ , state ) ; } if ( string === '▶' || string === '→' ) { this . timer = window . setInterval ( ( ) => { if ( this . haveStatus ( string ) ) { document . title = document . title . replace ( state , '[ ]' ) ; } else { if ( this . haveStatus ( ' ' ) ) { document . title = document . title . replace ( '[ ]' , state ) ; } else { clearInterval ( this . timer ) ; } } } , 500 ) ; } else { clearInterval ( this . timer ) ; } } } const titleBar = new TitleBar ( ) ; export { titleBar } ;