|
| 1 | +var _ = require('underscore'); |
| 2 | +var browser = require('./browser'); |
| 3 | +var report = require('../report'); |
| 4 | + |
| 5 | +var url = 'http://hovercards.com'; |
| 6 | + |
| 7 | +browser.browserAction.setBadgeBackgroundColor({ color: '#ff0000' }); |
| 8 | +browser.browserAction.onClicked.addListener(function() { |
| 9 | + browser.tabs.create({ url: url }); |
| 10 | + browser.storage.sync.set({ 'notifications.opensource': true }) |
| 11 | + .catch(report.captureException); |
| 12 | +}); |
| 13 | + |
| 14 | +browser.storage.onChanged.addListener(function(changes, areaName) { |
| 15 | + if (areaName !== 'sync') { |
| 16 | + return; |
| 17 | + } |
| 18 | + _.pairs(changes).forEach(function(entry) { |
| 19 | + if (entry[0] !== 'notifications.opensource') { |
| 20 | + return; |
| 21 | + } |
| 22 | + if (entry[1].newValue) { |
| 23 | + url = 'http://hovercards.com'; |
| 24 | + browser.browserAction.setBadgeText({ text: '' }); |
| 25 | + browser.browserAction.setTitle({ title: 'HoverCards' }); |
| 26 | + } else { |
| 27 | + url = 'https://github.com/kogg/hovercards#readme'; |
| 28 | + browser.browserAction.setBadgeText({ text: '1' }); |
| 29 | + browser.browserAction.setTitle({ title: 'HoverCards is open source!' }); |
| 30 | + } |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +browser.storage.sync.get('notifications.opensource') |
| 35 | + .then(function(items) { |
| 36 | + if (items['notifications.opensource']) { |
| 37 | + url = 'http://hovercards.com'; |
| 38 | + browser.browserAction.setBadgeText({ text: '' }); |
| 39 | + browser.browserAction.setTitle({ title: 'HoverCards' }); |
| 40 | + } else { |
| 41 | + url = 'https://github.com/kogg/hovercards#readme'; |
| 42 | + browser.browserAction.setBadgeText({ text: '1' }); |
| 43 | + browser.browserAction.setTitle({ title: 'HoverCards is open source!' }); |
| 44 | + } |
| 45 | + }) |
| 46 | + .catch(report.captureException); |
0 commit comments