-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
28 lines (26 loc) · 900 Bytes
/
content.js
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
var notifCountResolver;
function resolveCountData(data) {
var resolve = notifCountResolver;
if (resolve) {
notifCountResolver = null;
resolve(data);
}
}
///From web page
window.addEventListener('message',
function (event) {
///3. resolve onMessage for chrome.tabs.sendMessage
if (event.data && event.data.type == 'quire.notifCount')
resolveCountData(event.data);
}, false);
///From ce
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (sender.id == 'fafnibnpfejgmleffgpnddkboddbipgm'
&& message.content == 'quire.notifCount.ask') {
resolveCountData(); //safer if [getNotifCountFromTabs] called twice
notifCountResolver = sendResponse;
///1. postMessage to pack.js
window.postMessage({type: 'quire.notifCount.ask'}, '*');
return true; // return true to indicate you want to send a response asynchronously
} else sendResponse(null);
});