CSV download in More info tab

main
Elbert Alias 3 years ago
parent e5d5bf91e2
commit 5f1bdf274d

@ -286,6 +286,7 @@ small {
.panel__content th { .panel__content th {
font-weight: normal; font-weight: normal;
text-align: left; text-align: left;
min-width: 200px;
width: 33%; width: 33%;
} }

@ -8,6 +8,9 @@ const { agent, open, i18n, getOption, setOption, promisify, sendMessage } =
const baseUrl = 'https://www.wappalyzer.com' const baseUrl = 'https://www.wappalyzer.com'
const utm = '?utm_source=popup&utm_medium=extension&utm_campaign=wappalyzer' const utm = '?utm_source=popup&utm_medium=extension&utm_campaign=wappalyzer'
let csv = ''
let csvFilename = ''
const footers = [ const footers = [
{ {
heading: 'Generate sales leads', heading: 'Generate sales leads',
@ -147,6 +150,9 @@ const Popup = {
headerSwitchDisabled: document.querySelector('.header__switch--disabled'), headerSwitchDisabled: document.querySelector('.header__switch--disabled'),
plusConfigureApiKey: document.querySelector('.plus-configure__apikey'), plusConfigureApiKey: document.querySelector('.plus-configure__apikey'),
plusConfigureSave: document.querySelector('.plus-configure__save'), plusConfigureSave: document.querySelector('.plus-configure__save'),
plusDownloadLink: document.querySelector(
'.plus-download__button .button__link'
),
headerSettings: document.querySelector('.header__settings'), headerSettings: document.querySelector('.header__settings'),
headerThemes: document.querySelectorAll('.header__theme'), headerThemes: document.querySelectorAll('.header__theme'),
headerThemeLight: document.querySelector('.header__theme--light'), headerThemeLight: document.querySelector('.header__theme--light'),
@ -324,6 +330,9 @@ const Popup = {
}) })
}) })
// Download
el.plusDownloadLink.addEventListener('click', (event) => Popup.downloadCsv)
// Footer // Footer
const item = const item =
footers[ footers[
@ -592,7 +601,7 @@ const Popup = {
https = protocol === 'https:' https = protocol === 'https:'
hostname = hostname.replace(/^www\./, '').replace(/\./g, '-') hostname = hostname.replace(/^www\./, '')
} catch (error) { } catch (error) {
// Continue // Continue
} }
@ -660,7 +669,10 @@ const Popup = {
), ),
] ]
const csv = [`"${columns.join('","')}"`] csv = [`"${columns.join('","')}"`]
csvFilename = `wappalyzer${
hostname ? `_${hostname.replace('.', '-')}` : ''
}.csv`
const row = [`http${https ? 's' : ''}://${www ? 'www.' : ''}${hostname}`] const row = [`http${https ? 's' : ''}://${www ? 'www.' : ''}${hostname}`]
@ -856,6 +868,19 @@ const Popup = {
i18n() i18n()
}, },
downloadCsv() {
event.preventDefault()
chrome.downloads.download({
url: URL.createObjectURL(
new Blob([csv.join('\n')], { type: 'text/csv;charset=utf-8' })
),
filename: csvFilename,
})
return false
},
} }
if (/complete|interactive|loaded/.test(document.readyState)) { if (/complete|interactive|loaded/.test(document.readyState)) {