@@ -3,20 +3,31 @@ const tabs = {};
33const  inspectFile  =  'inspect.js' ; 
44const  activeIcon  =  'active-64.png' ; 
55const  defaultIcon  =  'small_logo.png' ; 
6- let  zeuz_url  =  '__ZeuZ__UrL_maPP' ; 
7- let  zeuz_key  =  '__ZeuZ__KeY_maPP' ; 
6+ var  zeuz_url ; 
7+ var  zeuz_key ; 
8+ 
9+ fetch ( "data.json" ) 
10+     . then ( Response  =>  Response . json ( ) ) 
11+     . then ( data  =>  { 
12+         zeuz_url  =  data . zeuz_url ; 
13+         zeuz_key  =  data . zeuz_key ; 
14+         console . log ( data ) ; 
15+         console . log ( zeuz_url ) ; 
16+         console . log ( zeuz_key ) ; 
17+         browserAppData . storage . local . set ( { 
18+             url : zeuz_url , 
19+             key : zeuz_key , 
20+         } , 
21+         function ( )  { 
22+             console . log ( "Logged in successfully!" ) ; 
23+         } ) ; 
24+     } ) ; 
825
926function  logout ( )  { 
1027    browserAppData . storage . local . remove ( [ 'key' ] ,  function ( )  { 
1128        alert ( "Logged out successfully!" ) ; 
1229    } ) ; 
1330} 
14- browserAppData . contextMenus . create ( { 
15-     title : "Logout" , 
16-     contexts : [ "all" ] , 
17-     // onclick: logout, 
18-     id : "zeuz_inspector" 
19- } ) ; 
2031
2132browserAppData . contextMenus . onClicked . addListener ( logout ) ; 
2233
@@ -66,123 +77,11 @@ function toggle(tab) {
6677
6778    if  ( ! isSupportedProtocolAndFileType ( tab . url ) )  return ; 
6879
69-     if  ( ! tabs [ tab . id ] )  { 
70-         // tabs[tab.id] = Object.create(inspect); 
71-         // inspect.toggleActivate(tab.id, 'activate', activeIcon); 
72- 
73-         // check key exists 
74-         browserAppData . storage . local . get ( [ 'key' ] ,  function ( result )  { 
75-             // console.log('Value currently is ' + result.key); 
76- 
77-             if  ( result . key  !=  null )  { 
78-                 // activate 
79-                 tabs [ tab . id ]  =  Object . create ( inspect ) ; 
80-                 inspect . toggleActivate ( tab . id ,  'activate' ,  activeIcon ) ; 
81-             }  else  { 
82-                 if  ( zeuz_url . startsWith ( '__ZeuZ__UrL_maP' ) ) 
83-                     var  server_url  =  prompt ( "Please enter your ZeuZ server address" ,  "" ) ; 
84-                 else 
85-                     var  server_url  =  zeuz_url ; 
86-                 if  ( zeuz_key . startsWith ( '__ZeuZ__KeY_maP' ) ) 
87-                     var  api_key  =  prompt ( "Please enter your API key" ,  "" ) ; 
88-                 else 
89-                     var  api_key  =  zeuz_key ; 
90- 
91-                 var  verify_status ; 
92-                 var  verify_token ; 
93- 
94-                 if  ( server_url  !=  null  &&  api_key  !=  null )  { 
95- 
96-                     //process the url 
97- 
98-                     var  lastChar  =  server_url . substr ( server_url . length  -  1 ) ; 
99-                     if  ( lastChar  ==  "/" )  { 
100-                         server_url  =  server_url . slice ( 0 ,  - 1 ) ;  // remove last char '/' 
101-                     } 
102- 
103-                     if  ( server_url . startsWith ( "http" )  ==  false )  { 
104- 
105-                         if  ( ( server_url . indexOf ( "localhost" )  !=  - 1 )  ||  ( server_url . indexOf ( "127.0.0.1" )  !=  - 1 )  ||  ( server_url . indexOf ( "0.0.0.0" )  !=  - 1 ) )  { 
106-                             server_url  =  "http://"  +  server_url ;  // add http:// in the beginning       
107-                         }  else  { 
108-                             server_url  =  "https://"  +  server_url ;  // add http:// in the beginning 
109-                         } 
110- 
111-                     } 
112- 
113-                     if  ( zeuz_key . startsWith ( '__ZeuZ__KeY_maP' ) )  { 
114-                         var  xhr  =  new  XMLHttpRequest ( ) ; 
115-                         xhr . withCredentials  =  true ; 
116-                         xhr . addEventListener ( "readystatechange" ,  function ( )  { 
117-                             if  ( this . readyState  ===  4 )  { 
118-                                 console . log ( this . responseText ) ; 
119- 
120-                                 verify_status  =  this . status ; 
121-                                 verify_token  =  this . responseText ; 
122- 
123-                                 // show message for verification 
124-                                 if  ( verify_status  ===  200 )  { 
125- 
126-                                     if  ( verify_token  ===  null )  { 
127-                                         alert ( "Sorry! Api key is wrong." ) ; 
128-                                     }  else  { 
129-                                         // save server url and api key 
130-                                         // browserAppData.storage.local.set({ url: server_url ,key: api_key }, function () { 
131-                                         browserAppData . storage . local . set ( { 
132-                                                 url : server_url , 
133-                                                 key : JSON . parse ( this . responseText ) . token 
134-                                             } , 
135-                                             function ( )  { 
136-                                                 console . log ( 'Value is set to ' ,  server_url ,  this . responseText ) ; 
137-                                                 if  ( zeuz_url . startsWith ( '__ZeuZ__UrL_maP' ) ) 
138-                                                     alert ( "Logged in successfully!" ) ; 
139-                                                 else 
140-                                                     console . log ( "Logged in successfully!" ) ; 
141-                                             } ) ; 
142- 
143-                                         // activate plugin 
144-                                         tabs [ tab . id ]  =  Object . create ( inspect ) ; 
145-                                         inspect . toggleActivate ( tab . id ,  'activate' ,  activeIcon ) ; 
146-                                     } 
147- 
148-                                 }  else  if  ( ( verify_status  ===  403 )  ||  ( verify_status  ===  0 ) )  { 
149-                                     alert ( "Sorry! Server URL is incorrect." ) ; 
150-                                 }  else  if  ( verify_status  ===  404 )  { 
151-                                     alert ( "Sorry! Api key is incorrect." ) ; 
152-                                 }  else  { 
153-                                     alert ( "Sorry! Server url/key is incorrect." ) ; 
154-                                 } 
155- 
156- 
157-                             } 
158-                         } ) ; 
159-                         xhr . open ( "GET" ,  server_url  +  "/api/auth/token/verify?api_key="  +  api_key ) ; 
160-                         xhr . send ( ) ; 
161-                     }  else  { 
162-                         browserAppData . storage . local . set ( { 
163-                                 url : server_url , 
164-                                 key : zeuz_key , 
165-                             } , 
166-                             function ( )  { 
167-                                 console . log ( "Logged in successfully!" ) ; 
168-                             } ) ; 
169- 
170-                         // activate plugin 
171-                         tabs [ tab . id ]  =  Object . create ( inspect ) ; 
172-                         inspect . toggleActivate ( tab . id ,  'activate' ,  activeIcon ) ; 
173-                     } 
174- 
175- 
176-                 }  else  { 
177-                     alert ( "Sorry! Server url/key cannot be empty." ) ; 
178-                 } 
179- 
180-             } 
181- 
182-         } ) ; 
183- 
184- 
185-     }  else  { 
80+     if  ( ! tabs [ tab . id ] ) { 
81+         tabs [ tab . id ]  =  Object . create ( inspect ) ; 
82+         inspect . toggleActivate ( tab . id ,  'activate' ,  activeIcon ) ; 
83+     } 
84+     else  { 
18685        // deactivate plugin 
18786        inspect . toggleActivate ( tab . id ,  'deactivate' ,  defaultIcon ) ; 
18887        for  ( const  tabId  in  tabs )  { 
@@ -238,7 +137,7 @@ browserAppData.runtime.onMessage.addListener(
238137    function ( request ,  sender ,  sendResponse )  { 
239138      if  ( request . apiName  ==  'ai_record_single_action' )  { 
240139        var  url  =  `${ zeuz_url }  
241- 
140+          console . log ( "zeuz_key" ,   zeuz_key ) 
242141        fetch ( url ,  { 
243142            method : "POST" , 
244143            headers : { 
0 commit comments