mirror of
https://github.com/twofas/2fas-browser-extension.git
synced 2024-11-21 09:39:59 +01:00
#1570 inputToken improvement
This commit is contained in:
parent
ce3d7edaed
commit
fe2783381d
@ -18,7 +18,7 @@
|
||||
//
|
||||
|
||||
/* global Event, KeyboardEvent, InputEvent */
|
||||
const delay = require('../../partials/delay');
|
||||
const runTasksWithDelay = require('../../partials/runTasksWithDelay');
|
||||
const getTabData = require('./getTabData');
|
||||
const clickSubmit = require('./clickSubmit');
|
||||
const clearAfterInputToken = require('./clearAfterInputToken');
|
||||
@ -35,14 +35,14 @@ const inputToken = (request, inputElement, siteURL) => {
|
||||
|
||||
const tokenLength = request.token.length;
|
||||
const promises = [];
|
||||
let currentToken = '';
|
||||
|
||||
inputElement.value = '';
|
||||
inputElement.focus();
|
||||
|
||||
for (let i = 0; i < tokenLength; i++) {
|
||||
promises.push(
|
||||
delay(() => {
|
||||
if (document.activeElement.value.length > 0 && document.activeElement.value !== currentToken) {
|
||||
() => new Promise(resolve => {
|
||||
if (document.activeElement !== inputElement) {
|
||||
document.activeElement.value = '';
|
||||
}
|
||||
|
||||
@ -59,12 +59,12 @@ const inputToken = (request, inputElement, siteURL) => {
|
||||
document.activeElement.dispatchEvent(new KeyboardEvent('keyup', { bubbles: true, cancelable: true, charCode: 0, code: `Digit${request.token[i]}`, ctrlKey: false, key: request.token[i], keyCode: 48 + parseInt(request.token[i], 10), location: 0, metaKey: false, repeat: false, shiftKey: false, which: 48 + parseInt(request.token[i], 10) }));
|
||||
document.activeElement.dispatchEvent(new Event('change', { bubbles: true, cancelable: true }));
|
||||
|
||||
currentToken += request.token[i];
|
||||
}, 100 * i)
|
||||
return resolve();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return Promise.all(promises)
|
||||
return runTasksWithDelay(promises, 150)
|
||||
.then(async () => {
|
||||
const tab = await getTabData();
|
||||
|
||||
|
@ -32,7 +32,9 @@ exports.inputsSelectors = require('./inputsSelectors');
|
||||
exports.months = require('./months');
|
||||
exports.onTabFocused = require('./onTabFocused');
|
||||
exports.openShortcutEdit = require('./openShortcutEdit');
|
||||
exports.runTasksWithDelay = require('./runTasksWithDelay');
|
||||
exports.sendMessageToTab = require('./sendMessageToTab');
|
||||
exports.storageValidation = require('./storageValidation');
|
||||
exports.storeLog = require('./storeLog');
|
||||
exports.uniqueOnly = require('./uniqueOnly');
|
||||
exports.wait = require('./wait');
|
||||
|
29
src/partials/runTasksWithDelay.js
Normal file
29
src/partials/runTasksWithDelay.js
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// 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 wait = require('./wait');
|
||||
|
||||
const runTasksWithDelay = async (tasks, delayTime) => {
|
||||
for (const task of tasks) {
|
||||
await task();
|
||||
await wait(delayTime);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = runTasksWithDelay;
|
24
src/partials/wait.js
Normal file
24
src/partials/wait.js
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// 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 wait = async ms => {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
};
|
||||
|
||||
module.exports = wait;
|
Loading…
Reference in New Issue
Block a user