Files
aliasvault/browser-extensions/chrome/contentScript.ts
2025-02-17 11:25:14 +01:00

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();
});