@@ -8,6 +8,7 @@ export const BACKGROUND_COLOR_END = 'rgba(85, 127, 243, 0.25)';
8
8
export const OVERLAY_ID = 'ddg-password-import-overlay' ;
9
9
export const DELAY_BEFORE_ANIMATION = 300 ;
10
10
const BOOKMARK_IMPORT_DOMAIN = 'takeout.google.com' ;
11
+ const TAKEOUT_DOWNLOAD_URL_BASE = '/takeout/download' ;
11
12
12
13
/**
13
14
* @typedef ButtonAnimationStyle
@@ -52,7 +53,7 @@ export default class AutofillPasswordImport extends ContentFeature {
52
53
53
54
#domLoaded;
54
55
55
- #currentLocation ;
56
+ #exportId ;
56
57
57
58
#isBookmarkModalVisible = false ;
58
59
#isBookmarkProcessed = false ;
@@ -427,16 +428,30 @@ export default class AutofillPasswordImport extends ContentFeature {
427
428
}
428
429
}
429
430
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
+
430
439
async handleBookmarkImportPath ( pathname ) {
431
440
console . log ( 'DEEP DEBUG autofill-password-import: handleBookmarkImportPath' , pathname ) ;
432
441
if ( pathname === '/' && ! this . #isBookmarkModalVisible) {
433
442
await this . clickDisselectAllButton ( ) ;
434
443
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 ( ) ;
435
449
}
436
450
}
437
451
438
452
/**
439
453
* @param {Location } location
454
+ *
440
455
*/
441
456
async handleLocation ( location ) {
442
457
const { pathname, hostname } = location ;
@@ -541,6 +556,28 @@ export default class AutofillPasswordImport extends ContentFeature {
541
556
async findDisselectAllButton ( ) {
542
557
return await withExponentialBackoff ( ( ) => document . querySelectorAll ( this . disselectAllButtonSelector ) [ 1 ] ) ;
543
558
}
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
+
544
581
async selectBookmark ( ) {
545
582
if ( this . #isBookmarkProcessed) {
546
583
return ;
@@ -570,18 +607,10 @@ export default class AutofillPasswordImport extends ContentFeature {
570
607
const okButton = /** @type HTMLButtonElement */ ( document . querySelectorAll ( 'div[role="button"]' ) [ 7 ] ) ;
571
608
572
609
await withExponentialBackoff ( ( ) => okButton . ariaDisabled !== 'true' ) ;
573
-
610
+
574
611
okButton ?. click ( ) ;
575
612
this . #isBookmarkModalVisible = false ;
576
613
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 ( ) ;
585
614
}
586
615
587
616
async clickDisselectAllButton ( ) {
0 commit comments