33var token
44var totunread = 0
55var notiunread = 0
6+ var interval ;
67
7- const INBOX_READ =
8+ const INBOX_UNREAD =
89`https://api.stackexchange.com/2.2/me/inbox/unread?key=${ KEY } &site=stackoverflow&filter=!0UscT51V)r-XJhlOHzduuQu)O`
910
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+
1015const 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+
1221
1322//error noti
1423function notifyerror ( error ) {
@@ -29,19 +38,38 @@ function logError(error) {
2938 //notifyerror(error)
3039}
3140
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+ }
3260
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+ // })
4270
4371function startInterval ( ) {
44- var interval = setInterval ( function ( ) {
72+ interval = setInterval ( function ( ) {
4573 unreadnotificatons ( token )
4674 . then ( ( val ) => {
4775 if ( val != - 1 ) { notifynotiunread } } )
@@ -56,8 +84,10 @@ var interval = setInterval(function(){
5684function badge ( ) {
5785 if ( ( totunread + notiunread ) > 0 )
5886 {
59- browser . browserAction . setBadgeText ( { text : ( totunread + notiunread ) . toString ( ) } ) ;
87+ browser . browserAction . setBadgeText ( { text : ( totunread ) . toString ( ) } ) ;
6088 }
6189}
6290
91+ browser . runtime . onMessage . addListener ( messageHandle ) ;
92+
6393
0 commit comments