From aa3f1b48706b94c56542a4642134f85f43e09fb0 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sat, 27 Jul 2024 07:49:22 +0300 Subject: [PATCH] Add Improved Input Field Detection to Predefined Sites feature --- .eslintrc | 1 + keepassxc-browser/common/sites.js | 4 +++ .../content/keepassxc-browser.js | 27 ++++++++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.eslintrc b/.eslintrc index 2d9910c..5ad12c7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -118,6 +118,7 @@ "IGNORE_NORMAL": true, "IGNORE_NOTHING": true, "importScripts": true, + "IMPROVED_DETECTION_PREDEFINED_SITELIST": true, "initColorTheme": true, "isEdge": true, "isFirefox": true, diff --git a/keepassxc-browser/common/sites.js b/keepassxc-browser/common/sites.js index 20d1fe8..e7fc41e 100644 --- a/keepassxc-browser/common/sites.js +++ b/keepassxc-browser/common/sites.js @@ -34,6 +34,10 @@ const PREDEFINED_SITELIST = [ 'https://*.wordpress.com/log-in/' ]; +const IMPROVED_DETECTION_PREDEFINED_SITELIST = [ + 'https://secure.chase.com/*' +]; + const googleUrl = 'https://accounts.google.com'; const kpxcSites = {}; diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 39ecdb6..76dd42b 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -747,7 +747,7 @@ kpxc.showGroupNameInAutocomplete = function() { || (kpxc.settings.showGroupNameInAutocomplete && kpxc.getUniqueGroupCount(kpxc.credentials) > 1); }; -// Returns true if site is ignored +// Returns true if site is ignored, and checks for predefined sites kpxc.siteIgnored = async function(condition) { if (kpxc.settings.sitePreferences) { let currentLocation; @@ -760,7 +760,6 @@ kpxc.siteIgnored = async function(condition) { currentLocation = window.self.location.href; } - // Refresh current settings for the site const currentSetting = condition || IGNORE_FULL; for (const site of kpxc.settings.sitePreferences) { if (siteMatch(site.url, currentLocation) || site.url === currentLocation) { @@ -768,6 +767,7 @@ kpxc.siteIgnored = async function(condition) { return true; } + // Refresh current settings for the site kpxc.singleInputEnabledForPage = site.usernameOnly; kpxc.improvedFieldDetectionEnabledForPage = site.improvedFieldDetection; await sendMessage('page_set_allow_iframes', [ site.allowIframes, currentLocation ]); @@ -776,11 +776,7 @@ kpxc.siteIgnored = async function(condition) { // Check for predefined sites if (kpxc.settings.usePredefinedSites) { - for (const url of PREDEFINED_SITELIST) { - if (siteMatch(url, currentLocation) || url === currentLocation) { - kpxc.singleInputEnabledForPage = true; - } - } + kpxc.usePredefinedSites(currentLocation); } } @@ -843,6 +839,23 @@ kpxc.updateTOTPList = async function() { return []; }; +// Enable certain settings based on predefined sites list +kpxc.usePredefinedSites = function(currentLocation) { + // Single input field + for (const url of PREDEFINED_SITELIST) { + if (siteMatch(url, currentLocation) || url === currentLocation) { + kpxc.singleInputEnabledForPage = true; + } + } + + // Improved input field detection + for (const url of IMPROVED_DETECTION_PREDEFINED_SITELIST) { + if (siteMatch(url, currentLocation) || url === currentLocation) { + kpxc.improvedFieldDetectionEnabledForPage = true; + } + } +}; + // Apply a script to the page for intercepting Passkeys (WebAuthn) requests kpxc.enablePasskeys = function() { if (document?.documentElement?.ownerDocument?.contentType !== 'text/html') {