Skip to content

Commit

Permalink
fix(edge): prevent multiple notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 committed Dec 28, 2019
1 parent 7e8ff9a commit 1ab4041
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/js/background.ts
Expand Up @@ -24,6 +24,9 @@ const amazonURLs = [
'*://*.amazon.nl/*'
];

const urlPattern = 'https?://w*.?amazon.(ae|ca|cn|co.jp|co.uk|com.au|com.br|com.mx|com.sg|com.tr|com|de|es|fr|ie|in|it|nl)/w*';
const urlRegExp = new RegExp(urlPattern);

interface BeforeRequestResponse {
url: string;
}
Expand All @@ -36,28 +39,33 @@ browser.webRequest.onBeforeRequest.addListener(
['blocking']
);
browser.webNavigation.onCompleted.addListener(
() => {
if (tags && tags.length) {
storage.get('disableNotifications').then((item: any) => {
if (!item.disableNotifications) {
browser.notifications
.create(amazonTagRemoverNotification, {
event => {
if (urlRegExp.test(event.url)) {
if (tags && tags.length) {
storage.get('disableNotifications').then((item: any) => {
if (!item.disableNotifications) {
console.log('calling notification');
// EdgeHTML sometimes does not return a Promise, but undefined
const potentialNotificationPromise = browser.notifications.create(amazonTagRemoverNotification, {
iconUrl: browser.extension.getURL('images/icon64.png'),
message: `The following tags were found and have been removed: ${tags}`,
title: 'Amazon Tag Remover',
type: 'basic'
})
.then(() => (tags = []));
} else {
tags = [];
}
});
});
if (potentialNotificationPromise && potentialNotificationPromise.then) {
potentialNotificationPromise.then(() => (tags = []));
}
} else {
tags = [];
}
});
}
}
},
{
url: [
{
urlMatches: 'https?://w*.?amazon.(ae|ca|cn|co.jp|co.uk|com.au|com.br|com.mx|com.sg|com.tr|com|de|es|fr|ie|in|it|nl)/w*'
urlMatches: urlPattern
}
]
}
Expand Down

0 comments on commit 1ab4041

Please sign in to comment.