1
- const temp_requests = [ ] ;
1
+ let temp_requests = [ ] ;
2
2
let timer = null ;
3
3
4
4
/**
@@ -15,41 +15,44 @@ function requestCallback(info) {
15
15
if ( ! temp_requests . length ) return ;
16
16
//拷贝数据
17
17
const temp_requests_clone = JSON . parse ( JSON . stringify ( temp_requests ) ) ;
18
+ temp_requests = [ ] ;
18
19
19
20
//处理数据
20
21
chrome . storage . local . get ( [ "tabs_request" ] ) . then ( ( storage ) => {
21
22
let storageTabs = storage [ "tabs_request" ] || { } ;
22
23
23
24
Promise . all (
24
- temp_requests_clone . map ( ( el ) =>
25
- chrome . tabs . get ( el . tabId ) . then ( ( tab ) => {
25
+ temp_requests_clone . map ( ( el ) => {
26
+ console . log ( "-----el" , el ) ;
27
+ return chrome . tabs . get ( el . tabId ) . then ( ( tab ) => {
26
28
return {
27
29
name : tab . title ,
28
30
icon : tab . favIconUrl ,
29
31
id : tab . id ,
30
32
requests : [ ] ,
31
33
} ;
32
- } )
33
- )
34
+ } ) ;
35
+ } )
34
36
)
35
- . then ( ( tabs , index ) => {
36
- const details = temp_requests_clone [ index ] ;
37
+ . then ( ( tabs ) => {
38
+ tabs . forEach ( ( tab , index ) => {
39
+ const details = temp_requests_clone [ index ] ;
37
40
38
- let tabInfo =
39
- storageTabs [ details . tabId ] || tabs . find ( ( el ) => el . id == details . tabId ) ;
41
+ let tabInfo = storageTabs [ details . tabId ] || tab ;
40
42
41
- if ( ! tabInfo . requests . find ( ( el ) => el . url == details . url ) ) {
42
- let fileName = "" ,
43
- pathArray = new URL ( details . url ) . pathname . split ( "/" ) ;
44
- while ( ! fileName ) {
45
- fileName = pathArray . pop ( ) ;
46
- }
47
- details . name = fileName ;
43
+ if ( ! tabInfo . requests . find ( ( el ) => el . url == details . url ) ) {
44
+ let fileName = "" ,
45
+ pathArray = new URL ( details . url ) . pathname . split ( "/" ) ;
46
+ while ( ! fileName ) {
47
+ fileName = pathArray . pop ( ) ;
48
+ }
49
+ details . name = fileName ;
48
50
49
- tabInfo . requests . push ( details ) ;
50
- }
51
+ tabInfo . requests . push ( details ) ;
52
+ }
51
53
52
- storageTabs [ details . tabId ] = tabInfo ;
54
+ storageTabs [ details . tabId ] = tabInfo ;
55
+ } ) ;
53
56
} )
54
57
. finally ( ( ) => {
55
58
storage [ "tabs_request" ] = storageTabs ;
@@ -72,7 +75,7 @@ function onWatchRequest(types) {
72
75
73
76
chrome . webRequest . onBeforeRequest . addListener (
74
77
requestCallback ,
75
- { urls : [ "<all_urls> " ] , types } ,
78
+ { urls : [ "http://*/*" , "https://*/* "] , types } ,
76
79
[ ]
77
80
) ;
78
81
}
0 commit comments