summaryrefslogtreecommitdiffstats
path: root/mobile/android/android-components/samples/browser/src/main/assets/extensions/test/background.js
blob: 950936be4c0fe95111e8b2f6134bf36b8663f356 (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
/* 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"});