diff --git a/keepassxc-browser/keepassxc-browser.js b/keepassxc-browser/keepassxc-browser.js index ebc1735..165a653 100755 --- a/keepassxc-browser/keepassxc-browser.js +++ b/keepassxc-browser/keepassxc-browser.js @@ -18,74 +18,6 @@ var _observerIds = []; // Document URL let _documentURL = document.location.href; -browser.runtime.onMessage.addListener(function(req, sender, callback) { - if ('action' in req) { - if (req.action === 'fill_user_pass_with_specific_login') { - if (cip.credentials[req.id]) { - let combination = null; - if (cip.u) { - cip.setValueWithChange(cip.u, cip.credentials[req.id].login); - combination = cipFields.getCombination('username', cip.u); - browser.runtime.sendMessage({ - action: 'page_set_login_id', args: [req.id] - }); - cip.u.focus(); - } - if (cip.p) { - cip.setValueWithChange(cip.p, cip.credentials[req.id].password); - browser.runtime.sendMessage({ - action: 'page_set_login_id', args: [req.id] - }); - combination = cipFields.getCombination('password', cip.p); - } - - let list = []; - if (cip.fillInStringFields(combination.fields, cip.credentials[req.id].stringFields, list)) { - cipForm.destroy(false, {'password': list.list[0], 'username': list.list[1]}); - } - } - } else if (req.action === 'fill_user_pass') { - _called.manualFillRequested = 'both'; - cip.receiveCredentialsIfNecessary().then((response) => { - cip.fillInFromActiveElement(false); - }); - } else if (req.action === 'fill_pass_only') { - _called.manualFillRequested = 'pass'; - cip.receiveCredentialsIfNecessary().then((response) => { - cip.fillInFromActiveElement(false, true); // passOnly to true - }); - } else if (req.action === 'fill_totp') { - cip.receiveCredentialsIfNecessary().then((response) => { - cip.fillInFromActiveElementTOTPOnly(false); - }); - } else if (req.action === 'activate_password_generator') { - cip.initPasswordGenerator(cipFields.getAllFields()); - } else if (req.action === 'remember_credentials') { - cip.contextMenuRememberCredentials(); - } else if (req.action === 'choose_credential_fields') { - cipDefine.init(); - } else if (req.action === 'clear_credentials') { - cipEvents.clearCredentials(); - return Promise.resolve(); - } else if (req.action === 'activated_tab') { - cipEvents.triggerActivatedTab(); - return Promise.resolve(); - } else if (req.action === 'redetect_fields') { - browser.runtime.sendMessage({ - action: 'load_settings', - }).then((response) => { - cip.settings = response; - cip.initCredentialFields(true); - }); - } else if (req.action === 'ignore-site') { - cip.ignoreSite(req.args); - } - else if (req.action === 'check_database_hash' && 'hash' in req) { - cip.detectDatabaseChange(req.hash); - } - } -}); - function _f(fieldId) { const field = (fieldId) ? jQuery('input[data-cip-id=\''+fieldId+'\']:first') : []; return (field.length > 0) ? field : null; @@ -1485,6 +1417,7 @@ cip.initCredentialFields = function(forceCall) { } if (cip.settings.autoRetrieveCredentials && _called.retrieveCredentials === false && (cip.url && cip.submitUrl)) { + _called.retrieveCredentials = true; browser.runtime.sendMessage({ action: 'retrieve_credentials', args: [ cip.url, cip.submitUrl ] diff --git a/keepassxc-browser/manifest.json b/keepassxc-browser/manifest.json index 0bd2aaa..8747b80 100755 --- a/keepassxc-browser/manifest.json +++ b/keepassxc-browser/manifest.json @@ -58,6 +58,16 @@ ], "run_at": "document_idle", "all_frames": true + }, + { + "matches": [ + "" + ], + "js": [ + "requests.js" + ], + "run_at": "document_idle", + "all_frames": false } ], "commands": { diff --git a/keepassxc-browser/requests.js b/keepassxc-browser/requests.js new file mode 100644 index 0000000..3330264 --- /dev/null +++ b/keepassxc-browser/requests.js @@ -0,0 +1,69 @@ +'use strict'; + +browser.runtime.onMessage.addListener(function(req, sender) { + if ('action' in req) { + if (req.action === 'fill_user_pass_with_specific_login') { + if (cip.credentials[req.id]) { + let combination = null; + if (cip.u) { + cip.setValueWithChange(cip.u, cip.credentials[req.id].login); + combination = cipFields.getCombination('username', cip.u); + browser.runtime.sendMessage({ + action: 'page_set_login_id', args: [req.id] + }); + cip.u.focus(); + } + if (cip.p) { + cip.setValueWithChange(cip.p, cip.credentials[req.id].password); + browser.runtime.sendMessage({ + action: 'page_set_login_id', args: [req.id] + }); + combination = cipFields.getCombination('password', cip.p); + } + + let list = []; + if (cip.fillInStringFields(combination.fields, cip.credentials[req.id].stringFields, list)) { + cipForm.destroy(false, {'password': list.list[0], 'username': list.list[1]}); + } + } + } else if (req.action === 'fill_user_pass') { + _called.manualFillRequested = 'both'; + cip.receiveCredentialsIfNecessary().then((response) => { + cip.fillInFromActiveElement(false); + }); + } else if (req.action === 'fill_pass_only') { + _called.manualFillRequested = 'pass'; + cip.receiveCredentialsIfNecessary().then((response) => { + cip.fillInFromActiveElement(false, true); // passOnly to true + }); + } else if (req.action === 'fill_totp') { + cip.receiveCredentialsIfNecessary().then((response) => { + cip.fillInFromActiveElementTOTPOnly(false); + }); + } else if (req.action === 'activate_password_generator') { + cip.initPasswordGenerator(cipFields.getAllFields()); + } else if (req.action === 'remember_credentials') { + cip.contextMenuRememberCredentials(); + } else if (req.action === 'choose_credential_fields') { + cipDefine.init(); + } else if (req.action === 'clear_credentials') { + cipEvents.clearCredentials(); + return Promise.resolve(); + } else if (req.action === 'activated_tab') { + cipEvents.triggerActivatedTab(); + return Promise.resolve(); + } else if (req.action === 'redetect_fields') { + browser.runtime.sendMessage({ + action: 'load_settings', + }).then((response) => { + cip.settings = response; + cip.initCredentialFields(true); + }); + } else if (req.action === 'ignore-site') { + cip.ignoreSite(req.args); + } + else if (req.action === 'check_database_hash' && 'hash' in req) { + cip.detectDatabaseChange(req.hash); + } + } +});