How can I create a notification through Chrome API in JavaScript every time I press a specific button?

375 views Asked by At

I am essentially creating a Budget Manager Chrome Extension by following this Youtube playlist and one of the features is that whenever you reset the total a notification would be created which would say "Oh, you've reset the total." But, this only occurs once. For example, a couple minutes later, when testing, I tried to reset the total again but this time the notification did not come and I am not so familiar with JavaScript so I'm not sure how I can make it so that every time I reset the total, a notification pops up every time (through the Chrome Notifications API).

Here is my code so far in the .js file:

$('#resetTotal').click(function() {
    chrome.storage.sync.set({'total': 0}, function() {
        var notifOptions = {
            type: 'basic',
            iconUrl: 'icons48.png',
            title: 'Total Reset!',
            message: "Clean slate - your total has been reset to zero!"
        };
        chrome.notifications.create('limitNotif', notifOptions);
    });
    close();
});

But, it only creates a notification once. How can I make it that it creates a notification every time the button is pressed.

0

There are 0 answers