import { EVT } from './EVT' ; class PageType { constructor ( ) { this . type = this . getPageType ( ) ; window . addEventListener ( EVT . events . pageSwitch , ( ) => { this . checkPageTypeIsNew ( ) ; } ) ; } private type : number = 0 ; public getPageType ( ) { let type ; const host = window . location . hostname ; const path = window . location . pathname ; const userPage = ( ! host . startsWith ( 'www.' ) && ! host . startsWith ( 'api.' ) && ! host . startsWith ( 'downloads.' ) ) || path . startsWith ( '/@' ) ; if ( host === 'www.fanbox.cc' && path === '/' ) { type = 0 ; } else if ( path === '/home/supporting' ) { type = 1 ; } else if ( userPage && ! path . includes ( '/posts' ) && ! path . includes ( '/tags/' ) && ! path . includes ( '/shop' ) ) { type = 2 ; } else if ( userPage && path . endsWith ( '/posts' ) ) { type = 3 ; } else if ( userPage && path . includes ( '/posts/' ) ) { type = 4 ; } else if ( userPage && path . includes ( '/tags/' ) ) { type = 5 ; } else if ( userPage && path . endsWith ( '/shop' ) ) { type = 6 ; } else { throw new Error ( 'Page type matching failed' ) ; } return type ; } private checkPageTypeIsNew ( ) { let newType = this . getPageType ( ) ; if ( this . type !== newType ) { EVT . fire ( EVT . events . pageTypeChange , newType ) ; } this . type = newType ; } } const pageType = new PageType ( ) ; export { pageType } ;