0

I would like to help me find a way how to count the clicks of a button with class and appear it on a chrome extension like the numbers that adblock has on its counter. Is this possible?

I have this code of button

 <a class="button" href="#" role="button">

<span>Button</span></a>

And i want a code that every time i hit this button to add +1 on the chrome extension icon like in adblock.

But this code does not have any "onClick" is it possible to be done?

Thanks for your time!

  • I found this https://stackoverflow.com/questions/5759130/google-chrome-extension-numbers-on-the-iconlink looking around. Hopefully it helps. – Yeezus Sep 08 '15 at 16:13

2 Answers2

0

Read this if you havn't already: https://developer.chrome.com/extensions/getstarted

Have this in your background page:

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
  if(request.message="add one"){
    chrome.browserAction.getBadgeText({tabId:sender.id}, function(badgeText){//get the tab's badge text
         if(badgeText.length<1){
             badgeText="0";//set the text if its empty
         }
         chrome.browserAction.setBadgeText({tabId:tab.id,text:badgeText/1+1+""});//and add one.
    });
  }
});

Call this from your context script whenever the button is pressed: chrome.runtime.sendMessage({message:"add one"});

Marc Guiselin
  • 3,442
  • 2
  • 25
  • 37
0

If you want it in HTML, something like that should work : http://jsfiddle.net/o0wy6oku/

.countSpan{
    position: relative;
    left: 12px;
    top: 7px;
    text-align: -webkit-match-parent;
}
Val
  • 65
  • 2
  • 12