Skip to content

Commit

Permalink
option to blacklist sites (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslawPokropinski authored Oct 30, 2021
1 parent 37ad89a commit 727def7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,13 @@
"keyInputPlaceholder": {
"message": "Motrix API Key",
"description": "Motrix API Key"
},
"blacklist": {
"message": "Blacklist",
"description": "Blacklist"
},
"saveBlacklist": {
"message": "Save blacklist",
"description": "Save blacklist"
}
}
11 changes: 11 additions & 0 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,31 @@ function downloadAgent() {
'enableNotifications',
'enableDownloadPrompt',
'minFileSize',
'blacklist',
]);

getResult.then(async (result) => {
if (!result.extensionStatus) {
// Extension is disabled
return;
}

if (
downloadItem.fileSize > 0 &&
downloadItem.fileSize < result.minFileSize * 1024 * 1024
) {
// File size is known and it is smaller than the minimum file size (in mb)
return;
}

// If url is on the blacklist then skip
if (
result.blacklist
.map((x) => downloadItem.url.includes(x))
.reduce((prev, curr) => prev || curr, false)
) {
return;
}
if (!result.motrixAPIkey) {
// API KEY is not set, triggers an alert to the user
alert(
Expand Down
36 changes: 36 additions & 0 deletions app/scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function ConfigView() {
const [enableNotifications, setEnableNotifications] = useState(false);
const [enableDownloadPrompt, setEnableDownloadPrompt] = useState(false);
const [minFileSize, setMinFileSize] = useState('');
const [blacklist, setBlacklist] = useState([]);

useEffect(() => {
browser.storage.sync
Expand All @@ -26,6 +27,7 @@ function ConfigView() {
'enableNotifications',
'enableDownloadPrompt',
'minFileSize',
'blacklist',
])
.then(
(result) => {
Expand Down Expand Up @@ -65,6 +67,13 @@ function ConfigView() {
} else {
setEnableDownloadPrompt(result.enableDownloadPrompt);
}

if (typeof result.blacklist === 'undefined') {
browser.storage.sync.set({ blacklist: [] });
setBlacklist([]);
} else {
setBlacklist(result.blacklist);
}
},
(error) => {
console.error(`Error: ${error}`);
Expand Down Expand Up @@ -170,6 +179,33 @@ function ConfigView() {
/>
</Box>
</Grid>

{/* Blacklist */}
<Grid item xs={8}>
<TextField
label="__MSG_blacklist__"
multiline
fullWidth
rows={4}
value={blacklist.join('\n')}
onChange={(e) => setBlacklist(e.target.value.split('\n'))}
/>
</Grid>
{/* Save blacklist button */}
<Grid item xs={6} />
<Grid item xs={2}>
<Button
variant="outlined"
style={{ width: '100%', height: '56px' }}
onClick={() =>
browser.storage.sync.set({
blacklist: blacklist.filter((x) => x !== ''),
})
}
>
__MSG_saveBlacklist__
</Button>
</Grid>
</Grid>
</Container>
);
Expand Down

0 comments on commit 727def7

Please sign in to comment.