Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update contentscript and inject icon logic (#541)
Leendert de Borst1263639ca254
diff --git a/browser-extensions/chrome/contentScript.ts b/browser-extensions/chrome/contentScript.tsindex f887ff183..10a782aa9 100644--- a/browser-extensions/chrome/contentScript.ts+++ b/browser-extensions/chrome/contentScript.ts@@ -7,7 +7,11 @@ import { injectIcon } from './src/contentScript/Form';*/document.addEventListener('focusin', async (e) => {const target = e.target as HTMLInputElement;- if (target.tagName === 'INPUT' && !target.dataset.aliasvaultIgnore) {+ 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();diff --git a/browser-extensions/chrome/src/contentScript/Filter.ts b/browser-extensions/chrome/src/contentScript/Filter.tsindex f991d45b9..7707dd8f0 100644--- a/browser-extensions/chrome/src/contentScript/Filter.ts+++ b/browser-extensions/chrome/src/contentScript/Filter.ts@@ -38,7 +38,23 @@ export function filterCredentials(credentials: Credential[], currentUrl: string,// 3. Page title word match if still no matchesif (filtered.length === 0 && pageTitle.length > 0) {- const titleWords = pageTitle.toLowerCase().split(/\s+/);+ // TODO: make bad words list configurable per language.+ const badWords = new Set([+ 'login', 'signin', 'sign', 'register', 'signup', 'account',+ 'portal', 'dashboard', 'home', 'welcome', 'authentication',+ 'page', 'site', 'secure', 'password', 'access', 'member',+ 'user', 'profile', 'auth', 'session', 'inloggen',+ 'registreren', 'registratie', 'free', 'gratis', 'create',+ 'new'+ ]);++ const titleWords = pageTitle.toLowerCase()+ .split(/\s+/)+ .filter(word =>+ word.length > 2 && // Filter out words shorter than 3 characters+ !badWords.has(word.toLowerCase()) // Filter out generic words+ );+filtered = credentials.filter(cred =>titleWords.some(word =>cred.ServiceName.toLowerCase().includes(word)diff --git a/browser-extensions/chrome/src/contentScript/Form.ts b/browser-extensions/chrome/src/contentScript/Form.tsindex b08e3d095..7284bae5a 100644--- a/browser-extensions/chrome/src/contentScript/Form.ts+++ b/browser-extensions/chrome/src/contentScript/Form.ts@@ -214,13 +214,12 @@ export function injectIcon(input: HTMLInputElement): void {align-items: center;justify-content: center;position: absolute;- right: 8px;- top: 8px;- margin: auto;cursor: pointer;- width: 20px;- height: 20px;- z-index: 999999;+ width: 24px;+ height: 24px;+ pointer-events: auto;+ opacity: 0;+ transition: opacity 0.2s ease-in-out;"><img src="data:image/svg+xml;base64,${btoa(aliasvaultIconSvg)}" style="width: 100%; height: 100%;" /></div>@@ -231,61 +230,75 @@ export function injectIcon(input: HTMLInputElement): void {input.id = `aliasvault-input-${Math.random().toString(36).substr(2, 9)}`;}- // Remove existing icon if one already exists- const existingIcon = document.querySelector(`[data-icon-for="${input.id}"]`);- if (existingIcon) {- existingIcon.remove();+ // Create an overlay container at document level if it doesn't exist+ let overlayContainer = document.getElementById('aliasvault-overlay-container');+ if (!overlayContainer) {+ overlayContainer = document.createElement('div');+ overlayContainer.id = 'aliasvault-overlay-container';+ overlayContainer.style.cssText = `+ position: fixed;+ top: 0;+ left: 0;+ width: 100%;+ height: 100%;+ pointer-events: none;+ z-index: 2147483647;+ `;+ document.body.appendChild(overlayContainer);}- const iconDiv = document.createElement('div');- iconDiv.innerHTML = ICON_HTML;- const icon = iconDiv.firstElementChild as HTMLElement;+ // Create the icon element from the HTML template+ const iconContainer = document.createElement('div');+ iconContainer.innerHTML = ICON_HTML;+ const icon = iconContainer.firstElementChild as HTMLElement;+ icon.setAttribute('data-icon-for', input.id);- // Get input's position and dimensions- const inputRect = input.getBoundingClientRect();+ // Enable pointer events just for the icon+ icon.style.pointerEvents = 'auto';- // Position icon absolutely relative to viewport- icon.style.cssText = `- position: fixed;- z-index: 9999;- cursor: pointer;- top: ${inputRect.top + window.scrollY + (inputRect.height - 24) / 2}px;- right: ${window.innerWidth - (inputRect.right + window.scrollX) + 8}px;- width: 24px;- height: 24px;- pointer-events: auto;- opacity: 0;- transition: opacity 0.2s ease-in-out;- `;+ // Function to update icon position+ const updateIconPosition = () => {+ const rect = input.getBoundingClientRect();+ icon.style.position = 'fixed';+ icon.style.top = `${rect.top + (rect.height - 24) / 2}px`;+ icon.style.left = `${rect.right - 32}px`;+ };- icon.setAttribute('data-icon-for', input.id);+ // Update position initially and on relevant events+ updateIconPosition();+ window.addEventListener('scroll', updateIconPosition, true);+ window.addEventListener('resize', updateIconPosition);+ // Add click event to trigger the autofill popup and refocus the inputicon.addEventListener('click', (e: MouseEvent) => {e.preventDefault();e.stopPropagation();- // Prevent the input from losing focus when clicking the iconsetTimeout(() => input.focus(), 0);openAutofillPopup(input);});- // Add to body- document.body.appendChild(icon);+ // Append the icon to the overlay container+ overlayContainer.appendChild(icon);// Fade in the iconrequestAnimationFrame(() => {icon.style.opacity = '1';});- /**- * Remove icon when input loses focus, except when clicking the icon- */- const handleBlur = () : void => {- // Fade out and remove icon+ // Remove the icon when the input loses focus+ const handleBlur = (): void => {icon.style.opacity = '0';setTimeout(() => {icon.remove();input.removeEventListener('blur', handleBlur);- }, 200); // Match transition duration+ window.removeEventListener('scroll', updateIconPosition, true);+ window.removeEventListener('resize', updateIconPosition);++ // Remove overlay container if it's empty+ if (!overlayContainer.children.length) {+ overlayContainer.remove();+ }+ }, 200);};input.addEventListener('blur', handleBlur);