#1501 AutoSubmit - Experimental, toggle added

This commit is contained in:
GrzegorzZajac000 2024-02-15 11:32:04 +01:00
parent 9ae1597639
commit 7fecadae8c
10 changed files with 115 additions and 6 deletions

View File

@ -9,7 +9,9 @@
"optionsDonate": "Donate",
"optionsPairedHeader": "Paired devices:",
"optionsAddAnotherDevice": "Add another device",
"optionsExcludedDomainsHeader": "Auto submit excluded domains:",
"optionsAutoSubmitSwitchHeader": "[EXPERIMENTAL] Auto submit:",
"optionsAutoSubmitSwitchLabel": "Enable automatic submission of 2fa forms",
"optionsExcludedDomainsHeader": "[EXPERIMENTAL] Auto submit excluded domains:",
"optionsRemoveFromExcluded": "Remove from excluded",
"optionsExcludeAnotherDomain": "Exclude domain",
"optionsExcludeImportDefault": "Import default list",

View File

@ -59,6 +59,7 @@ const generateDefaultStorage = browserInfo => {
nativePush: (process.env.EXT_PLATFORM !== 'Safari'),
pinInfo: false,
extensionVersion: config.ExtensionVersion,
autoSubmitEnabled: false,
autoSubmitExcludedDomains: defaultAutoSubmitExcludedDomains,
attempt: attempt + 1
});

View File

@ -41,10 +41,14 @@ const closest = (counts, goal) => {
const clickSubmit = (inputElement, siteURL) => {
return delay(() => {}, 500)
.then(() => loadFromLocalStorage(['autoSubmitExcludedDomains']))
.then(() => loadFromLocalStorage(['autoSubmitExcludedDomains', 'autoSubmitEnabled']))
.then(storage => {
if (!storage?.autoSubmitEnabled) {
return false;
}
const domains = storage.autoSubmitExcludedDomains || [];
const url = new URL(siteURL);
const url = new URL(siteURL); // @TODO try catch
const hostname = url.hostname.replace(/^(www\.)?/, '').replace(/\/$/, '');
if (domains && domains?.includes(hostname)) {

View File

@ -0,0 +1,26 @@
//
// This file is part of the 2FAS Browser Extension (https://github.com/twofas/2fas-browser-extension)
// Copyright © 2023 Two Factor Authentication Service, Inc.
// Contributed by Grzegorz Zając. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>
//
const saveToLocalStorage = require('../../localStorage/saveToLocalStorage');
const handleAutoSubmitChange = e => {
return saveToLocalStorage({ autoSubmitEnabled: e.currentTarget.checked });
};
module.exports = handleAutoSubmitChange;

View File

@ -27,6 +27,7 @@ exports.generateEmptyShortcutBox = require('./generateEmptyShortcutBox');
exports.generateShortcutBox = require('./generateShortcutBox');
exports.generateShortcutLink = require('./generateShortcutLink');
exports.handleAdvancedHeaderClick = require('./handleAdvancedHeaderClick');
exports.handleAutoSubmitChange = require('./handleAutoSubmitChange');
exports.handleContextMenuChange = require('./handleContextMenuChange');
exports.handleHamburgerClick = require('./handleHamburgerClick');
exports.handleImportDefaultExcludedDomains = require('./handleImportDefaultExcludedDomains');
@ -45,6 +46,7 @@ exports.removeDomain = require('./removeDomain');
exports.removeDomainFromDOM = require('./removeDomainFromDOM');
exports.sendTestNotification = require('./sendTestNotification');
exports.setAdvanced = require('./setAdvanced');
exports.setAutoSubmitSwitch = require('./setAutoSubmitSwitch');
exports.setExtName = require('./setExtName');
exports.setContextMenuToggle = require('./setContextMenuToggle');
exports.setExtNameUpdateForm = require('./setExtNameUpdateForm');

View File

@ -0,0 +1,47 @@
//
// This file is part of the 2FAS Browser Extension (https://github.com/twofas/2fas-browser-extension)
// Copyright © 2023 Two Factor Authentication Service, Inc.
// Contributed by Grzegorz Zając. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>
//
const S = require('../../selectors');
const handleAutoSubmitChange = require('./handleAutoSubmitChange');
const { loadFromLocalStorage, saveToLocalStorage } = require('../../localStorage');
const setAutoSubmitSwitch = () => {
return loadFromLocalStorage(['autoSubmitEnabled'])
.then(storage => {
if (!('autoSubmitEnabled' in storage)) {
return saveToLocalStorage({ autoSubmitEnabled: false }, storage);
}
return storage;
})
.then(storage => {
const autoSubmitToggle = document.querySelector(S.optionsPage.autoSubmit.toggle);
if (autoSubmitToggle) {
autoSubmitToggle.checked = storage.autoSubmitEnabled;
}
autoSubmitToggle.addEventListener('change', handleAutoSubmitChange);
return Promise.resolve();
})
.catch(() => {});
};
module.exports = setAutoSubmitSwitch;

View File

@ -123,9 +123,30 @@
</div>
</div>
<div class="twofas-options-page-content-auto-submit-switch">
<div class="twofas-options-page-content-auto-submit-switch-header">
<h2 data-i18n="optionsAutoSubmitSwitchHeader">[EXPERIMENTAL] Auto submit:</h2>
</div>
<div class="twofas-options-page-content-auto-submit-switch-button">
<div class="twofas-toggle">
<input type="checkbox" name="twofas-auto-submit-switch" id="twofas-auto-submit-switch">
<label for="twofas-auto-submit-switch">
<span class="twofas-toggle-box">
<span class="twofas-toggle-box-circle"></span>
</span>
<span class="twofas-toggle-text">
<span data-i18n="optionsAutoSubmitSwitchLabel">Enable automatic submission of 2fa forms</span>
</span>
</label>
</div>
</div>
</div>
<div class="twofas-options-page-content-auto-submit-excluded-domain-list">
<div class="twofas-options-page-content-auto-submit-excluded-domain-list-header">
<h2 data-i18n="optionsExcludedDomainsHeader">Auto submit excluded domains:</h2>
<h2 data-i18n="optionsExcludedDomainsHeader">[EXPERIMENTAL] Auto submit excluded domains:</h2>
</div>
<div class="twofas-options-page-content-auto-submit-excluded-domain-list-list">

View File

@ -25,7 +25,7 @@ const TwoFasNotification = require('../notification');
const SDK = require('../sdk');
const extPageOnMessage = require('../partials/extPageOnMessage');
const { delay, storeLog, handleTargetBlank, hidePreloader, storageValidation } = require('../partials');
const { generateDevicesList, setLoggingToggle, setContextMenuToggle, setPushRadio, setPinInfo, setExtName, setExtNameUpdateForm, setModalsListeners, setAdvanced, setMenuLinks, setPinInfoBtns, setShortcutBox, setHamburger, setExtVersion, generateShortcutBox, generateShortcutLink, showIntegrityError, generateDomainsList, setImportDefaultExcludedDomains } = require('./functions');
const { generateDevicesList, setLoggingToggle, setContextMenuToggle, setPushRadio, setPinInfo, setExtName, setExtNameUpdateForm, setModalsListeners, setAdvanced, setMenuLinks, setPinInfoBtns, setShortcutBox, setHamburger, setExtVersion, generateShortcutBox, generateShortcutLink, showIntegrityError, generateDomainsList, setImportDefaultExcludedDomains, setAutoSubmitSwitch } = require('./functions');
const init = async storage => {
i18n();
@ -55,6 +55,7 @@ const init = async storage => {
.then(() => setExtNameUpdateForm(storage))
.then(setModalsListeners)
.then(setAdvanced)
.then(setAutoSubmitSwitch)
.then(setMenuLinks)
.then(setPinInfoBtns)
.then(generateShortcutBox)

View File

@ -336,9 +336,13 @@
}
}
&-auto-submit-excluded-domain-list {
&-auto-submit-switch {
margin-top: 34px;
}
&-auto-submit-excluded-domain-list {
margin-top: 10px;
table {
border-collapse: collapse;
border: 0;

View File

@ -76,6 +76,7 @@ const selectors = {
content: '.js-twofas-options-menu-content'
},
autoSubmit: {
toggle: 'input#twofas-auto-submit-switch',
list: '.js-twofas-auto-submit-excluded-domain-list',
exclude: '.js-twofas-auto-submit-excluded-domain-exclude',
add: '.js-twofas-auto-submit-excluded-domain-add',