Skip to content

Commit 5a94b61

Browse files
committed
wip: complete flow
1 parent fcdefe5 commit 5a94b61

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

injected/src/features/autofill-password-import.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const BACKGROUND_COLOR_END = 'rgba(85, 127, 243, 0.25)';
88
export const OVERLAY_ID = 'ddg-password-import-overlay';
99
export const DELAY_BEFORE_ANIMATION = 300;
1010
const 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,6 +556,28 @@ 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;
@@ -570,18 +607,10 @@ export default class AutofillPasswordImport extends ContentFeature {
570607
const okButton = /** @type HTMLButtonElement */ (document.querySelectorAll('div[role="button"]')[7]);
571608

572609
await withExponentialBackoff(() => okButton.ariaDisabled !== 'true');
573-
610+
574611
okButton?.click();
575612
this.#isBookmarkModalVisible = false;
576613
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();
585614
}
586615

587616
async clickDisselectAllButton() {

0 commit comments

Comments
 (0)