Skip to content

Commit

Permalink
Update popup.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostnetic authored Apr 10, 2023
1 parent 30d9439 commit b9365f5
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ document.getElementById('generate-filter').addEventListener('click', () => {
chrome.runtime.sendMessage(
{ action: 'generateFilter', fileContents },
response => {
if (response.error) {
if (response && response.error) {
alert(response.error);
} else {
downloadFile('my-blocklist.txt', response.filterContent);
}
}
);
Expand All @@ -35,12 +33,10 @@ function readFileAsText(file) {
});
}

function downloadFile(filename, content) {
const blob = new Blob([content], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
document.getElementById('file-input').addEventListener('change', (event) => {
const fileInput = event.target;
const fileNames = Array.from(fileInput.files)
.map(file => file.name)
.join(', ');
document.getElementById('file-selected-label').textContent = fileNames || 'No file chosen';
});

0 comments on commit b9365f5

Please sign in to comment.