|
3811 | 3811 | var BACKGROUND_COLOR_START = "rgba(85, 127, 243, 0.10)";
|
3812 | 3812 | var BACKGROUND_COLOR_END = "rgba(85, 127, 243, 0.25)";
|
3813 | 3813 | var OVERLAY_ID = "ddg-password-import-overlay";
|
3814 |
| - var _exportButtonSettings, _settingsButtonSettings, _signInButtonSettings, _elementToCenterOn, _currentOverlay, _currentElementConfig, _domLoaded, _tappedElements; |
| 3814 | + var _exportButtonSettings, _settingsButtonSettings, _signInButtonSettings, _exportConfirmButtonSettings, _elementToCenterOn, _currentOverlay, _currentElementConfig, _domLoaded, _tappedElements; |
3815 | 3815 | var AutofillPasswordImport = class extends ContentFeature {
|
3816 | 3816 | constructor() {
|
3817 | 3817 | super(...arguments);
|
3818 | 3818 | __privateAdd(this, _exportButtonSettings);
|
3819 | 3819 | __privateAdd(this, _settingsButtonSettings);
|
3820 | 3820 | __privateAdd(this, _signInButtonSettings);
|
| 3821 | + __privateAdd(this, _exportConfirmButtonSettings); |
3821 | 3822 | /** @type {HTMLElement|Element|SVGElement|null} */
|
3822 | 3823 | __privateAdd(this, _elementToCenterOn);
|
3823 | 3824 | /** @type {HTMLElement|null} */
|
|
3897 | 3898 | get domLoaded() {
|
3898 | 3899 | return __privateGet(this, _domLoaded);
|
3899 | 3900 | }
|
| 3901 | + /** |
| 3902 | + * @returns {Promise<Element|HTMLElement|null>} |
| 3903 | + */ |
| 3904 | + async runWithRetry(fn) { |
| 3905 | + try { |
| 3906 | + return await withExponentialBackoff(fn); |
| 3907 | + } catch { |
| 3908 | + return null; |
| 3909 | + } |
| 3910 | + } |
| 3911 | + /** |
| 3912 | + * @returns {Promise<ElementConfig | null>} |
| 3913 | + */ |
| 3914 | + async getExportConfirmElementAndStyle() { |
| 3915 | + const exportConfirmElement = await this.findExportConfirmElement(); |
| 3916 | + const shouldAutotap = __privateGet(this, _exportConfirmButtonSettings)?.shouldAutotap && exportConfirmElement != null; |
| 3917 | + return shouldAutotap ? { |
| 3918 | + animationStyle: null, |
| 3919 | + element: exportConfirmElement, |
| 3920 | + shouldTap: true, |
| 3921 | + shouldWatchForRemoval: false, |
| 3922 | + tapOnce: false |
| 3923 | + } : null; |
| 3924 | + } |
| 3925 | + /** |
| 3926 | + * @returns {Promise<ElementConfig | null>} |
| 3927 | + */ |
| 3928 | + async getExportElementAndStyle() { |
| 3929 | + const element = await this.findExportElement(); |
| 3930 | + return element != null ? { |
| 3931 | + animationStyle: this.exportButtonAnimationStyle, |
| 3932 | + element, |
| 3933 | + shouldTap: __privateGet(this, _exportButtonSettings)?.shouldAutotap ?? false, |
| 3934 | + shouldWatchForRemoval: true, |
| 3935 | + tapOnce: true |
| 3936 | + } : null; |
| 3937 | + } |
3900 | 3938 | /**
|
3901 | 3939 | * Takes a path and returns the element and style to animate.
|
3902 | 3940 | * @param {string} path
|
|
3913 | 3951 | tapOnce: false
|
3914 | 3952 | } : null;
|
3915 | 3953 | } else if (path === "/options") {
|
3916 |
| - const element = await this.findExportElement(); |
3917 |
| - return element != null ? { |
3918 |
| - animationStyle: this.exportButtonAnimationStyle, |
3919 |
| - element, |
3920 |
| - shouldTap: __privateGet(this, _exportButtonSettings)?.shouldAutotap ?? false, |
3921 |
| - shouldWatchForRemoval: true, |
3922 |
| - tapOnce: true |
3923 |
| - } : null; |
| 3954 | + const isExportButtonTapped = this.currentElementConfig?.element != null && __privateGet(this, _tappedElements).has(this.currentElementConfig?.element); |
| 3955 | + if (isExportButtonTapped) { |
| 3956 | + return await this.getExportConfirmElementAndStyle(); |
| 3957 | + } else { |
| 3958 | + return await this.getExportElementAndStyle(); |
| 3959 | + } |
3924 | 3960 | } else if (path === "/intro") {
|
3925 | 3961 | const element = await this.findSignInButton();
|
3926 | 3962 | return element != null ? {
|
|
4072 | 4108 | autotapElement(element) {
|
4073 | 4109 | element.click();
|
4074 | 4110 | }
|
| 4111 | + async findExportConfirmElement() { |
| 4112 | + return await this.runWithRetry(() => document.querySelector(this.exportConfirmButtonSelector)); |
| 4113 | + } |
4075 | 4114 | /**
|
4076 | 4115 | * On passwords.google.com the export button is in a container that is quite ambiguious.
|
4077 | 4116 | * To solve for that we first try to find the container and then the button inside it.
|
|
4086 | 4125 | const findWithLabel = () => {
|
4087 | 4126 | return document.querySelector(this.exportButtonLabelTextSelector);
|
4088 | 4127 | };
|
4089 |
| - return await withExponentialBackoff(() => findInContainer() ?? findWithLabel()); |
| 4128 | + return await this.runWithRetry(() => findInContainer() ?? findWithLabel()); |
4090 | 4129 | }
|
4091 | 4130 | /**
|
4092 | 4131 | * @returns {Promise<HTMLElement|Element|null>}
|
|
4096 | 4135 | const settingsButton = document.querySelector(this.settingsButtonSelector);
|
4097 | 4136 | return settingsButton;
|
4098 | 4137 | };
|
4099 |
| - return await withExponentialBackoff(fn); |
| 4138 | + return await this.runWithRetry(fn); |
4100 | 4139 | }
|
4101 | 4140 | /**
|
4102 | 4141 | * @returns {Promise<HTMLElement|Element|null>}
|
4103 | 4142 | */
|
4104 | 4143 | async findSignInButton() {
|
4105 |
| - return await withExponentialBackoff(() => document.querySelector(this.signinButtonSelector)); |
| 4144 | + return await this.runWithRetry(() => document.querySelector(this.signinButtonSelector)); |
4106 | 4145 | }
|
4107 | 4146 | /**
|
4108 | 4147 | * @param {Event} event
|
|
4118 | 4157 | setCurrentElementConfig(config) {
|
4119 | 4158 | if (config != null) {
|
4120 | 4159 | __privateSet(this, _currentElementConfig, config);
|
4121 |
| - this.setElementToCenterOn(config.element, config.animationStyle); |
| 4160 | + if (config.animationStyle != null) this.setElementToCenterOn(config.element, config.animationStyle); |
4122 | 4161 | }
|
4123 | 4162 | }
|
4124 | 4163 | /**
|
|
4127 | 4166 | * @returns {boolean}
|
4128 | 4167 | */
|
4129 | 4168 | isSupportedPath(path) {
|
4130 |
| - return [__privateGet(this, _exportButtonSettings)?.path, __privateGet(this, _settingsButtonSettings)?.path, __privateGet(this, _signInButtonSettings)?.path].includes(path); |
| 4169 | + return [ |
| 4170 | + __privateGet(this, _exportButtonSettings)?.path, |
| 4171 | + __privateGet(this, _settingsButtonSettings)?.path, |
| 4172 | + __privateGet(this, _signInButtonSettings)?.path, |
| 4173 | + __privateGet(this, _exportConfirmButtonSettings)?.path |
| 4174 | + ].includes(path); |
4131 | 4175 | }
|
4132 | 4176 | async handlePath(path) {
|
4133 | 4177 | this.removeOverlayIfNeeded();
|
|
4151 | 4195 | */
|
4152 | 4196 | async animateOrTapElement() {
|
4153 | 4197 | const { element, animationStyle, shouldTap, shouldWatchForRemoval } = this.currentElementConfig ?? {};
|
4154 |
| - if (element != null && animationStyle != null) { |
| 4198 | + if (element != null) { |
4155 | 4199 | if (shouldTap) {
|
4156 | 4200 | this.autotapElement(element);
|
4157 | 4201 | } else {
|
4158 |
| - await this.domLoaded; |
4159 |
| - this.animateElement(element, animationStyle); |
| 4202 | + if (animationStyle != null) { |
| 4203 | + await this.domLoaded; |
| 4204 | + this.animateElement(element, animationStyle); |
| 4205 | + } |
4160 | 4206 | }
|
4161 | 4207 | if (shouldWatchForRemoval) {
|
4162 | 4208 | this.observeElementRemoval(element, () => {
|
|
4171 | 4217 | get exportButtonContainerSelector() {
|
4172 | 4218 | return __privateGet(this, _exportButtonSettings)?.selectors?.join(",");
|
4173 | 4219 | }
|
| 4220 | + /** |
| 4221 | + * @returns {string} |
| 4222 | + */ |
| 4223 | + get exportConfirmButtonSelector() { |
| 4224 | + return __privateGet(this, _exportConfirmButtonSettings)?.selectors?.join(","); |
| 4225 | + } |
4174 | 4226 | /**
|
4175 | 4227 | * @returns {string}
|
4176 | 4228 | */
|
|
4205 | 4257 | __privateSet(this, _exportButtonSettings, this.getFeatureSetting("exportButton"));
|
4206 | 4258 | __privateSet(this, _signInButtonSettings, this.getFeatureSetting("signInButton"));
|
4207 | 4259 | __privateSet(this, _settingsButtonSettings, this.getFeatureSetting("settingsButton"));
|
| 4260 | + __privateSet(this, _exportConfirmButtonSettings, this.getFeatureSetting("exportConfirmButton")); |
4208 | 4261 | }
|
4209 | 4262 | urlChanged() {
|
4210 | 4263 | this.handlePath(window.location.pathname);
|
|
4235 | 4288 | _exportButtonSettings = new WeakMap();
|
4236 | 4289 | _settingsButtonSettings = new WeakMap();
|
4237 | 4290 | _signInButtonSettings = new WeakMap();
|
| 4291 | + _exportConfirmButtonSettings = new WeakMap(); |
4238 | 4292 | _elementToCenterOn = new WeakMap();
|
4239 | 4293 | _currentOverlay = new WeakMap();
|
4240 | 4294 | _currentElementConfig = new WeakMap();
|
|
0 commit comments