1- /*global getAccessToken */
1+ /*main back to get th */
22
33var 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
129function 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
0 commit comments