mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-03-20 07:39:07 -04:00
32 lines
1005 B
TypeScript
32 lines
1005 B
TypeScript
import { FormDetector } from './src/shared/formDetector/FormDetector';
|
|
import { isAutoShowPopupDisabled, openAutofillPopup, removeExistingPopup } from './src/contentScript/Popup';
|
|
import { injectIcon } from './src/contentScript/Form';
|
|
|
|
/**
|
|
* Listen for input field focus
|
|
*/
|
|
document.addEventListener('focusin', async (e) => {
|
|
const target = e.target as HTMLInputElement;
|
|
const textInputTypes = ['text', 'email', 'tel', 'password', 'search', 'url'];
|
|
|
|
if (target.tagName === 'INPUT' &&
|
|
textInputTypes.includes(target.type) &&
|
|
!target.dataset.aliasvaultIgnore) {
|
|
const formDetector = new FormDetector(document, target);
|
|
const forms = formDetector.detectForms();
|
|
|
|
if (!forms.length) return;
|
|
|
|
injectIcon(target);
|
|
|
|
const isDisabled = await isAutoShowPopupDisabled();
|
|
if (!isDisabled) {
|
|
openAutofillPopup(target);
|
|
}
|
|
}
|
|
});
|
|
|
|
// Also listen for popstate events (back/forward navigation)
|
|
window.addEventListener('popstate', () => {
|
|
removeExistingPopup();
|
|
}); |