0

I'm new to Extensions and I want to make an extension for my website that displays how many PMs I receive. It should show up as a Chrome Icon, like this: http://puu.sh/5U4xv.png, where the number can be any number that's on my inbox. It also changes colors when there's no PMs (basic icon, no changes), when there's a couple of PMs it becomes yellow and when there's a lot of PMs it becomes red. The problem is, it doesn't work and I don't know how to receive the amount of PMs in my inbox and display it in the icon.

What I have right now:

case "getQuestions":
    var timeNow = new Date().getTime();
    if( (timeNow - questionsTimer) >= 15000 || questions == null ) {
        sendResponse('update');
    } else {
        sendResponse(reports);
    }
    break;

case "setQuestions":
    questions= request.questions;
    questionsTimer = new Date().getTime();
    var Total = questions.match(/total: ([0-9]+)/)[1];
    var Large = questions.match(/large: ([0-9]+)/)[1];

    if( Large > 0 ) {
        chrome.browserAction.setIcon({path: chrome.extension.getURL('Style/Images/icon_red.png')});
    } else {
        if( Total > 0 ) {
            chrome.browserAction.setIcon({path: chrome.extension.getURL('Style/Images/icon_yellow.png')});
        } else {
            chrome.browserAction.setIcon({path: chrome.extension.getURL('Style/Images/icon_green.png')});
            Total = "";
        }
    }
Swift Try
  • 171
  • 1
  • 1
  • 3
  • It is not clear what does not work. The code for setting the icon works fine. What exactly is your problem ? – gkalpak Dec 21 '13 at 20:11
  • The problem is that the extension can't read the amount of PMs. I want to display that. I want to find the proper class so the icon changes and displays the amount of PMs but I can't. – Swift Try Dec 21 '13 at 20:22
  • 2
    FYI, to set that counter, the [`chrome.browserAction.setBadgeText`](https://developer.chrome.com/extensions/browserAction.html#method-setBadgeText) method can be used. – Rob W Dec 21 '13 at 20:40
  • You are probably looking for **[`setBadgeText()`](https://developer.chrome.com/extensions/browserAction.html#method-setBadgeText)** and **[`setBadgeBackgroundColor()`](https://developer.chrome.com/extensions/browserAction.html#method-setBadgeBackgroundColor)**, as Rob suggested. – gkalpak Dec 21 '13 at 20:59
  • Check this question: http://stackoverflow.com/questions/8894461/updating-an-extension-button-dynamically-inspiration-required/11655534#11655534 – Eder Franco Oct 20 '15 at 22:05

0 Answers0