#1458 clickSubmit improvements

This commit is contained in:
Grzegorz Zając 2024-01-12 15:24:22 +01:00
parent 71a55bb609
commit f3cd85c209
7 changed files with 132 additions and 11 deletions

View File

@ -24,8 +24,16 @@ const delay = require('../../partials/delay');
const closest = (counts, goal) => {
return counts.indexOf(
counts.reduce((prev, curr) => {
return (Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev);
counts.reduce((a, b) => {
const aDiff = Math.abs(a - goal);
const bDiff = Math.abs(b - goal);
if (aDiff === bDiff) {
// Choose largest vs smallest (> vs <)
return a > b ? a : b;
} else {
return bDiff < aDiff ? b : a;
}
})
);
};

View File

@ -17,13 +17,43 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>
//
const getInputs = require('./getInputs');
const getFormSubmitElements = require('./getFormSubmitElements');
const buttonsTexts = require('../../partials/buttonsTexts');
const ignoreButtonTexts = require('../../partials/ignoreButtonTexts');
const getFormElements = () => {
const inputs = getInputs();
const formSubmitElements = getFormSubmitElements();
return inputs.concat(formSubmitElements);
const inputsSelector = require('../../partials/inputsSelectors')();
let submits = require('../../partials/formSubmitSelectors')();
let submitTextCheck = false;
let submitsLength = document.querySelectorAll(submits).length;
if (submitsLength <= 0) {
submits = require('../../partials/formSubmitSecondSelectors')();
}
submitsLength = document.querySelectorAll(submits).length;
if (submitsLength <= 0) {
submits = 'button';
submitTextCheck = true;
}
const query = inputsSelector.concat(',', submits);
let elements = Array.from(document.querySelectorAll(query));
if (submitTextCheck) {
elements = elements.filter(element => {
if (element.nodeName.toLowerCase() === 'input') {
return true;
}
if (element.nodeName.toLowerCase() === 'button') {
return buttonsTexts.includes(element.innerText.toLowerCase())
}
return false;
})
}
return elements.filter(element => !ignoreButtonTexts().includes(element.innerText.toLowerCase()));
};
module.exports = getFormElements;

View File

@ -18,6 +18,7 @@
//
const buttonsTexts = require('../../partials/buttonsTexts');
const ignoreButtonTexts = require('../../partials/ignoreButtonTexts');
const getFormSubmitElements = () => {
let submits = Array.from(
@ -35,7 +36,7 @@ const getFormSubmitElements = () => {
submits = buttons.filter(button => buttonsTexts.includes(button.innerText.toLowerCase()));
}
return submits;
return submits.filter(button => !ignoreButtonTexts().includes(button.innerText.toLowerCase()));
};
module.exports = getFormSubmitElements;

View File

@ -31,13 +31,13 @@ const createObserver = tabData => {
!mutation ||
mutation.attributeName === 'data-twofas-element-number' ||
mutation.attributeName === 'data-twofas-input' ||
mutation.target.className === 'twofas-be-notification visible'
mutation.target.className === 'twofas-be-notification visible' ||
mutation.target.nodeName.toLowerCase() === 'g' ||
mutation.target.nodeName.toLowerCase() === 'path'
) {
return false;
}
console.log(mutation);
if (
(mutation?.addedNodes && Array.from(mutation?.addedNodes).length > 0) ||
(mutation?.attributeName === 'disabled' && !mutation?.target?.disabled) ||

View File

@ -24,6 +24,7 @@ const ignoreButtonSelectors = () => {
':not(#search)',
':not([class*="dropdown"])',
':not([class*="cancel"])',
':not([class*="hidden"])',
':not([disabled])',
':not([style*="display:none"])',
':not([style*="opacity:0"])',

View File

@ -0,0 +1,80 @@
//
// 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 ignoreButtonTexts = () => {
return [
'search',
'buscar',
'zoeken',
'rechercher',
'suchen',
'pencarian',
'cerca',
'szukaj',
'procurar',
'ara',
'пошук',
'close',
'fechar',
'sluiten',
'fermer',
'schließen',
'tutup',
'chiudi',
'zamknij',
'cerrar',
'kapat',
'закрити',
'join',
'meedoen',
'rejoindre',
'verbinden',
'bergabung',
'giuntura',
'dołącz',
'juntar',
'unirse',
'katılmak',
'приєднатися',
'back',
'rug',
'dos',
'zurück',
'kembali',
'indietro',
'wróć',
'cofnij',
'voltar',
'atrás',
'geri',
'назад',
'cancel',
'cancelar',
'annuleren',
'annuler',
'abbrechen',
'membatalkan',
'annulla',
'anuluj',
'i̇ptal',
'відміна'
];
};
module.exports = ignoreButtonTexts;

View File

@ -27,6 +27,7 @@ exports.handleTargetBlank = require('./handleTargetBlank');
exports.hidePreloader = require('./hidePreloader');
exports.i18n = require('./i18n');
exports.ignoreButtonSelectors = require('./ignoreButtonSelectors');
exports.ignoreButtonTexts = require('./ignoreButtonTexts');
exports.inputsSelectors = require('./inputsSelectors');
exports.months = require('./months');
exports.onTabFocused = require('./onTabFocused');