From eab96894cbbefb7ae6250549e5874a03ef00ac99 Mon Sep 17 00:00:00 2001 From: Elbert Alias <77259+AliasIO@users.noreply.github.com> Date: Mon, 15 Nov 2021 08:09:02 +1100 Subject: [PATCH] Add CSV export --- .../webextension/_locales/ca/messages.json | 1 + .../webextension/_locales/de/messages.json | 1 + .../webextension/_locales/el/messages.json | 1 + .../webextension/_locales/en/messages.json | 1 + .../webextension/_locales/es/messages.json | 1 + .../webextension/_locales/fa/messages.json | 1 + .../webextension/_locales/fr/messages.json | 1 + .../webextension/_locales/gl_ES/messages.json | 1 + .../webextension/_locales/gr/messages.json | 1 + .../webextension/_locales/id/messages.json | 1 + .../webextension/_locales/it/messages.json | 1 + .../webextension/_locales/ja/messages.json | 1 + .../webextension/_locales/ko/messages.json | 1 + .../webextension/_locales/nl/messages.json | 1 + .../webextension/_locales/pl/messages.json | 1 + .../webextension/_locales/pt/messages.json | 1 + .../webextension/_locales/pt_BR/messages.json | 1 + .../webextension/_locales/ro/messages.json | 1 + .../webextension/_locales/ru/messages.json | 1 + .../webextension/_locales/sk/messages.json | 1 + .../webextension/_locales/tr/messages.json | 1 + .../webextension/_locales/uk/messages.json | 1 + .../webextension/_locales/uz/messages.json | 1 + .../webextension/_locales/zh_CN/messages.json | 1 + .../webextension/_locales/zh_TW/messages.json | 1 + src/drivers/webextension/css/styles.css | 10 ++ src/drivers/webextension/html/popup.html | 16 +- src/drivers/webextension/js/driver.js | 15 +- src/drivers/webextension/js/popup.js | 168 ++++++++++++++++++ src/drivers/webextension/manifest.json | 3 +- 30 files changed, 234 insertions(+), 3 deletions(-) diff --git a/src/drivers/webextension/_locales/ca/messages.json b/src/drivers/webextension/_locales/ca/messages.json index c541a783c..c35cc2136 100644 --- a/src/drivers/webextension/_locales/ca/messages.json +++ b/src/drivers/webextension/_locales/ca/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/de/messages.json b/src/drivers/webextension/_locales/de/messages.json index 5f2cb397f..4a08338bf 100644 --- a/src/drivers/webextension/_locales/de/messages.json +++ b/src/drivers/webextension/_locales/de/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/el/messages.json b/src/drivers/webextension/_locales/el/messages.json index 1018ef77a..9e0a0c10f 100644 --- a/src/drivers/webextension/_locales/el/messages.json +++ b/src/drivers/webextension/_locales/el/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/en/messages.json b/src/drivers/webextension/_locales/en/messages.json index 13435c873..09d536f98 100644 --- a/src/drivers/webextension/_locales/en/messages.json +++ b/src/drivers/webextension/_locales/en/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/es/messages.json b/src/drivers/webextension/_locales/es/messages.json index a080da570..8b84dd3a6 100644 --- a/src/drivers/webextension/_locales/es/messages.json +++ b/src/drivers/webextension/_locales/es/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/fa/messages.json b/src/drivers/webextension/_locales/fa/messages.json index 47fb224e1..e151aef54 100644 --- a/src/drivers/webextension/_locales/fa/messages.json +++ b/src/drivers/webextension/_locales/fa/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/fr/messages.json b/src/drivers/webextension/_locales/fr/messages.json index 59e91a111..555766d0d 100644 --- a/src/drivers/webextension/_locales/fr/messages.json +++ b/src/drivers/webextension/_locales/fr/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Type de société" }, "attributeCompanyFounded": { "message": "Création de l'entreprise" }, "attributeKeywords": { "message": "Mots clés" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "Enregistrement SPF" }, "attributeDns_dmarc": { "message": "Enregistrement DMARC" }, "attributeSchemaOrgTypes": { "message": "types schema.org" }, diff --git a/src/drivers/webextension/_locales/gl_ES/messages.json b/src/drivers/webextension/_locales/gl_ES/messages.json index 8c561e4db..1e85c8e01 100644 --- a/src/drivers/webextension/_locales/gl_ES/messages.json +++ b/src/drivers/webextension/_locales/gl_ES/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/gr/messages.json b/src/drivers/webextension/_locales/gr/messages.json index dcbf12f89..c75a202e1 100644 --- a/src/drivers/webextension/_locales/gr/messages.json +++ b/src/drivers/webextension/_locales/gr/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/id/messages.json b/src/drivers/webextension/_locales/id/messages.json index 1b5074750..adde316bd 100644 --- a/src/drivers/webextension/_locales/id/messages.json +++ b/src/drivers/webextension/_locales/id/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/it/messages.json b/src/drivers/webextension/_locales/it/messages.json index 46e7d32c9..a6efd243d 100644 --- a/src/drivers/webextension/_locales/it/messages.json +++ b/src/drivers/webextension/_locales/it/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/ja/messages.json b/src/drivers/webextension/_locales/ja/messages.json index 3f2c9b2bc..4a5d28684 100644 --- a/src/drivers/webextension/_locales/ja/messages.json +++ b/src/drivers/webextension/_locales/ja/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "会社種別" }, "attributeCompanyFounded": { "message": "会社創立日" }, "attributeKeywords": { "message": "キーワード" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPFレコード" }, "attributeDns_dmarc": { "message": "DMARCレコード" }, "attributeSchemaOrgTypes": { "message": "schema.orgタイプ" }, diff --git a/src/drivers/webextension/_locales/ko/messages.json b/src/drivers/webextension/_locales/ko/messages.json index bbacf366d..f8485f0bf 100644 --- a/src/drivers/webextension/_locales/ko/messages.json +++ b/src/drivers/webextension/_locales/ko/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "회사 종류" }, "attributeCompanyFounded": { "message": "회사 상장" }, "attributeKeywords": { "message": "키워드" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF 레코드" }, "attributeDns_dmarc": { "message": "DMARC 레코드" }, "attributeSchemaOrgTypes": { "message": "schema.org 타입" }, diff --git a/src/drivers/webextension/_locales/nl/messages.json b/src/drivers/webextension/_locales/nl/messages.json index 4b451d9a2..4b11536c6 100644 --- a/src/drivers/webextension/_locales/nl/messages.json +++ b/src/drivers/webextension/_locales/nl/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Bedrijfstype" }, "attributeCompanyFounded": { "message": "Oprichting van het bedrijf" }, "attributeKeywords": { "message": "Trefwoorden" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF-registratie" }, "attributeDns_dmarc": { "message": "DMARC-registratie" }, "attributeSchemaOrgTypes": { "message": "Typen schema.org" }, diff --git a/src/drivers/webextension/_locales/pl/messages.json b/src/drivers/webextension/_locales/pl/messages.json index 663be5092..25658716b 100644 --- a/src/drivers/webextension/_locales/pl/messages.json +++ b/src/drivers/webextension/_locales/pl/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/pt/messages.json b/src/drivers/webextension/_locales/pt/messages.json index 2a2620ab3..01dbc5e2b 100644 --- a/src/drivers/webextension/_locales/pt/messages.json +++ b/src/drivers/webextension/_locales/pt/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/pt_BR/messages.json b/src/drivers/webextension/_locales/pt_BR/messages.json index ad36017e7..4e98dbebc 100644 --- a/src/drivers/webextension/_locales/pt_BR/messages.json +++ b/src/drivers/webextension/_locales/pt_BR/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/ro/messages.json b/src/drivers/webextension/_locales/ro/messages.json index d61f2d843..b69336056 100644 --- a/src/drivers/webextension/_locales/ro/messages.json +++ b/src/drivers/webextension/_locales/ro/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/ru/messages.json b/src/drivers/webextension/_locales/ru/messages.json index 253661c8d..2142633a6 100644 --- a/src/drivers/webextension/_locales/ru/messages.json +++ b/src/drivers/webextension/_locales/ru/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/sk/messages.json b/src/drivers/webextension/_locales/sk/messages.json index e83b5f9f8..55afaca59 100644 --- a/src/drivers/webextension/_locales/sk/messages.json +++ b/src/drivers/webextension/_locales/sk/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/tr/messages.json b/src/drivers/webextension/_locales/tr/messages.json index 389e20683..375a123c5 100644 --- a/src/drivers/webextension/_locales/tr/messages.json +++ b/src/drivers/webextension/_locales/tr/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/uk/messages.json b/src/drivers/webextension/_locales/uk/messages.json index 7c91cfe5c..a8de4e1a7 100644 --- a/src/drivers/webextension/_locales/uk/messages.json +++ b/src/drivers/webextension/_locales/uk/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/uz/messages.json b/src/drivers/webextension/_locales/uz/messages.json index 67bb87640..1b5d466f0 100644 --- a/src/drivers/webextension/_locales/uz/messages.json +++ b/src/drivers/webextension/_locales/uz/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/zh_CN/messages.json b/src/drivers/webextension/_locales/zh_CN/messages.json index 2ec846c36..ef262653d 100644 --- a/src/drivers/webextension/_locales/zh_CN/messages.json +++ b/src/drivers/webextension/_locales/zh_CN/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/_locales/zh_TW/messages.json b/src/drivers/webextension/_locales/zh_TW/messages.json index 5d007922e..abee6c0fe 100644 --- a/src/drivers/webextension/_locales/zh_TW/messages.json +++ b/src/drivers/webextension/_locales/zh_TW/messages.json @@ -91,6 +91,7 @@ "attributeCompanyType": { "message": "Company type" }, "attributeCompanyFounded": { "message": "Company founded" }, "attributeKeywords": { "message": "Keywords" }, + "attributeEmployees": { "message": "Employees" }, "attributeDns_spf": { "message": "SPF record" }, "attributeDns_dmarc": { "message": "DMARC record" }, "attributeSchemaOrgTypes": { "message": "schema.org types" }, diff --git a/src/drivers/webextension/css/styles.css b/src/drivers/webextension/css/styles.css index 9e59a6628..bbd367f71 100644 --- a/src/drivers/webextension/css/styles.css +++ b/src/drivers/webextension/css/styles.css @@ -391,6 +391,16 @@ small { display: none; } +.plus-download { + background: var(--color-secondary); + padding: 1rem 1.5rem 0 1.5rem; + text-align: right; +} + +.plus-download--hidden { + display: none; +} + .plus-error { margin: 1.5rem; } diff --git a/src/drivers/webextension/html/popup.html b/src/drivers/webextension/html/popup.html index 7a9848d91..94c3830d4 100644 --- a/src/drivers/webextension/html/popup.html +++ b/src/drivers/webextension/html/popup.html @@ -154,6 +154,20 @@
+
+
+ + + + + + + Download CSV + + +
+
+
@@ -180,7 +194,7 @@
- +   diff --git a/src/drivers/webextension/js/driver.js b/src/drivers/webextension/js/driver.js index 908805692..7a69fee73 100644 --- a/src/drivers/webextension/js/driver.js +++ b/src/drivers/webextension/js/driver.js @@ -179,6 +179,13 @@ const Driver = { } }, + /** + * Get all categories + */ + getCategories() { + return Wappalyzer.categories + }, + /** * Perform a HTTP POST request * @param {String} url @@ -780,11 +787,17 @@ const Driver = { * Get the detected technologies for the current tab */ async getDetections() { - const [{ id, url }] = await promisify(chrome.tabs, 'query', { + const tab = await promisify(chrome.tabs, 'query', { active: true, currentWindow: true, }) + if (!tab) { + return + } + + const [{ id, url }] = tab + if (await Driver.isDisabledDomain(url)) { await Driver.setIcon(url, []) diff --git a/src/drivers/webextension/js/popup.js b/src/drivers/webextension/js/popup.js index fae3bed91..b48f82195 100644 --- a/src/drivers/webextension/js/popup.js +++ b/src/drivers/webextension/js/popup.js @@ -41,6 +41,54 @@ const footers = [ }, ] +const attributeKeys = [ + 'phone', + 'skype', + 'whatsapp', + 'email', + 'verifiedEmail', + 'safeEmail', + 'twitter', + 'facebook', + 'instagram', + 'github', + 'tiktok', + 'youtube', + 'pinterest', + 'linkedin', + 'owler', + 'title', + 'description', + 'copyright', + 'copyrightYear', + 'responsive', + 'schemaOrgTypes', + 'certInfo.subjectOrg', + 'certInfo.subjectCountry', + 'certInfo.subjectState', + 'certInfo.subjectLocality', + 'certInfo.issuer', + 'certInfo.protocol', + 'certInfo.validTo', + 'dns.spf', + 'dns.dmarc', + 'https', + 'trackerGoogleAnalytics', + 'trackerGoogleAdSense', + 'trackerMedianet', + 'trackerFacebook', + 'trackerOptimizely', + 'companyName', + 'inferredCompanyName', + 'industry', + 'about', + 'locations', + 'companySize', + 'companyType', + 'companyFounded', + 'employees', +] + function setDisabledDomain(enabled) { const el = { headerSwitchEnabled: document.querySelector('.header__switch--enabled'), @@ -56,6 +104,30 @@ function setDisabledDomain(enabled) { } } +function csvEscape(value = '') { + if (Array.isArray(value)) { + value = value + .flat() + .slice(0, 10) + .map((value) => csvEscape(value.replace(/ ; /g, ' : '))) + .join(' ; ') + } + + if (typeof value === 'string') { + return value.replace(/\n/g, ' ').replace(/"/g, '""').trim() + } + + if (typeof value === 'boolean') { + return String(value).toUpperCase() + } + + if (value === null) { + return '' + } + + return String(value).replace(/"/g, '""') +} + const Popup = { /** * Initialise popup @@ -472,6 +544,10 @@ const Popup = { empty: document.querySelector('.plus-empty'), crawl: document.querySelector('.plus-crawl'), error: document.querySelector('.plus-error'), + download: document.querySelector('.plus-download'), + downloadLink: document.querySelector( + '.plus-download__button .button__link' + ), errorMessage: document.querySelector('.plus-error__message'), configure: document.querySelector('.plus-configure'), credits: document.querySelector('.credits'), @@ -494,6 +570,7 @@ const Popup = { } el.panels.classList.add('panels--hidden') + el.download.classList.add('plus-download--hidden') el.empty.classList.add('plus-empty--hidden') el.crawl.classList.add('plus-crawl--hidden') el.error.classList.add('plus-error--hidden') @@ -502,6 +579,24 @@ const Popup = { el.panels.removeChild(el.panels.lastElementChild) } + let hostname = '' + let www = false + let https = false + + try { + let protocol = '' + + ;({ hostname, protocol } = new URL(url)) + + www = hostname.startsWith('www') + + https = protocol === 'https:' + + hostname = hostname.replace(/^www\./, '').replace(/\./g, '-') + } catch (error) { + // Continue + } + try { const response = await fetch( `https://api.wappalyzer.com/v2/plus/${encodeURIComponent(url)}`, @@ -549,6 +644,45 @@ const Popup = { return } + const categories = await Popup.driver('getCategories') + + const columns = [ + 'URL', + ...categories.map(({ id }) => + chrome.i18n.getMessage(`categoryName${id}`) + ), + ...attributeKeys.map((key) => + chrome.i18n.getMessage( + `attribute${ + key.charAt(0).toUpperCase() + key.slice(1).replace('.', '_') + }` + ) + ), + ] + + const csv = [`"${columns.join('","')}"`] + + const row = [`http${https ? 's' : ''}://${www ? 'www.' : ''}${hostname}`] + + const detections = await Popup.driver('getDetections') + + row.push( + ...categories.reduce((categories, { id }) => { + categories.push( + detections + .filter(({ categories }) => + categories.some(({ id: _id }) => _id === id) + ) + .map(({ name }) => name) + .join(' ; ') + ) + + return categories + }, []) + ) + + const attributeValues = {} + Object.keys(attributes).forEach((set) => { const panel = document.createElement('div') const header = document.createElement('div') @@ -579,11 +713,15 @@ const Popup = { }` ) + attributeValues[key] = [] + if (Array.isArray(value)) { value.forEach((value) => { const div = document.createElement('div') if (typeof value === 'object') { + attributeValues[key].push(value.text) + const a = document.createElement('a') a.href = value.to @@ -601,6 +739,8 @@ const Popup = { td.appendChild(div) } } else if (key === 'employees') { + attributeValues[key].push(value) + const [name, title] = value.split(' -- ') const strong = document.createElement('strong') @@ -613,17 +753,23 @@ const Popup = { div.appendChild(span) td.appendChild(div) } else { + attributeValues[key].push(value) + div.textContent = value td.appendChild(div) } }) } else if (key === 'companyName') { + attributeValues[key].push(value) + const strong = document.createElement('strong') strong.textContent = value td.appendChild(strong) } else { + attributeValues[key].push(value) + td.textContent = value } @@ -642,7 +788,29 @@ const Popup = { el.panels.appendChild(panel) }) + row.push(...attributeKeys.map((key) => csvEscape(attributeValues[key]))) + + csv.push(`"${row.join('","')}"`) + + el.downloadLink.addEventListener('click', (event) => { + event.preventDefault() + + const file = URL.createObjectURL( + new Blob([csv.join('\n')], { type: 'text/csv;charset=utf-8' }) + ) + + chrome.downloads.download({ + url: file, + filename: `wappalyzer${ + hostname ? `_${hostname.replace('.', '-')}` : '' + }.csv`, + }) + + return false + }) + el.panels.classList.remove('panels--hidden') + el.download.classList.remove('plus-download--hidden') } catch (error) { Popup.log(error.data) diff --git a/src/drivers/webextension/manifest.json b/src/drivers/webextension/manifest.json index afa84028c..2800c07e7 100644 --- a/src/drivers/webextension/manifest.json +++ b/src/drivers/webextension/manifest.json @@ -73,8 +73,9 @@ "tabs", "webRequest", "webNavigation", + "downloads", "http://*/*", "https://*/*" ], "content_security_policy": "script-src 'self'; object-src 'self'" -} \ No newline at end of file +}