mirror of
https://github.com/twofas/2fas-browser-extension.git
synced 2024-11-25 11:40:30 +01:00
#1458 hiddenNodes improvement
This commit is contained in:
parent
41f0f03d29
commit
6973f63899
@ -70,7 +70,7 @@
|
||||
"css-minimizer-webpack-plugin": "^5.0.1",
|
||||
"dotenv": "^16.3.1",
|
||||
"dotenv-webpack": "^8.0.1",
|
||||
"eslint": "8.55.0",
|
||||
"eslint": "8.56.0",
|
||||
"eslint-config-standard": "^17.1.0",
|
||||
"eslint-friendly-formatter": "^4.0.1",
|
||||
"eslint-plugin-import": "^2.29.0",
|
||||
|
36
src/content/observer/observerFunctions/getChildNodes.js
Normal file
36
src/content/observer/observerFunctions/getChildNodes.js
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// 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 getChildNodes = childNodes => {
|
||||
const cN = Array.from(childNodes);
|
||||
|
||||
if (cN && cN.length > 0) {
|
||||
return cN.map(childNode => {
|
||||
if (childNode?.childNodes && childNode?.childNodes?.length > 0) {
|
||||
return getChildNodes(childNode.childNodes).flat();
|
||||
}
|
||||
|
||||
return childNode;
|
||||
});
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = getChildNodes;
|
@ -18,32 +18,14 @@
|
||||
//
|
||||
|
||||
const isVisible = require('../../functions/isVisible');
|
||||
const significantInputs = require('../observerConstants/significantInputs');
|
||||
const findSignificantChanges = require('./findSignificantChanges');
|
||||
const getChildNodes = require('./getChildNodes');
|
||||
const { loadFromLocalStorage, saveToLocalStorage } = require('../../../localStorage');
|
||||
const storeLog = require('../../../partials/storeLog');
|
||||
|
||||
const hiddenNodes = async (mutation, tabData) => {
|
||||
let storage;
|
||||
|
||||
const node = mutation.target;
|
||||
const nodeName = node.nodeName.toLowerCase();
|
||||
|
||||
if (!significantInputs.includes(nodeName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const twofasInput = node.getAttribute('data-twofas-input');
|
||||
|
||||
if (!twofasInput) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const visible = await isVisible(node);
|
||||
|
||||
if (visible) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
storage = await loadFromLocalStorage([`tabData-${tabData?.id}`]);
|
||||
} catch (err) {
|
||||
@ -54,12 +36,25 @@ const hiddenNodes = async (mutation, tabData) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (twofasInput === storage[`tabData-${tabData?.id}`].lastFocusedInput) {
|
||||
delete storage[`tabData-${tabData?.id}`].lastFocusedInput;
|
||||
}
|
||||
let hiddenInputs = [mutation.target, ...getChildNodes(mutation.target.childNodes).flat()];
|
||||
hiddenInputs = hiddenInputs.filter(node => findSignificantChanges(node) && node.getAttribute('data-twofas-input'));
|
||||
|
||||
return saveToLocalStorage({ [`tabData-${tabData?.id}`]: storage[`tabData-${tabData?.id}`] })
|
||||
.catch(err => storeLog('error', 42, err, tabData?.url));
|
||||
return hiddenInputs.map(async node => {
|
||||
const visible = await isVisible(node);
|
||||
|
||||
if (node.getAttribute('data-twofas-input') === storage[`tabData-${tabData?.id}`].lastFocusedInput && !visible) {
|
||||
delete storage[`tabData-${tabData?.id}`].lastFocusedInput;
|
||||
|
||||
if (document?.activeElement && document?.activeElement?.getAttribute('data-twofas-input')) {
|
||||
storage[`tabData-${tabData?.id}`].lastFocusedInput = document.activeElement.getAttribute('data-twofas-input');
|
||||
}
|
||||
|
||||
return saveToLocalStorage({ [`tabData-${tabData?.id}`]: storage[`tabData-${tabData?.id}`] })
|
||||
.catch(err => storeLog('error', 42, err, tabData?.url));
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = hiddenNodes;
|
||||
|
@ -19,5 +19,6 @@
|
||||
|
||||
exports.addedNodes = require('./addedNodes');
|
||||
exports.checkChildNodes = require('./checkChildNodes');
|
||||
exports.getChildNodes = require('./getChildNodes');
|
||||
exports.hiddenNodes = require('./hiddenNodes');
|
||||
exports.removedNodes = require('./removedNodes');
|
||||
|
Loading…
Reference in New Issue
Block a user