summaryrefslogtreecommitdiffstats
path: root/mobile/android/android-components/samples/browser/src/main/assets/extensions/test/background.js
blob: f3ee460d9bdef7493bc0b85e8ba5269aa13ff3d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

/* Avoid adding ID selector rules in this style sheet, since they could
 * inadvertently match elements in the article content. */

// Counts to three and sends a greeting via the browser action of a newly created tab.
browser.tabs.onCreated.addListener(tab => {
  let counter = 0;
  let intervalId = setInterval(() => {
    var message;
    if (++counter <= 3) {
      message = "" + counter;
    } else {
      message = "Hi!";
      clearInterval(intervalId);
    }
    browser.browserAction.setBadgeTextColor({
      tabId: tab.id,
      color: "#FFFFFF",
    });
    browser.browserAction.setBadgeText({ tabId: tab.id, text: message });
  }, 1000);
});

browser.browserAction.setBadgeBackgroundColor({ color: "#AAAAAA" });