@@ -4,36 +4,44 @@ import store from './store'
4
4
5
5
// map to save id + url for checking if allready post
6
6
let domainsVisited = [ ]
7
+ let dataMap = new Map ( )
7
8
8
9
// send url to analyzer
9
- async function sendUrl ( url ) {
10
+ async function sendUrl ( url , domain ) {
11
+
12
+ //loading
13
+ store . commit ( 'SET_ISLOADING' , true ) ;
14
+
10
15
try {
11
16
await axios ( {
12
17
method : 'GET' ,
13
- url : `https://vue-telemetry.netlify.com/api/analyze?url=${ url } ` ,
18
+ url : `https://vue-telemetry.netlify.com/api/analyze?url=${ url } &src=extension ` ,
14
19
auth : {
15
20
username : 'nuxt-admin' ,
16
21
password : 'vue-telemetry-protected-area'
17
- }
22
+ } ,
18
23
} ) . then ( ( { data } ) => {
19
- store . dispatch ( 'setData' , data )
24
+ //not need tag meta
25
+ delete data . url
26
+ delete data . hostname
27
+ delete data . domain
28
+ delete data . screenshot
29
+ delete data . meta
30
+ dataMap . set ( domain , data )
31
+ store . commit ( 'SET_DATA' , dataMap )
20
32
} ) . catch ( ( err ) => {
21
- console . error ( err )
33
+ store . commit ( 'SET_CURRENTDOMAIN' , "WSError" )
22
34
} )
23
35
} catch ( e ) {
24
- console . error ( e )
36
+ store . commit ( 'SET_CURRENTDOMAIN' , "WSError" )
25
37
}
38
+ store . commit ( 'SET_ISLOADING' , false ) ;
26
39
}
27
40
28
- // when tab updated with new url
29
- async function handleUpdated ( tabId , changeInfo ) {
30
- if ( changeInfo . url ) {
31
- const { response } = await detectVue ( tabId )
32
- // check if not already analyzed
33
- if ( response . vueInfo . hasVue && ! domainsVisited . includes ( response . vueInfo . domain ) ) {
34
- domainsVisited . push ( response . vueInfo . domain )
35
- sendUrl ( changeInfo . url , tabId )
36
- }
41
+ // when tab updated
42
+ async function handleUpdated ( tabId , changeInfo , tabInfo ) {
43
+ if ( changeInfo . status == "complete" ) {
44
+ await detectVue ( tabId , tabInfo . url )
37
45
}
38
46
}
39
47
@@ -43,25 +51,64 @@ tabs.onUpdated.addListener(handleUpdated)
43
51
async function handleActivated ( ) {
44
52
// get active tab
45
53
tabs . query ( { currentWindow : true , active : true } ) . then ( async function ( tabsArray ) {
46
-
47
- const { response } = await detectVue ( tabsArray [ 0 ] . id )
48
- // check if not already analyzed
49
- if ( response . vueInfo . hasVue && ! domainsVisited . includes ( response . vueInfo . domain ) ) {
50
- domainsVisited . push ( response . vueInfo . domain )
51
- sendUrl ( tabsArray [ 0 ] . url , tabsArray [ 0 ] . id )
52
- }
54
+ await detectVue ( tabsArray [ 0 ] . id , tabsArray [ 0 ] . url )
53
55
} )
54
56
}
55
57
56
58
tabs . onActivated . addListener ( handleActivated )
57
59
58
- function detectVue ( tabId ) {
60
+ //function to detect vue and send url
61
+ async function detectVue ( tabId , url ) {
62
+
63
+ store . commit ( 'SET_CURRENTDOMAIN' , 'noVue' )
64
+
65
+ //Check vue
66
+ await hasVue ( tabId ) . then ( ( { response } ) => {
67
+
68
+ //set store current domain
69
+
70
+ if ( response . vueInfo . hasVue ) {
71
+
72
+ store . commit ( 'SET_CURRENTDOMAIN' , response . vueInfo . domain )
73
+
74
+ browser . browserAction . setIcon ( {
75
+ tabId : tabId ,
76
+ path : {
77
+ 16 : `icons/icon-nuxtjs.png` ,
78
+ 48 : `icons/icon-nuxtjs.png` ,
79
+ 128 : `icons/icon-nuxtjs.png`
80
+ }
81
+ } )
82
+ }
83
+
84
+ // if not already analyzed
85
+ if ( ! domainsVisited . includes ( response . vueInfo . domain ) ) {
86
+
87
+ domainsVisited . push ( response . vueInfo . domain )
88
+
89
+ //send url and change icon extension
90
+ if ( response . vueInfo . hasVue ) {
91
+ sendUrl ( url , response . vueInfo . domain )
92
+ }
93
+ }
94
+
95
+ return response . vueInfo . hasVue ;
96
+
97
+ } ) . catch ( ( err ) => {
98
+ //set store current domain to error
99
+ store . commit ( 'SET_CURRENTDOMAIN' , "noVUe" )
100
+ return false ;
101
+ } )
102
+ }
103
+
104
+ //check vue in detector.js and get response
105
+ function hasVue ( tabId ) {
59
106
return new Promise ( resolve => {
60
107
browser . tabs . sendMessage (
61
108
tabId ,
62
109
{ greeting : '' }
63
- ) . then ( response => {
64
- resolve ( response )
65
- } )
110
+ ) . then ( response => {
111
+ resolve ( response )
66
112
} )
67
- }
113
+ } )
114
+ }
0 commit comments