Доработал резолвер доменов для режима вне плагина

master
Sipachev Igor 3 years ago
parent 3658044216
commit e5c055cdc2
  1. 52
      popup/src/api/DomainResolver.ts

@ -1,44 +1,58 @@
export class DomainResolver {
resolve (): Promise<string> {
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 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 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 domain = isPlacetgroup ? 'com' : 'lt'
const tld = isPlacetgroup ? 'com' : 'lt'
const isLocal = url.indexOf('.sv') !== -1
if (nickname && isLocal) {
url = project + '.' + nickname + '.sv'
} else {
url = 'dev.' + project + '.' + domain
url = 'dev.' + project + '.' + tld
}
url = (isLocal ? 'http://' : 'https://') + url
console.log('domain_resolver', parts, nickname, isPlacetgroup, project, domain, url)
resolve(url)
return
}
})
})
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
return promise.then((url) => {
console.log('url', url)
console.log('domain_resolver', parts, nickname, isPlacetgroup, project, tld, url)
return url
})
}
}

Loading…
Cancel
Save