Skip to content

Commit ffc82a6

Browse files
committed
showing last 3 messages :laugh:
1 parent 048ccfc commit ffc82a6

8 files changed

Lines changed: 91 additions & 108 deletions

File tree

background/authorize.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
/* exported getAccessToken */
22

3-
// const REDIRECT_URL = browser.identity.getRedirectURL();
4-
// const CLIENT_ID = "12428";
53
const KEY = "f26RUH3uoCiokrEYNeDf9Q(("
6-
// const SCOPES = ["read_inbox", "noexpire"];
7-
// const AUTH_URL =
8-
// `https://stackoverflow.com/oauth/dialog?
9-
// client_id=${CLIENT_ID}&key=${KEY}&redirect_uri=${encodeURIComponent(REDIRECT_URL)}
10-
// &scope=${encodeURIComponent(SCOPES.join(' '))}`;
114

125
const VALIDATION_BASE_URL="https://api.stackexchange.com/2.2/";
136

@@ -19,18 +12,6 @@ function extractAccessToken(redirectUri) {
1912
return params.get("access_token");
2013
}
2114

22-
/**
23-
Validate the token contained in redirectURL.
24-
This follows essentially the process here:
25-
https://developers.google.com/identity/protocols/OAuth2UserAgent#tokeninfo-validation
26-
- make a GET request to the validation URL, including the access token
27-
- if the response is 200, and contains an "aud" property, and that property
28-
matches the clientID, then the response is valid
29-
- otherwise it is not valid
30-
31-
Note that the Google page talks about an "audience" property, but in fact
32-
it seems to be "aud".
33-
*/
3415
function validate(redirectURL) {
3516
const accessToken = extractAccessToken(redirectURL);
3617
console.log(accessToken + " access")

background/main.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
/*global getAccessToken*/
1+
/*main back to get th*/
22

33
var token
4-
// function notifyUser(user) {
5-
// browser.notifications.create({
6-
// "type": "basic",
7-
// "title": "Google info",
8-
// "message": `Hi ${user.name}`
9-
// });}
104

5+
const INBOX_READ =
6+
`https://api.stackexchange.com/2.2/me/inbox?page=1&pagesize=3&key=${KEY}&site=stackoverflow&filter=!LURAJLCc5nUZDmmWGEXuwH`
117

8+
//error log function
129
function logError(error) {
1310
console.error(`Error: ${error}`);
1411
}
@@ -20,14 +17,46 @@ function recivemessage (message,sender,sendResponse){
2017
console.log(message.data)
2118
token = validate(message.data).catch(logError).then((val)=>{
2219
console.log("val "+val)
20+
token = val;
2321
sendResponse({response: val})
2422

25-
})
23+
}).then(()=>{
24+
browser.notifications.create({
25+
"type": "basic",
26+
"title": "Token Created",
27+
"message": "Token is created"
28+
})
29+
},logError)
30+
return true
31+
}
32+
if(message.command == "inbox") {
33+
var url = INBOX_READ+`&access_token=${message.token}`
34+
var msg = get(url, (msg1)=>{
35+
console.log(msg1)
36+
sendResponse({response: msg1})
37+
})
38+
39+
40+
return true
41+
42+
}
2643

44+
function get(url, callback){
45+
var xmlHttp = new XMLHttpRequest();
46+
// xmlHttp.open( "GET", url, false ); // false for synchronous request
47+
// xmlHttp.send( null );
48+
// return xmlHttp.responseText;
49+
xmlHttp.onreadystatechange = function() {
50+
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
51+
callback(xmlHttp.responseText);
52+
}
53+
xmlHttp.open("GET", url, true); // true for asynchronous
54+
xmlHttp.send(null);
55+
}
2756

28-
return true
57+
// return true
2958

30-
}
59+
3160

3261
}
3362

background/userinfo.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

manifest.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "Eazy access for your StackOverflow account",
2+
"description": "Eazy access to your StackOverflow account",
33
"manifest_version": 2,
44
"name": "StackZilla",
55
"version": "1.0",
@@ -11,14 +11,12 @@
1111
"permissions": [
1212
"notifications",
1313
"identity",
14-
"tabs",
15-
"activeTab",
1614
"*://api.stackexchange.com/*",
1715
"*://*.stackoverflow.com/*"
1816
],
1917
"applications": {
2018
"gecko": {
21-
"id": "stackzilla1@mozilla.org"
19+
"id": "stackzilla2@mozilla.org"
2220
}
2321
},
2422
"browser_action": {
@@ -29,7 +27,6 @@
2927
"background": {
3028
"scripts": [
3129
"background/authorize.js",
32-
"background/userinfo.js",
3330
"background/main.js"
3431
]
3532
},

popup/css/bootstrap.min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

popup/index.css

Lines changed: 0 additions & 31 deletions
This file was deleted.

popup/index.html

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,30 @@
33
<html>
44
<head>
55
<meta charset="utf-8">
6-
<link rel="stylesheet" href="index.css"/>
7-
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://api.stackexchange.com">
8-
</head>
6+
<link rel="stylesheet" href="css/bootstrap.min.css"/>
7+
</head>
98

109
<body>
11-
<div id="popup-content row">
12-
<div class="token">
13-
<button type="button" id="tokenbtn">Get Token</button>
10+
<div class="container-fluid">
11+
<div id="popup-content row" class="row">
12+
<div class="col-sm col-md">
13+
<button type="button" class="btn btn-info small" id="tokenbtn">Get Token</button>
1414
</div>
15-
1615
<div class="token" id="token"></div>
17-
1816
<div class="col user">
19-
2017
</div>
21-
2218
</div>
23-
<div id="error-content" class="hidden">
24-
<p>Can't beastify this web page.</p><p>Try a different page.</p>
19+
20+
<div class="row" id="main_inbox" hidden>
21+
<button type="button" class="btn btn-primary" id="showinbox">
22+
Inbox <span class="badge badge-light" id="inboxcount"></span>
23+
<span class="sr-only">messages</span>
24+
</button>
25+
26+
<ul id="inbox" hidden></ul>
2527
</div>
2628

29+
</div>
2730

2831

2932
<script type='text/javascript' src="scripts/jquery-3.3.1.min.js"></script>

popup/stackpopup.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
const REDIRECT_URL = browser.identity.getRedirectURL();
55
const CLIENT_ID = "12428";
66
const KEY = "f26RUH3uoCiokrEYNeDf9Q(("
7-
const SCOPES = ["read_inbox", "noexpire"];
7+
const SCOPES = ["read_inbox"];
88
const AUTH_URL =
9-
`https://stackoverflow.com/oauth/dialog?client_id=${CLIENT_ID}&key=${KEY}&redirect_uri=${REDIRECT_URL}`;
10-
//&scope=${encodeURIComponent(SCOPES.join(' '))}`;
9+
`https://stackoverflow.com/oauth/dialog?client_id=${CLIENT_ID}&key=${KEY}&redirect_uri=${REDIRECT_URL}&scope=${encodeURIComponent(SCOPES.join(' '))}`;
1110

1211

1312
function handleResponse(message) {
14-
console.log(`background script sent a response: ${message.response}`);
13+
//console.log(`background script sent a response: ${message.response}`)
14+
getinbox(message.response)
15+
1516
}
1617

1718
function handleError(error) {
@@ -32,11 +33,32 @@ document.getElementById('tokenbtn').addEventListener("click", async function get
3233

3334
})
3435

35-
function tokenSet (req) {
36-
document.getElementById('token').innerHTML = req
36+
37+
function handleinbox(message) {
38+
console.log("Inbox")
3739

40+
let msg = JSON.parse(message.response)
41+
42+
43+
var inbox = document.getElementById("inbox")
44+
45+
for (var i=0; i<msg.items.length; i++){
46+
var item = document.createElement('li')
47+
item.innerHTML =
48+
'<a href="'+ msg.items[i].link +'">' + msg.items[i].title + '</a>'
49+
inbox.appendChild(item)
50+
}
51+
52+
3853
}
3954

55+
function getinbox(token) {
56+
var inbox = browser.runtime.sendMessage({
57+
command: "inbox",
58+
token: token
59+
})
60+
inbox.then(handleinbox,handleError)
61+
}
4062

4163

4264

0 commit comments

Comments
 (0)