@@ -44,17 +44,39 @@ function request_proxy({ url, method, data }) {
4444 } ;
4545}
4646
47+ const wbSpiderConfig = { } ;
48+
49+ chrome . storage . onChanged . addListener ( ( changes , namespace ) => {
50+ console . log ( 'change ======' ) ;
51+ for ( const [ key , { oldValue, newValue } ] of Object . entries ( changes ) ) {
52+ console . log ( 'change key' , key , newValue ) ;
53+ if ( key === 'wbSpider' || key === 'wbSpiderStart' ) {
54+ if ( key === 'wbSpider' ) {
55+ wbSpiderConfig . url = newValue ;
56+ } else if ( key === 'wbSpiderStart' ) {
57+ wbSpiderConfig . start = newValue ;
58+ }
59+ }
60+ console . log ( wbSpiderConfig ) ;
61+ }
62+ } ) ;
63+
4764chrome . runtime . onMessage . addListener ( ( data , sender , sendResponse ) => {
48- const url = 'http://127.0.0.1:8081/api/chrome-extension/save-spider?token=zhimin-studio-save-spider' ;
49- fetch ( url , {
50- method : 'POST' ,
51- body : JSON . stringify ( data ) ,
52- headers : {
53- 'Content-Type' : 'application/json;charset=UTF-8' ,
54- } ,
55- } ) . then ( ( resp ) => {
56- console . log ( resp ) ;
57- } ) ;
58- // request_proxy({ url, method: 'POST', data });
65+ if ( wbSpiderConfig . url !== '' && wbSpiderConfig . start ) {
66+ fetch ( wbSpiderConfig . url , {
67+ method : 'POST' ,
68+ body : JSON . stringify ( data ) ,
69+ headers : {
70+ 'Content-Type' : 'application/json;charset=UTF-8' ,
71+ } ,
72+ } ) . then ( ( resp ) => {
73+ console . log ( resp ) ;
74+ sendResponse ( { code : 200 } ) ;
75+ } )
76+ . catch ( ( err ) => {
77+ console . log ( err ) ;
78+ sendResponse ( { code : 500 } ) ;
79+ } ) ;
80+ }
5981 sendResponse ( { code : 200 } ) ;
6082} ) ;
0 commit comments