@@ -8,6 +8,7 @@ export const BACKGROUND_COLOR_END = 'rgba(85, 127, 243, 0.25)';
88export  const  OVERLAY_ID  =  'ddg-password-import-overlay' ; 
99export  const  DELAY_BEFORE_ANIMATION  =  300 ; 
1010const  BOOKMARK_IMPORT_DOMAIN  =  'takeout.google.com' ; 
11+ const  TAKEOUT_DOWNLOAD_URL_BASE  =  '/takeout/download' ; 
1112
1213/** 
1314 * @typedef  ButtonAnimationStyle 
@@ -52,7 +53,7 @@ export default class AutofillPasswordImport extends ContentFeature {
5253
5354    #domLoaded; 
5455
55-     #currentLocation ; 
56+     #exportId ; 
5657
5758    #isBookmarkModalVisible =  false ; 
5859    #isBookmarkProcessed =  false ; 
@@ -427,16 +428,30 @@ export default class AutofillPasswordImport extends ContentFeature {
427428        } 
428429    } 
429430
431+     async  downloadData ( )  { 
432+         const  userId  =  document . querySelector ( 'a[href*="&user="]' ) ?. getAttribute ( 'href' ) ?. split ( '&user=' ) [ 1 ] ; 
433+         console . log ( 'DEEP DEBUG autofill-password-import: userId' ,  userId ) ; 
434+         await  withExponentialBackoff ( ( )  =>  document . querySelector ( `a[href="./manage/archive/${ this . #exportId}  "]` ) ,  8 ) ; 
435+         const  downloadURL  =  `${ TAKEOUT_DOWNLOAD_URL_BASE }  ?j=${ this . #exportId}  &i=0&user=${ userId }  ` ; 
436+         window . location . href  =  downloadURL ; 
437+     } 
438+ 
430439    async  handleBookmarkImportPath ( pathname )  { 
431440        console . log ( 'DEEP DEBUG autofill-password-import: handleBookmarkImportPath' ,  pathname ) ; 
432441        if  ( pathname  ===  '/'  &&  ! this . #isBookmarkModalVisible)  { 
433442            await  this . clickDisselectAllButton ( ) ; 
434443            await  this . selectBookmark ( ) ; 
444+             this . startExportProcess ( ) ; 
445+             await  this . storeExportId ( ) ; 
446+             const  manageButton  =  /** @type  HTMLAnchorElement */  ( document . querySelector ( 'a[href="manage"]' ) ) ; 
447+             manageButton ?. click ( ) ; 
448+             await  this . downloadData ( ) ; 
435449        } 
436450    } 
437451
438452    /** 
439453     * @param  {Location } location 
454+      * 
440455     */ 
441456    async  handleLocation ( location )  { 
442457        const  {  pathname,  hostname }  =  location ; 
@@ -541,15 +556,43 @@ export default class AutofillPasswordImport extends ContentFeature {
541556    async  findDisselectAllButton ( )  { 
542557        return  await  withExponentialBackoff ( ( )  =>  document . querySelectorAll ( this . disselectAllButtonSelector ) [ 1 ] ) ; 
543558    } 
559+ 
560+     async  findExportId ( )  { 
561+         const  panels  =  document . querySelectorAll ( 'div[role="tabpanel"]' ) ; 
562+         const  exportPanel  =  panels [ panels . length  -  1 ] ; 
563+         return  await  withExponentialBackoff ( ( )  =>  exportPanel . querySelector ( 'div[data-archive-id]' ) ?. getAttribute ( 'data-archive-id' ) ) ; 
564+     } 
565+ 
566+     async  storeExportId ( )  { 
567+         this . #exportId =  await  this . findExportId ( ) ; 
568+         console . log ( 'DEEP DEBUG autofill-password-import: stored export id' ,  this . #exportId) ; 
569+     } 
570+ 
571+     startExportProcess ( )  { 
572+         const  nextStepButton  =  /** @type  HTMLButtonElement */  ( document . querySelectorAll ( this . nextStepButtonSelector ) [ 0 ] ) ; 
573+         nextStepButton ?. scrollIntoView ( {  behavior : 'smooth' ,  block : 'center' ,  inline : 'center'  } ) ; 
574+         nextStepButton ?. click ( ) ; 
575+ 
576+         const  createExportButton  =  /** @type  HTMLButtonElement */  ( document . querySelectorAll ( this . createExportButtonSelector ) [ 0 ] ) ; 
577+         createExportButton ?. scrollIntoView ( {  behavior : 'smooth' ,  block : 'center' ,  inline : 'center'  } ) ; 
578+         createExportButton ?. click ( ) ; 
579+     } 
580+ 
544581    async  selectBookmark ( )  { 
545582        if  ( this . #isBookmarkProcessed)  { 
546583            return ; 
547584        } 
548585        const  chromeDataButtonSelector  =  `${ this . chromeSectionSelector }   button` ; 
549586        const  chromeDataButton  =  /** @type  HTMLButtonElement */  ( 
550-             await  withExponentialBackoff ( ( )  =>  document . querySelectorAll ( chromeDataButtonSelector ) [ 1 ] ,  5 ) 
587+             await  withExponentialBackoff ( ( )  =>  { 
588+                 const  button  =  /** @type  HTMLButtonElement */  ( document . querySelectorAll ( chromeDataButtonSelector ) [ 1 ] ) ; 
589+                 if  ( button . checkVisibility ( ) )  { 
590+                     return  button ; 
591+                 } 
592+                 return  null ; 
593+             } ) 
551594        ) ; 
552-         chromeDataButton ?. focus ( ) ; 
595+         console . log ( chromeDataButton ) ; 
553596        chromeDataButton ?. click ( ) ; 
554597        this . #isBookmarkModalVisible =  true ; 
555598        await  this . domLoaded ; 
@@ -570,18 +613,10 @@ export default class AutofillPasswordImport extends ContentFeature {
570613        const  okButton  =  /** @type  HTMLButtonElement */  ( document . querySelectorAll ( 'div[role="button"]' ) [ 7 ] ) ; 
571614
572615        await  withExponentialBackoff ( ( )  =>  okButton . ariaDisabled  !==  'true' ) ; 
573-          
616+ 
574617        okButton ?. click ( ) ; 
575618        this . #isBookmarkModalVisible =  false ; 
576619        this . #isBookmarkProcessed =  true ; 
577- 
578-         const  nextStepButton  =  /** @type  HTMLButtonElement */  ( document . querySelectorAll ( this . nextStepButtonSelector ) [ 0 ] ) ; 
579-         nextStepButton ?. scrollIntoView ( {  behavior : 'smooth' ,  block : 'center' ,  inline : 'center'  } ) ; 
580-         nextStepButton ?. click ( ) ; 
581- 
582-         const  createExportButton  =  /** @type  HTMLButtonElement */  ( document . querySelectorAll ( this . createExportButtonSelector ) [ 0 ] ) ; 
583-         createExportButton ?. scrollIntoView ( {  behavior : 'smooth' ,  block : 'center' ,  inline : 'center'  } ) ; 
584-         createExportButton ?. click ( ) ; 
585620    } 
586621
587622    async  clickDisselectAllButton ( )  { 
0 commit comments