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

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

@ -1,33 +1,14 @@
export class DomainResolver { export class DomainResolver {
resolve (): Promise<string> { resolve (): Promise<string> {
const promise = new Promise((resolve) => { const promise = new Promise((resolve) => {
if (typeof chrome === 'undefined') {
resolve(null)
return
}
if (typeof chrome.tabs === 'undefined') { if (typeof chrome.tabs === 'undefined') {
resolve(null) const url = this.grabTargetUrl(location.href || '')
resolve(url)
return return
} }
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
for (const tab of tabs) { for (const tab of tabs) {
let url = tab.url || '' const url = this.grabTargetUrl(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)
resolve(url) resolve(url)
return return
} }
@ -40,6 +21,39 @@ export class DomainResolver {
return 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 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() export default new DomainResolver()

Loading…
Cancel
Save