mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Fix await with TOTP fill, code cleaning
This commit is contained in:
parent
96b8a2abee
commit
0dd1e7d952
10 changed files with 30 additions and 59 deletions
|
|
@ -103,12 +103,6 @@ page.initOpenedTabs = async function() {
|
|||
}
|
||||
};
|
||||
|
||||
page.isValidProtocol = function(url) {
|
||||
let protocol = url.substring(0, url.indexOf(':'));
|
||||
protocol = protocol.toLowerCase();
|
||||
return !(url.indexOf('.') === -1 || (protocol !== 'http' && protocol !== 'https' && protocol !== 'ftp' && protocol !== 'sftp'));
|
||||
};
|
||||
|
||||
page.switchTab = function(tab) {
|
||||
browserAction.showDefault(tab);
|
||||
browser.tabs.sendMessage(tab.id, { action: 'activated_tab' }).catch((e) => {});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
var kpxcAutocomplete = {};
|
||||
const kpxcAutocomplete = {};
|
||||
kpxcAutocomplete.autoSubmit = false;
|
||||
kpxcAutocomplete.elements = [];
|
||||
kpxcAutocomplete.started = false;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const DEFAULT_BROWSER_GROUP = 'KeePassXC-Browser Passwords';
|
||||
|
||||
var kpxcBanner = {};
|
||||
const kpxcBanner = {};
|
||||
kpxcBanner.banner = undefined;
|
||||
kpxcBanner.created = false;
|
||||
kpxcBanner.credentials = {};
|
||||
|
|
|
|||
|
|
@ -274,11 +274,7 @@ kpxcDefine.prepareStep3 = function() {
|
|||
$('#kpxcDefine-btn-confirm').style.display = 'inline-block';
|
||||
};
|
||||
|
||||
kpxcDefine.skip = function(e) {
|
||||
if (!e.isTrusted) {
|
||||
return;
|
||||
}
|
||||
|
||||
kpxcDefine.skip = function() {
|
||||
if (kpxcDefine.dataStep === 1) {
|
||||
kpxcDefine.selection.username = null;
|
||||
kpxcDefine.prepareStep2();
|
||||
|
|
@ -290,32 +286,20 @@ kpxcDefine.skip = function(e) {
|
|||
}
|
||||
};
|
||||
|
||||
kpxcDefine.again = function(e) {
|
||||
if (!e.isTrusted) {
|
||||
return;
|
||||
}
|
||||
|
||||
kpxcDefine.again = function() {
|
||||
kpxcDefine.resetSelection();
|
||||
kpxcDefine.prepareStep1();
|
||||
kpxcDefine.markAllUsernameFields('#kpxcDefine-fields');
|
||||
};
|
||||
|
||||
kpxcDefine.more = function(e) {
|
||||
if (!e.isTrusted) {
|
||||
return;
|
||||
}
|
||||
|
||||
kpxcDefine.more = function() {
|
||||
if (kpxcDefine.dataStep === 2) {
|
||||
kpxcDefine.prepareStep2();
|
||||
kpxcDefine.markAllPasswordFields('#kpxcDefine-fields', true);
|
||||
}
|
||||
};
|
||||
|
||||
kpxcDefine.confirm = async function(e) {
|
||||
if (!e.isTrusted) {
|
||||
return;
|
||||
}
|
||||
|
||||
kpxcDefine.confirm = async function() {
|
||||
if (kpxcDefine.dataStep !== 3) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -353,11 +337,7 @@ kpxcDefine.confirm = async function(e) {
|
|||
kpxcDefine.close();
|
||||
};
|
||||
|
||||
kpxcDefine.discard = async function(e) {
|
||||
if (!e.isTrusted) {
|
||||
return;
|
||||
}
|
||||
|
||||
kpxcDefine.discard = async function() {
|
||||
if (!$('#kpxcDefine-btn-discard')) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
var ManualFill = {
|
||||
const ManualFill = {
|
||||
NONE: 0,
|
||||
PASS: 1,
|
||||
BOTH: 2
|
||||
};
|
||||
|
||||
// contains already called method names
|
||||
var _called = {};
|
||||
const _called = {};
|
||||
_called.retrieveCredentials = false;
|
||||
_called.clearLogins = false;
|
||||
_called.manualFillRequested = ManualFill.NONE;
|
||||
|
|
@ -18,7 +18,7 @@ const _maximumInputs = 100;
|
|||
var _detectedFields = 0;
|
||||
|
||||
// Element id's containing input fields detected by MutationObserver
|
||||
var _observerIds = [];
|
||||
const _observerIds = [];
|
||||
|
||||
// Document URL
|
||||
let _documentURL = document.location.href;
|
||||
|
|
@ -38,7 +38,7 @@ browser.runtime.onMessage.addListener(async function(req, sender) {
|
|||
kpxc.fillInFromActiveElement(false, true); // passOnly to true
|
||||
} else if (req.action === 'fill_totp') {
|
||||
await kpxc.receiveCredentialsIfNecessary();
|
||||
kpxc.fillInFromActiveElementTOTPOnly(false);
|
||||
kpxc.fillInFromActiveElementTOTPOnly();
|
||||
} else if (req.action === 'clear_credentials') {
|
||||
kpxcEvents.clearCredentials();
|
||||
return Promise.resolve();
|
||||
|
|
@ -186,7 +186,7 @@ kpxcForm.getNewPassword = function() {
|
|||
};
|
||||
|
||||
|
||||
var kpxcFields = {};
|
||||
const kpxcFields = {};
|
||||
kpxcFields.inputQueryPattern = 'input[type=\'text\'], input[type=\'email\'], input[type=\'password\'], input[type=\'tel\'], input[type=\'number\'], input[type=\'username\'], input:not([type])';
|
||||
|
||||
// copied from Sizzle.js
|
||||
|
|
@ -658,10 +658,7 @@ kpxcObserverHelper.getInputs = function(target) {
|
|||
// Only include input fields that match with kpxcObserverHelper.inputTypes
|
||||
const inputs = [];
|
||||
for (const i of inputFields) {
|
||||
let type = i.getAttribute('type');
|
||||
if (type) {
|
||||
type = type.toLowerCase();
|
||||
}
|
||||
let type = i.getLowerCaseAttribute('type');
|
||||
|
||||
if (kpxcObserverHelper.inputTypes.includes(type)) {
|
||||
inputs.push(i);
|
||||
|
|
@ -682,7 +679,7 @@ kpxcObserverHelper.ignoredElement = function(target) {
|
|||
|
||||
// Ignore KeePassXC-Browser classes
|
||||
if (target.className && target.className !== undefined &&
|
||||
(target.className.includes('kpxc') || target.className.includes('ui-helper'))) {
|
||||
target.className.includes('kpxc')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -792,7 +789,7 @@ observer.observe(document, {
|
|||
attributeFilter: [ 'style', 'class' ]
|
||||
});
|
||||
|
||||
var kpxc = {};
|
||||
const kpxc = {};
|
||||
kpxc.settings = {};
|
||||
kpxc.u = null;
|
||||
kpxc.p = null;
|
||||
|
|
@ -970,7 +967,7 @@ kpxc.receiveCredentialsIfNecessary = async function() {
|
|||
|
||||
// If the database was locked, this is scope never met. In these cases the response is met at kpxc.detectDatabaseChange
|
||||
_called.manualFillRequested = ManualFill.NONE;
|
||||
kpxc.retrieveCredentialsCallback(credentials, false);
|
||||
await kpxc.retrieveCredentialsCallback(credentials, false);
|
||||
return credentials;
|
||||
}
|
||||
|
||||
|
|
@ -1195,7 +1192,7 @@ kpxc.fillInCredentials = async function(combination, onlyPassword, suppressWarni
|
|||
args: [ kpxc.url, kpxc.submitUrl, true ] // Sets triggerUnlock to true
|
||||
});
|
||||
|
||||
kpxc.retrieveCredentialsCallback(credentials, true);
|
||||
await kpxc.retrieveCredentialsCallback(credentials, true);
|
||||
kpxc.fillIn(combination, onlyPassword, suppressWarnings);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
var kpxcPassword = {};
|
||||
const kpxcPassword = {};
|
||||
kpxcPassword.created = false;
|
||||
kpxcPassword.icon = null;
|
||||
kpxcPassword.inputField = null;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ const siteList = [
|
|||
}
|
||||
];
|
||||
|
||||
var kpxcSites = {};
|
||||
const kpxcSites = {};
|
||||
|
||||
// Returns a predefined URL for certain sites to ensure compatibility with Site Preferences
|
||||
kpxcSites.definedURL = function(url) {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
// jQuery style wrapper for querySelector()
|
||||
var $ = function(elem) {
|
||||
const $ = function(elem) {
|
||||
return document.querySelector(elem);
|
||||
};
|
||||
|
||||
// Returns a string with 'px' for CSS styles
|
||||
var Pixels = function(value) {
|
||||
const Pixels = function(value) {
|
||||
return String(value) + 'px';
|
||||
};
|
||||
|
||||
var kpxcUI = {};
|
||||
const kpxcUI = {};
|
||||
|
||||
// Wrapper for creating elements
|
||||
kpxcUI.createElement = function(type, classes, attributes, textContent) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
var kpxcUsernameField = {};
|
||||
const kpxcUsernameField = {};
|
||||
kpxcUsernameField.icon = null;
|
||||
kpxcUsernameField.inputField = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ const schemeSegment = '(\\*|http|https|ws|wss|file|ftp)';
|
|||
const hostSegment = '(\\*|(?:\\*\\.)?(?:[^/*]+))?';
|
||||
const pathSegment = '(.*)';
|
||||
|
||||
var isFirefox = function() {
|
||||
const isFirefox = function() {
|
||||
return navigator.userAgent.indexOf('Firefox') !== -1 || navigator.userAgent.indexOf('Gecko/') !== -1;
|
||||
};
|
||||
|
||||
var showNotification = function(message) {
|
||||
const showNotification = function(message) {
|
||||
browser.notifications.create({
|
||||
'type': 'basic',
|
||||
'iconUrl': browser.extension.getURL('icons/keepassxc_64x64.png'),
|
||||
|
|
@ -21,7 +21,7 @@ var showNotification = function(message) {
|
|||
});
|
||||
};
|
||||
|
||||
var AssociatedAction = {
|
||||
const AssociatedAction = {
|
||||
NOT_ASSOCIATED: 0,
|
||||
ASSOCIATED: 1,
|
||||
NEW_ASSOCIATION: 2,
|
||||
|
|
@ -38,7 +38,7 @@ var AssociatedAction = {
|
|||
*
|
||||
* https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Match_patterns
|
||||
*/
|
||||
var matchPatternToRegExp = function(pattern) {
|
||||
const matchPatternToRegExp = function(pattern) {
|
||||
if (pattern === '') {
|
||||
return (/^(?:http|https|file|ftp|app):\/\//);
|
||||
}
|
||||
|
|
@ -93,12 +93,12 @@ var matchPatternToRegExp = function(pattern) {
|
|||
return new RegExp(regex);
|
||||
};
|
||||
|
||||
var siteMatch = function(site, url) {
|
||||
const siteMatch = function(site, url) {
|
||||
const rx = matchPatternToRegExp(site);
|
||||
return url.match(rx);
|
||||
};
|
||||
|
||||
var slashNeededForUrl = function(pattern) {
|
||||
const slashNeededForUrl = function(pattern) {
|
||||
const matchPattern = new RegExp(`^${schemeSegment}://${hostSegment}$`);
|
||||
return matchPattern.exec(pattern);
|
||||
};
|
||||
|
|
@ -108,6 +108,6 @@ function tr(key, params) {
|
|||
}
|
||||
|
||||
// Removes everything after '?' from URL
|
||||
var trimURL = function(url) {
|
||||
const trimURL = function(url) {
|
||||
return url.indexOf('?') !== -1 ? url.split('?')[0] : url;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue