-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.js
60 lines (52 loc) · 1.77 KB
/
page.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
window.chrome = (function () {
return window.msBrowser ||
window.browser ||
window.chrome;
})();
//var runtimeOrExtension = chrome.runtime && chrome.runtime.sendMessage ? 'runtime' : 'extension';
var inoLastResult = {};
function get_client_counters(force){
if (!document.getElementById('total_unread_cnt')){
if(chrome.runtime && chrome.runtime.sendMessage){
chrome.runtime.sendMessage(0);
}
return;
}
var result = {
"unread_cnt" : parseInt(document.getElementById('total_unread_cnt').innerHTML),
"logged_in" : parseInt(document.getElementById('logged_in_div').innerHTML),
"unseen_cnt" : parseInt(document.getElementById('total_unseen_cnt').innerHTML),
"max_cnt" : parseInt(document.getElementById('max_unread_cnt').innerHTML)
};
if(force == false && result.unread_cnt == inoLastResult.unread_cnt && result.unseen_cnt == inoLastResult.unseen_cnt){
return;
}
inoLastResult = result;
if(chrome.runtime && chrome.runtime.sendMessage){
chrome.runtime.sendMessage(result);
}
}
UpdateTimer = setInterval(function(){
get_client_counters(false);
}, 1000);
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if(request.action == 'force_counter_refresh'){
get_client_counters(true);
}
});
if(!document.getElementById('inoreader_companion_div')){
var dummy = document.createElement("a");
dummy.id = 'inoreader_companion_div';
document.body.appendChild(dummy);
}
window.addEventListener("message", function(event) {
if(event.source != window){
return;
}
if(event.data.request){
try{
chrome.runtime.sendMessage(event.data.request);
}catch(e){
}
}
}, false);