import browser from 'webextension-polyfill' ; import AgentoInfo from './domain' ; abstract class Strategy { abstract getCompanyName ( ) ; abstract insertElement ( infoObject ) ; async getCompanyInfo ( companyName ) { return browser . runtime . sendMessage ( { query : companyName } ) ; } createFreshAgentoContainer ( ) { let agentoContainer = document . getElementById ( 'agento-container' ) ; if ( agentoContainer ) { agentoContainer . remove ( ) ; } agentoContainer = document . createElement ( 'div' ) ; agentoContainer . setAttribute ( 'id' , 'agento-container' ) ; return agentoContainer ; } render ( ) { ( async ( ) => { const companyName = await this . getCompanyName ( ) ; let infoObject = await this . getCompanyInfo ( companyName ) ; if ( ! infoObject ) { infoObject = await this . getCompanyInfo ( companyName . replace ( /\(.*?\)/g , '' ) ) ; } this . insertElement ( infoObject ) ; } ) ( ) ; } } export default Strategy ;