3
3
var token
4
4
var totunread = 0
5
5
var notiunread = 0
6
+ var interval ;
6
7
7
- const INBOX_READ =
8
+ const INBOX_UNREAD =
8
9
`https://api.stackexchange.com/2.2/me/inbox/unread?key=${ KEY } &site=stackoverflow&filter=!0UscT51V)r-XJhlOHzduuQu)O`
9
10
11
+ const INBOX =
12
+ `https://api.stackexchange.com/2.2/me/inbox?key=${ KEY } &site=stackoverflow&pagesize=5&filter=!8IfPpxGro.Z6_M(hOhkHW`
13
+
14
+
10
15
const NOTIFICATIONS =
11
- `https://api.stackexchange.com/2.2/me/reputation?site=stackoverflow&key=${ KEY } `
16
+ `https://api.stackexchange.com/2.2/me/notifications/unread?site=stackoverflow&key=${ KEY } &pagesize=5&filter=!w*yCRQ_T5l9PdmgVXW`
17
+
18
+ const BADGEUPDATES =
19
+ `https://api.stackexchange.com/2.2/me/notifications?site=stackoverflow&key=${ KEY } &pagesize=5&filter=!w*yCRQ_T5l9PdmgVXW`
20
+
12
21
13
22
//error noti
14
23
function notifyerror ( error ) {
@@ -29,19 +38,38 @@ function logError(error) {
29
38
//notifyerror(error)
30
39
}
31
40
41
+ async function messageHandle ( request , sender , sendResponse ) {
42
+ if ( request . command == "getToken" ) {
43
+ console . log ( "CLICKED" )
44
+ token = await getAccessToken ( )
45
+ console . log ( "tok " + token )
46
+ unreadnotificatons ( token ) . then ( notifynotiunread ) . catch ( logError )
47
+ unreadmessages ( token ) . then ( notifyunread ) . catch ( logError )
48
+ badge ( )
49
+ clearInterval ( interval )
50
+ startInterval ( )
51
+ inbox ( token ) . then ( res => {
52
+ console . log ( "mmmm " + res )
53
+ sendResponse ( { data : res } )
54
+ } )
55
+ }
56
+ return true
57
+
58
+
59
+ }
32
60
33
- browser . browserAction . onClicked . addListener ( async function ( ) {
34
- console . log ( "CLICKED" )
35
- token = await getAccessToken ( )
36
- console . log ( "tok " + token )
37
- unreadnotificatons ( token ) . then ( notifynotiunread ) . catch ( logError )
38
- unreadmessages ( token ) . then ( notifyunread ) . catch ( logError )
39
- badge ( )
40
- startInterval ( )
41
- } )
61
+ // browser.browserAction.onClicked.addListener(async function() {
62
+ // console.log("CLICKED")
63
+ // token = await getAccessToken()
64
+ // console.log("tok "+token)
65
+ // unreadnotificatons(token).then(notifynotiunread).catch(logError)
66
+ // unreadmessages(token).then(notifyunread).catch(logError)
67
+ // badge()
68
+ // startInterval()
69
+ // })
42
70
43
71
function startInterval ( ) {
44
- var interval = setInterval ( function ( ) {
72
+ interval = setInterval ( function ( ) {
45
73
unreadnotificatons ( token )
46
74
. then ( ( val ) => {
47
75
if ( val != - 1 ) { notifynotiunread } } )
@@ -56,8 +84,10 @@ var interval = setInterval(function(){
56
84
function badge ( ) {
57
85
if ( ( totunread + notiunread ) > 0 )
58
86
{
59
- browser . browserAction . setBadgeText ( { text : ( totunread + notiunread ) . toString ( ) } ) ;
87
+ browser . browserAction . setBadgeText ( { text : ( totunread ) . toString ( ) } ) ;
60
88
}
61
89
}
62
90
91
+ browser . runtime . onMessage . addListener ( messageHandle ) ;
92
+
63
93
0 commit comments