|
1 | 1 | /* global repeater */ |
2 | 2 |
|
3 | 3 | /* updating badge when action is posted */ |
4 | | -chrome.webRequest.onCompleted.addListener(d => { |
5 | | - if (d.tabId) { |
6 | | - if ( |
7 | | - d.type === 'main_frame' || |
8 | | - d.url.includes('&act=') || |
9 | | - (d.url.includes('/sync/u/') && d.method === 'POST') || |
10 | | - (d.url.includes('/mail/u/') && d.method === 'POST') |
11 | | - ) { |
12 | | - repeater.reset('webrequest', 1000); |
| 4 | + |
| 5 | +{ |
| 6 | + const observe = d => { |
| 7 | + if (d.tabId) { |
| 8 | + if ( |
| 9 | + d.type === 'main_frame' || |
| 10 | + d.url.includes('&act=') || |
| 11 | + (d.url.includes('/sync/u/') && d.method === 'POST') || |
| 12 | + (d.url.includes('/mail/u/') && d.method === 'POST') |
| 13 | + ) { |
| 14 | + repeater.reset('webrequest', 1000); |
| 15 | + } |
| 16 | + } |
| 17 | + }; |
| 18 | + |
| 19 | + const run = b => { |
| 20 | + chrome.webRequest.onCompleted.removeListener(observe); |
| 21 | + if (b) { |
| 22 | + chrome.webRequest.onCompleted.addListener(observe, { |
| 23 | + urls: [ |
| 24 | + '*://mail.google.com/mail/u*', |
| 25 | + '*://mail.google.com/sync/u/*/i/s*', |
| 26 | + '*://mail.google.com/mail/logout*' |
| 27 | + ]}, |
| 28 | + []); |
| 29 | + } |
| 30 | + }; |
| 31 | + |
| 32 | + chrome.storage.local.get({ |
| 33 | + 'network.watch': true |
| 34 | + }).then(prefs => { |
| 35 | + run(prefs['network.watch']); |
| 36 | + }); |
| 37 | + |
| 38 | + chrome.storage.onChanged.addListener(ps => { |
| 39 | + if ('network.watch' in ps) { |
| 40 | + run(ps['network.watch'].newValue); |
13 | 41 | } |
14 | | - } |
15 | | -}, { |
16 | | - urls: [ |
17 | | - '*://mail.google.com/mail/u*', |
18 | | - '*://mail.google.com/sync/u/*/i/s*', |
19 | | - '*://mail.google.com/mail/logout*' |
20 | | - ]}, |
21 | | -[]); |
| 42 | + }); |
| 43 | +} |
0 commit comments