aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/background.js
blob: 1557814b42069c14d2b2d812096c1628db2f041b (plain) (blame)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const web3 = require('web3')

const identitiesUrl = 'https://alpha.metamask.io/identities/'
const messagingChannelName = 'metamask'


// setup badge click handler
chrome.browserAction.onClicked.addListener(function(activeTab) {
  chrome.tabs.create({ url: identitiesUrl })
})

// setup page<->plugin messaging
chrome.runtime.onConnect.addListener(function(port) {
  console.assert(port.name == messagingChannelName)
  port.onMessage.addListener(function(msg) {
    console.log(msg)
    port.postMessage({answer: 'Madame'})
  })
})

// update badge text
chrome.browserAction.setBadgeText({text: '2'})

// listen to storage changes
chrome.storage.onChanged.addListener(function(changes, namespace) {
  for (key in changes) {
    var storageChange = changes[key]
    console.log('Storage key "%s" in namespace "%s" changed. ' +
                'Old value was "%s", new value is "%s".',
                key,
                namespace,
                storageChange.oldValue,
                storageChange.newValue)
  }
})

// Save it using the Chrome extension storage API.
chrome.storage.sync.set({'zzz': 22}, function() {
  // Notify that we saved.
  console.log('Settings saved')
})