export class DomainResolver { resolve (): Promise { const promise = new Promise((resolve) => { if (typeof chrome.tabs === 'undefined') { const url = this.grabTargetUrl(location.href || '') resolve(url) return } chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { for (const tab of tabs) { const url = this.grabTargetUrl(tab.url || '') resolve(url) return } }) }) // eslint-disable-next-line @typescript-eslint/ban-ts-ignore // @ts-ignore return promise.then((url) => { console.log('url', url) return url }) } grabTargetUrl (url: string): string | null { if (url.indexOf('localhost') > -1) { return null } const parts = url.match(/http:\/\/.*?\.(.*?)\..*?/) || [] const nickname = parts[1] || null const isNordecum = url.indexOf('smspinigai') > -1 || url.indexOf('paskolos') > -1 || url.indexOf('nordecum') > -1 const project = isNordecum ? 'nordecum' : 'placetgroup' const tld = isNordecum ? 'lt' : 'com' const isLocal = url.indexOf('.sv') !== -1 if (isLocal && !nickname) { return null } url = isLocal ? 'http://' + project + '.' + nickname + '.sv' : 'https://dev.' + project + '.' + tld console.log('domain_resolver', parts, nickname, isNordecum, project, tld, url) return url } } export default new DomainResolver()