|
|
|
@ -1,33 +1,14 @@ |
|
|
|
|
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 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() |
|
|
|
|