@@ -13,18 +13,56 @@ import './sentiment_analyzer.js';
1313import  './back_reocrder.js' ; 
1414// import '../common_files/poly_fill.js'; 
1515
16- /* Zeuz function start */ 
1716var  master  =  { } ; 
1817var  clickEnabled  =  true ; 
1918
20- /* Open panel */ 
19+ /* Create menu */ 
20+ function  create_menus ( )  { 
21+     let  menus  =  [ 
22+         [ "Go_to_link" ,  "Go to link" ] , 
23+         [ "Save_Text" ,  "Save Text" ] , 
24+         [ "Validate_Text" ,  "Validate Text" ] , 
25+         // ["Validate_Text_By_AI", "Validate Text by AI"], 
26+         [ "Wait_For_Element_To_Appear" ,  "Wait for Element to Appear" ] , 
27+         [ "Wait_For_Element_To_Disappear" ,  "Wait for Element to Disappear" ] , 
28+     ] 
29+     for ( let  i  = 0 ;  i <  menus . length ;  i ++ ) { 
30+         browserAppData . contextMenus . create ( { 
31+             id : menus [ i ] [ 0 ] , 
32+             title : menus [ i ] [ 1 ] , 
33+             documentUrlPatterns : [ 
34+                 "http://*/*" , 
35+                 "https://*/*" 
36+             ] , 
37+             contexts : [ "all" ] 
38+         } ) 
39+     } 
40+     browserAppData . runtime . sendMessage ( { 
41+         action : 'content_classify' , 
42+         text : "Hello world" , 
43+     } ) 
44+     . then ( ( ) => { 
45+         console . log ( "Classify init finished" ) ; 
46+         browserAppData . contextMenus . create ( { 
47+             id : "Validate_Text_By_AI" , 
48+             title : "Validate Text by AI" , 
49+             documentUrlPatterns : [ 
50+                 "http://*/*" , 
51+                 "https://*/*" 
52+             ] , 
53+             contexts : [ "all" ] 
54+         } ) 
55+     } ) ; 
56+ } 
57+ 
2158
22- // import {getWindowSize} from "/back_zeuz.js"; 
2359function  getWindowSize ( callback )  { 
24-     browserAppData . storage . local . get ( 'window' ,  function ( result )  { 
25-         var  height  =  740 ; 
26-         //var width = 780; 
27-         var  width  =  1110 ; 
60+     browserAppData . storage . local . get ( 'window' ,  async  function ( result )  { 
61+ 
62+         // var width = 1110; 
63+         var  win  =  await  chrome . windows . getCurrent ( ) ; 
64+         var  height  =  Math . round ( win . height * 0.9 ) ; 
65+         var  width  =  Math . round ( win . width * 0.6 ) ; 
2866        if  ( result )  { 
2967            try  { 
3068                result  =  result . window ; 
@@ -51,7 +89,7 @@ function open_panel(tab) {
5189        browserAppData . windows . update ( master [ contentWindowId ] ,  { 
5290            focused : true 
5391        } ) . catch ( function ( e )  { 
54-             master [ contentWindowId ]  ==   undefined ; 
92+             master [ contentWindowId ]  =  undefined ; 
5593            open_panel ( tab ) ; 
5694        } ) ; 
5795        return ; 
@@ -112,47 +150,97 @@ function open_panel(tab) {
112150    getWindowSize ( f ) ; 
113151} 
114152
115- /* Create menu */ 
116- function  create_menus ( )  { 
117-     let  menus  =  [ 
118-         [ "Go_to_link" ,  "Go to link" ] , 
119-         [ "Save_Text" ,  "Save Text" ] , 
120-         [ "Validate_Text" ,  "Validate Text" ] , 
121-         // ["Validate_Text_By_AI", "Validate Text by AI"], 
122-         [ "Wait_For_Element_To_Appear" ,  "Wait for Element to Appear" ] , 
123-         [ "Wait_For_Element_To_Disappear" ,  "Wait for Element to Disappear" ] , 
124-     ] 
125-     for ( let  i  = 0 ;  i <  menus . length ;  i ++ ) { 
126-         browserAppData . contextMenus . create ( { 
127-             id : menus [ i ] [ 0 ] , 
128-             title : menus [ i ] [ 1 ] , 
129-             documentUrlPatterns : [ 
130-                 "http://*/*" , 
131-                 "https://*/*" 
132-             ] , 
133-             contexts : [ "all" ] 
134-         } ) 
135-     } 
136-     browserAppData . runtime . sendMessage ( { 
137-         action : 'content_classify' , 
138-         text : "Hello world" , 
139-     } ) 
140-     . then ( ( ) => { 
141-         console . log ( "Classify init finished" ) ; 
142-         browserAppData . contextMenus . create ( { 
143-             id : "Validate_Text_By_AI" , 
144-             title : "Validate Text by AI" , 
145-             documentUrlPatterns : [ 
146-                 "http://*/*" , 
147-                 "https://*/*" 
148-             ] , 
149-             contexts : [ "all" ] 
150-         } ) 
153+ var  panelWindow ; 
154+ async  function  open_panel_2 ( tab )  { 
155+     browserAppData . storage . local . set ( { 
156+         meta_data : metaData , 
157+         recorded_actions : [ ] , 
151158    } ) ; 
152- } 
159+     let  contentWindowId  =  tab . windowId ; 
160+     console . log ( 'panelWindow' ,  panelWindow ) ; 
161+     var  result  =  await  browserAppData . storage . local . get ( [ 'panelWindow' ] ) ; 
162+     console . log ( 'result.panelWindow' ,  result . panelWindow ) ; 
163+     // console.log('result.panelWindow', result.panelWindow); 
164+ 
165+     if  ( result . panelWindow  &&  result . panelWindow [ contentWindowId ] )  { 
166+         browserAppData . windows . update ( result . panelWindow [ contentWindowId ] ,  { 
167+             focused : true 
168+         } ) . catch ( function ( e )  { 
169+             console . log ( 'panelWindow catch error' ,  panelWindow ) ; 
170+             console . error ( 'error' ,  e ) ; 
171+             var  panel_dict  =  result . panelWindow 
172+             panel_dict [ contentWindowId ]  =  undefined ; 
173+             panelWindow  =  undefined ; 
174+             browserAppData . storage . local . set ( { 
175+                 panelWindow : panel_dict 
176+             } ) . then ( open_panel ( tab ) ) ; 
177+         } ) ; 
178+         return ; 
179+     }  else  if  ( ! clickEnabled )  { 
180+         return ; 
181+     } 
182+ 
183+     clickEnabled  =  false ; 
184+     setTimeout ( function ( )  { 
185+         clickEnabled  =  true ; 
186+     } ,  1000 ) ; 
187+ 
188+     var  f  =  function ( height ,  width )  { 
189+         browserAppData . windows . create ( { 
190+             url : browserAppData . runtime . getURL ( "panel/index.html" ) , 
191+             type : "popup" , 
192+             //height: 705, 
193+             height : height , 
194+             //width: 1366 
195+             width : width 
196+         } ) . then ( function  waitForPanelLoaded ( panelWindowInfo )  { 
197+             return  new  Promise ( function ( resolve ,  reject )  { 
198+                 let  count  =  0 ; 
199+                 let  interval  =  setInterval ( function ( )  { 
200+                     if  ( count  >  100 )  { 
201+                         reject ( "editor has no response" ) ; 
202+                         clearInterval ( interval ) ; 
203+                     } 
153204
205+                     browserAppData . tabs . query ( { 
206+                         active : true , 
207+                         windowId : panelWindowInfo . id , 
208+                         status : "complete" 
209+                     } ) . then ( async  function ( tabs )  { 
210+                         if  ( tabs . length  !=  1 )  { 
211+                             count ++ ; 
212+                             return ; 
213+                         }  else  { 
214+                             var  result  =  await  browserAppData . storage . local . get ( [ 'panelWindow' ] ) ; 
215+                             if  ( result . panelWindow )  var  panel_dict  =  result . panelWindow ; 
216+                             else  var  panel_dict  =  { } ; 
217+                             panel_dict [ contentWindowId ]  =  panelWindowInfo . id ; 
218+                             await  browserAppData . storage . local . set ( { 
219+                                 panelWindow : panel_dict 
220+                             } ) ; 
221+                             console . log ( 'panel_dict' ,  panel_dict ) ; 
222+                             panelWindow  =  panelWindowInfo . id ; 
223+                             console . log ( 'opening panelWindow' ,  panelWindow ) ; 
224+                             create_menus ( ) ; 
225+                             resolve ( panelWindowInfo ) ; 
226+                             clearInterval ( interval ) ; 
227+                         } 
228+                     } ) 
229+                 } ,  200 ) ; 
230+             } ) ; 
231+         } ) . then ( function  bridge ( panelWindowInfo ) { 
232+             return  browserAppData . tabs . sendMessage ( panelWindowInfo . tabs [ 0 ] . id ,  { 
233+                 selfWindowId : panelWindowInfo . id , 
234+                 commWindowId : contentWindowId 
235+             } ) ; 
236+         } ) . catch ( function ( e )  { 
237+             console . log ( e ) ; 
238+         } ) ; 
239+     } ; 
240+     getWindowSize ( f ) ; 
241+ } 
154242
155- browserAppData . action . onClicked . addListener ( open_panel ) ; 
243+ browserAppData . action . onClicked . addListener ( open_panel_2 ) ; 
156244browserAppData . windows . onRemoved . addListener ( function ( windowId )  { 
157245    let  keys  =  Object . keys ( master ) ; 
158246    for  ( let  key  of  keys )  { 
@@ -181,3 +269,8 @@ browserAppData.runtime.onInstalled.addListener(function (details) {
181269        console . log ( "Recorder Installed" ) ; 
182270    } 
183271} ) ; 
272+ 
273+ var  i_am_running  =  0 ; 
274+ setInterval ( ( ) => { 
275+     i_am_running ++ ; 
276+ } , 200 ) 
0 commit comments