Skip to content

Commit

Permalink
fix csv columns and filename
Browse files Browse the repository at this point in the history
  • Loading branch information
joshparkerj committed Jan 8, 2022
1 parent cbfc4cf commit 2365777
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions worldometer/covid-table.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
saveButton.innerText = 'Save table as CSV';

saveButton.addEventListener('click', () => {
const csv = `${dataColumns.map(({ name }) => name).join(',')}\n${dates.map((date, i) => `${date},${dataColumns.map(({ data }) => data[i]).join(',')}`).join('\n')}`;
const csv = `dates,${dataColumns.map(({ name }) => name).join(',')}\n${dates.map((date, i) => `"${date}",${dataColumns.map(({ data }) => data[i]).join(',')}`).join('\n')}`;

const blob = new Blob([csv], { type: 'text/csv' });
const url = URL.createObjectURL(blob);

GM_download({
url,
name: 'covid-table.csv',
name: `covid-table-${document.title.split('COVID')[0].trim()}.csv`,
saveAs: true,
onerror: ({ error, details }) => {
console.log(error);
Expand All @@ -86,6 +86,7 @@
const alert = document.createElement('div');
alert.innerText = 'You have to have .csv in your whitelisted extensions. Got to tampermonkey settings and make sure settings mode is beginner or advanced, not novice. Look for Downloads BETA.';
alert.style.setProperty('color', 'red');
alert.style.setProperty('position', 'absolute');
saveButton.appendChild(alert);
}
},
Expand Down

0 comments on commit 2365777

Please sign in to comment.