|
|
@ -1,44 +1,58 @@ |
|
|
|
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 || '') |
|
|
|
|
|
|
|
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 parts = url.match(/http:\/\/.*?\.(.*?)\..*?/) || [] |
|
|
|
const nickname = parts[1] || null |
|
|
|
const nickname = parts[1] || null |
|
|
|
const isPlacetgroup = url.indexOf('laen') > -1 || |
|
|
|
const isPlacetgroup = url.indexOf('laen') > -1 || |
|
|
|
url.indexOf('smsmoney') > -1 || |
|
|
|
url.indexOf('smsmoney') > -1 || |
|
|
|
url.indexOf('smsraha') > -1 || |
|
|
|
url.indexOf('smsraha') > -1 || |
|
|
|
url.indexOf('placetgroup') > -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 project = isPlacetgroup ? 'placetgroup' : 'nordecum' |
|
|
|
const domain = isPlacetgroup ? 'com' : 'lt' |
|
|
|
const tld = isPlacetgroup ? 'com' : 'lt' |
|
|
|
const isLocal = url.indexOf('.sv') !== -1 |
|
|
|
const isLocal = url.indexOf('.sv') !== -1 |
|
|
|
if (nickname && isLocal) { |
|
|
|
if (nickname && isLocal) { |
|
|
|
url = project + '.' + nickname + '.sv' |
|
|
|
url = project + '.' + nickname + '.sv' |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
url = 'dev.' + project + '.' + domain |
|
|
|
url = 'dev.' + project + '.' + tld |
|
|
|
} |
|
|
|
} |
|
|
|
url = (isLocal ? 'http://' : 'https://') + url |
|
|
|
url = (isLocal ? 'http://' : 'https://') + url |
|
|
|
console.log('domain_resolver', parts, nickname, isPlacetgroup, project, domain, url) |
|
|
|
console.log('domain_resolver', parts, nickname, isPlacetgroup, project, tld, 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 |
|
|
|
return url |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|