Skip to content

Commit eca5dcf

Browse files
authored
Merge pull request #15 from namila007/popupfin
Popupfin
2 parents 59ba50c + 1300d5e commit eca5dcf

File tree

12 files changed

+7651
-54
lines changed

12 files changed

+7651
-54
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/.vscode

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Namila Bandara
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# StackZilla
2-
[email protected] Namila Bandara namila007 IA1
2+
3+
This is an firefox addon to connect and get notification of inbox and achievements from stackoverflow. To use this user have to add the addon and login through stackoverflow account.
4+
This will send notification popu if there is a new inbox or achievement unlocked. User also can check the latest inbox via popup

background/inboxInfo.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,37 @@ function notifyunread(count) {
55
"title": "Inbox",
66
"message": "You have "+count+" unread messages"
77
})
8-
}
8+
}
99

1010

1111

1212
function unreadmessages(token){
13-
var url = INBOX_READ+`&access_token=${token}`
14-
console.log(url)
13+
var url = INBOX_UNREAD+`&access_token=${token}`
1514

1615
return axios.get(url).then(res=>{
1716
console.log(totunread+" "+res.data.items.length )
1817
console.log(res.data)
19-
if(totunread < res.data.items.length )
18+
if(totunread <= res.data.items.length )
2019
{
2120
totunread = res.data.items.length
2221
console.log(totunread+" "+res.data.items.length )
2322
return Promise.resolve(res.data.items.length)
23+
}else{
24+
totunread = 0
2425
}
25-
if(totunread == res.data.items.length ){
26-
console.log(totunread+" "+res.data.items.length )
27-
return Promise.resolve(-1)
28-
}
29-
throw new Error('Error occured While fetching inbox data')
26+
//throw new Error('Error occured While fetching inbox data')
3027
})
3128

32-
}
29+
}
3330

31+
function inbox (token) {
32+
var url = INBOX+`&access_token=${token}`
3433

34+
return axios.get(url).then(res=>{
3535

36+
console.log(res.data.items.length)
37+
console.log("MSGS "+ res.data.items)
38+
return Promise.resolve(res.data.items)
39+
40+
})
41+
}

background/main.js

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33
var token
44
var totunread = 0
55
var 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+
1015
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+
1221

1322
//error noti
1423
function 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

4371
function 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(){
5684
function 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

manifest.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@
2222
"browser_action": {
2323
"default_icon": "icons/toolbar.png",
2424
"default_title": "StackZilla",
25-
"browser_style": true
25+
"browser_style": true,
26+
"default_popup": "popup/index.html"
2627
},
2728
"background": {
2829
"scripts": [
2930
"background/authorize.js",
3031
"background/main.js",
3132
"background/inboxInfo.js",
3233
"background/notificationInfo.js",
33-
"background/axios.js"
34-
34+
"background/axios.js"
3535
]
3636
},
3737

3838
"content_scripts": [
3939
{
4040
"matches": ["*://*/*"],
41-
"js": ["popup/stackpopup.js"]
41+
"js": ["popup/popup.js"]
4242
}
4343
],
4444
"options_ui": {

0 commit comments

Comments
 (0)