From 8b8c0d64f4fc5746ecab24dffa304fc0d4562a43 Mon Sep 17 00:00:00 2001 From: Sipachev Igor Date: Mon, 4 Apr 2022 13:01:26 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- popup/src/api/CountryResolver.ts | 40 +++++++++++++++++++ popup/src/components/person-tab/script.ts | 5 +++ popup/src/components/person-tab/template.html | 8 ++-- 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 popup/src/api/CountryResolver.ts diff --git a/popup/src/api/CountryResolver.ts b/popup/src/api/CountryResolver.ts new file mode 100644 index 0000000..4ab4fa9 --- /dev/null +++ b/popup/src/api/CountryResolver.ts @@ -0,0 +1,40 @@ +import { Country } from '@/classes/Enum/Country' + +export class CountryResolver { + resolve (): Promise { + const promise = new Promise((resolve) => { + if (typeof chrome.tabs === 'undefined') { + const country = this.grabCountry(location.href || '') + resolve(country) + return + } + chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { + for (const tab of tabs) { + const country = this.grabCountry(tab.url || '') + resolve(country) + return + } + }) + }) + // eslint-disable-next-line @typescript-eslint/ban-ts-ignore + // @ts-ignore + return promise.then((country) => { + console.log('country', country) + return country + }) + } + + grabCountry (url: string): Country { + const isNordecum = url.indexOf('smspinigai') > -1 || + url.indexOf('paskolos') > -1 || + url.indexOf('nordecum') > -1 + + if (isNordecum) { + return Country.LITHUANIA + } + + return Country.ESTONIA + } +} + +export default new CountryResolver() diff --git a/popup/src/components/person-tab/script.ts b/popup/src/components/person-tab/script.ts index 9d92dd2..585bfb2 100644 --- a/popup/src/components/person-tab/script.ts +++ b/popup/src/components/person-tab/script.ts @@ -10,6 +10,7 @@ import { Target } from '@/classes/Enum/Target' import sender from '@/classes/Service/Browser/Chrome/Sender' import { Action } from '@/classes/Enum/Action' import Mocks from '@/components/mocks/main.vue' +import countryResolver from '@/api/CountryResolver' Vue.use(VueClipboard) @@ -23,6 +24,10 @@ export default class PersonTab extends Vue { person = new Person() copyText = '' + async mounted () { + this.person.country = await countryResolver.resolve() + } + get allowedMonths () { const result = [] for (let i = 1; i <= 12; i++) { diff --git a/popup/src/components/person-tab/template.html b/popup/src/components/person-tab/template.html index 917895f..b227f97 100644 --- a/popup/src/components/person-tab/template.html +++ b/popup/src/components/person-tab/template.html @@ -17,11 +17,9 @@