Search code examples
javascriptjquerygoogle-chrome-extensionfirefox-addonfirefox-addon-webextensions

How do I make a badge counter similar to Ad-blocker?


I want to improve my extension and the best way for me to do that right now is probably to add a badge to show that it's blocking things. I just can't wrap my head around how badges work, here is my extension (https://github.com/Cybo1927/Anti-Click-Tracking) and thanks for the help!

I've tried checking popular extensions like uBlock Origin, AdGuard, and Adblock Plus but I can't seem to figure it out.

I hope for it to show the amount of things blocking (for all the attributes if possible)


Solution

  • You can use browser.browserAction.setBadgeText

    Code example:

    var clicks = 0;
    
    function increment() {
      browser.browserAction.setBadgeText({text: (++clicks).toString()});
    }
    
    browser.browserAction.onClicked.addListener(increment);
    

    For more information

    You can check this example too