From e5c055cdc2ad4fe8af168303433b8fedaf85812e Mon Sep 17 00:00:00 2001 From: Sipachev Igor Date: Wed, 23 Mar 2022 13:22:21 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BB=20=D1=80=D0=B5=D0=B7=D0=BE=D0=BB=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D0=B0=20=D0=B2=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popup/src/api/DomainResolver.ts | 58 ++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/popup/src/api/DomainResolver.ts b/popup/src/api/DomainResolver.ts index 1f5c68e..26515da 100644 --- a/popup/src/api/DomainResolver.ts +++ b/popup/src/api/DomainResolver.ts @@ -1,33 +1,14 @@ export class DomainResolver { resolve (): Promise { const promise = new Promise((resolve) => { - if (typeof chrome === 'undefined') { - resolve(null) - return - } if (typeof chrome.tabs === 'undefined') { - resolve(null) + const url = this.grabTargetUrl(location.href || '') + resolve(url) return } chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { for (const tab of tabs) { - let url = tab.url || '' - const parts = url.match(/http:\/\/.*?\.(.*?)\..*?/) || [] - const nickname = parts[1] || null - const isPlacetgroup = url.indexOf('laen') > -1 || - url.indexOf('smsmoney') > -1 || - url.indexOf('smsraha') > -1 || - url.indexOf('placetgroup') > -1 - const project = isPlacetgroup ? 'placetgroup' : 'nordecum' - const domain = isPlacetgroup ? 'com' : 'lt' - const isLocal = url.indexOf('.sv') !== -1 - if (nickname && isLocal) { - url = project + '.' + nickname + '.sv' - } else { - url = 'dev.' + project + '.' + domain - } - url = (isLocal ? 'http://' : 'https://') + url - console.log('domain_resolver', parts, nickname, isPlacetgroup, project, domain, url) + const url = this.grabTargetUrl(tab.url || '') resolve(url) return } @@ -40,6 +21,39 @@ export class DomainResolver { 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 isPlacetgroup = url.indexOf('laen') > -1 || + url.indexOf('smsmoney') > -1 || + url.indexOf('smsraha') > -1 || + url.indexOf('placetgroup') > -1 + + const isNordecum = url.indexOf('smspinigai') > -1 || + url.indexOf('paskolos') > -1 || + url.indexOf('nordecum') > -1 + + if (!isPlacetgroup && !isNordecum) { + return null + } + + const project = isPlacetgroup ? 'placetgroup' : 'nordecum' + const tld = isPlacetgroup ? 'com' : 'lt' + const isLocal = url.indexOf('.sv') !== -1 + if (nickname && isLocal) { + url = project + '.' + nickname + '.sv' + } else { + url = 'dev.' + project + '.' + tld + } + url = (isLocal ? 'http://' : 'https://') + url + console.log('domain_resolver', parts, nickname, isPlacetgroup, project, tld, url) + return url + } } export default new DomainResolver()