|
1 | 1 | /*main back to get th*/ |
2 | 2 |
|
3 | 3 | var token |
| 4 | +var totunread = -1 |
| 5 | +var notiunread = -1 |
4 | 6 |
|
5 | 7 | const INBOX_READ = |
6 | | -`https://api.stackexchange.com/2.2/me/inbox?page=1&pagesize=5&key=${KEY}&site=stackoverflow&filter=!LURAJLCc5n-3UL-M6AmXYq` |
| 8 | +`https://api.stackexchange.com/2.2/me/inbox/unread?page=1&pagesize=5&key=${KEY}&site=stackoverflow&filter=!0UscT51V)r-XK9Kg9bV54nqom` |
| 9 | + |
| 10 | +const NOTIFICATIONS = |
| 11 | +`https://api.stackexchange.com/2.2/me/notifications/unread?page=1&pagesize=2&site=stackoverflow&filter=!0UscT5320P8DSPTPhCF)1tNYL&key=${KEY}` |
7 | 12 |
|
8 | 13 | //error log function |
9 | 14 | function logError(error) { |
10 | 15 | console.error(`Error: ${error}`); |
11 | 16 | } |
12 | 17 |
|
13 | | -browser.runtime.onMessage.addListener(recivemessage) |
14 | | - |
15 | | -function recivemessage (message,sender,sendResponse){ |
16 | | - if(message.command === "tokenurl"){ |
17 | | - console.log(message.data) |
18 | | - token = validate(message.data).catch(logError).then((val)=>{ |
19 | | - console.log("val "+val) |
20 | | - token = val; |
21 | | - sendResponse({response: val}) |
22 | | - |
23 | | - }).then(()=>{ |
24 | | - browser.notifications.create({ |
25 | | - "type": "basic", |
26 | | - "iconUrl": browser.extension.getURL("icons/addon.png"), |
27 | | - "title": "Token Created", |
28 | | - "message": "Token is created" |
29 | | - }) |
30 | | - },logError) |
31 | | - return true |
32 | | - } |
33 | | - if(message.command == "inbox") { |
34 | | - var url = INBOX_READ+`&access_token=${message.token}` |
35 | | - get(url, (msg1)=>{ |
36 | | - //console.log(msg1) |
37 | | - |
38 | | - sendResponse({response: msg1}) |
39 | | - }) |
40 | | - |
41 | | - } |
42 | | - |
43 | | - |
44 | | - return true |
45 | | - |
46 | | - } |
47 | | - |
48 | | - function get(url, callback){ |
49 | | - var xmlHttp = new XMLHttpRequest(); |
50 | | - xmlHttp.onreadystatechange = function() { |
51 | | - if (xmlHttp.readyState == 4 && xmlHttp.status == 200) |
52 | | - callback(xmlHttp.responseText); |
53 | | - } |
54 | | - xmlHttp.open("GET", url, true); // true for asynchronous |
55 | | - xmlHttp.send(null); |
| 18 | +function get(url, callback){ |
| 19 | + var xmlHttp = new XMLHttpRequest(); |
| 20 | + xmlHttp.onreadystatechange = function() { |
| 21 | + if (xmlHttp.readyState == 4 && xmlHttp.status == 200) |
| 22 | + callback(xmlHttp.responseText); |
56 | 23 | } |
57 | | - |
58 | | - // return true |
59 | | - |
| 24 | + xmlHttp.open("GET", url, true); // true for asynchronous |
| 25 | + xmlHttp.send(null); |
| 26 | +} |
| 27 | + |
| 28 | +browser.browserAction.onClicked.addListener(async function() { |
| 29 | + console.log("CLICKED") |
| 30 | + token = await getAccessToken() |
| 31 | + console.log("tok "+token) |
| 32 | + unreadnotificatons(token).catch(logError) |
| 33 | + unreadmessages(token).then((data)=>{console.log(data)}).catch(logError) |
| 34 | + |
| 35 | +}) |
| 36 | + |
| 37 | + |
| 38 | + |
60 | 39 |
|
61 | 40 |
|
62 | 41 |
|
0 commit comments