mirror of
https://github.com/twofas/2fas-browser-extension.git
synced 2024-11-24 11:09:58 +01:00
#1515 Code refactor
This commit is contained in:
parent
77f270c3ca
commit
56f559283b
@ -49,13 +49,13 @@
|
|||||||
16 - inputFocus
|
16 - inputFocus
|
||||||
17 - contentOnMessage
|
17 - contentOnMessage
|
||||||
18 - neverShowNotificationInfo
|
18 - neverShowNotificationInfo
|
||||||
*19 - openOptionsPage [redundant]
|
*19 - openOptionsPage [deprecated]
|
||||||
39 - removedNodes - loadFromLocalStorage
|
*39 - removedNodes - loadFromLocalStorage [deprecated]
|
||||||
40 - removedNodes - saveToLocalStorage
|
*40 - removedNodes - saveToLocalStorage [deprecated]
|
||||||
41 - hiddenNodes - loadFromLocalStorage
|
*41 - hiddenNodes - loadFromLocalStorage [deprecated]
|
||||||
42 - hiddenNodes - saveToLocalStorage
|
*42 - hiddenNodes - saveToLocalStorage [deprecated]
|
||||||
43 - pageLoadComplete - loadFromLocalStorage
|
*43 - pageLoadComplete - loadFromLocalStorage [deprecated]
|
||||||
44 - pageLoadComplete - saveToLocalStorage
|
*44 - pageLoadComplete - saveToLocalStorage [deprecated]
|
||||||
46 - clickSubmit - loadFromLocalStorage
|
46 - clickSubmit - loadFromLocalStorage
|
||||||
|
|
||||||
// INSTALL PAGE
|
// INSTALL PAGE
|
||||||
|
@ -35,8 +35,6 @@
|
|||||||
"errorStorageIntegrityMessage": "Please reinstall browser extension or contact with 2FAS Support on Discord",
|
"errorStorageIntegrityMessage": "Please reinstall browser extension or contact with 2FAS Support on Discord",
|
||||||
"warningTooSoonTitle": "Wait a moment",
|
"warningTooSoonTitle": "Wait a moment",
|
||||||
"warningTooSoonMessage": "Please wait DIFF seconds before sending another request.",
|
"warningTooSoonMessage": "Please wait DIFF seconds before sending another request.",
|
||||||
"warningSelectInputTitle": "Select the text field first",
|
|
||||||
"warningSelectInputMessage": "Select the text field for the 2FA token then click the extension icon or use the chosen shortcut.",
|
|
||||||
"successPushSentTitle": "Push sent",
|
"successPushSentTitle": "Push sent",
|
||||||
"successPushSentMessage": "Please check your phone and accept your login request.",
|
"successPushSentMessage": "Please check your phone and accept your login request.",
|
||||||
"successPushSentClipboardTitle": "Push sent",
|
"successPushSentClipboardTitle": "Push sent",
|
||||||
|
@ -104,10 +104,6 @@ const config = {
|
|||||||
Title: browser.i18n.getMessage('warningTooSoonTitle') || t.warningTooSoonTitle,
|
Title: browser.i18n.getMessage('warningTooSoonTitle') || t.warningTooSoonTitle,
|
||||||
Message: (browser.i18n.getMessage('warningTooSoonMessage') || t.warningTooSoonMessage).replace('DIFF', 10 - Math.round(diff))
|
Message: (browser.i18n.getMessage('warningTooSoonMessage') || t.warningTooSoonMessage).replace('DIFF', 10 - Math.round(diff))
|
||||||
}
|
}
|
||||||
},
|
|
||||||
SelectInput: {
|
|
||||||
Title: browser.i18n.getMessage('warningSelectInputTitle') || t.warningSelectInputTitle,
|
|
||||||
Message: browser.i18n.getMessage('warningSelectInputMessage') || t.warningSelectInputMessage
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Success: {
|
Success: {
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
//
|
|
||||||
// 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 updateEventListener = require('./updateEventListener');
|
|
||||||
const inputFocus = require('./inputFocus');
|
|
||||||
|
|
||||||
const addInputListener = (elements, tabID) => {
|
|
||||||
if (!Array.isArray(elements) || elements?.length <= 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let func = event => inputFocus(event, tabID);
|
|
||||||
|
|
||||||
elements.map(input => {
|
|
||||||
if (input?.dataset?.twofasInputListener === 'true' && input?.dataset.twofasInput) {
|
|
||||||
if (input === document.activeElement || input.matches(':focus')) {
|
|
||||||
return func({ target: input });
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return updateEventListener(input, func);
|
|
||||||
});
|
|
||||||
|
|
||||||
func = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = addInputListener;
|
|
@ -1,27 +0,0 @@
|
|||||||
//
|
|
||||||
// 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 inputsSelectors = require('../../partials/inputsSelectors')();
|
|
||||||
|
|
||||||
const getInputs = node => {
|
|
||||||
const el = node || document;
|
|
||||||
return Array.from(el.querySelectorAll(inputsSelectors));
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = getInputs;
|
|
@ -18,20 +18,16 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
exports.addFormElementsNumber = require('./addFormElementsNumber');
|
exports.addFormElementsNumber = require('./addFormElementsNumber');
|
||||||
exports.addInputListener = require('./addInputListener');
|
|
||||||
exports.clearFormElementsNumber = require('./clearFormElementsNumber');
|
exports.clearFormElementsNumber = require('./clearFormElementsNumber');
|
||||||
exports.clickSubmit = require('./clickSubmit');
|
exports.clickSubmit = require('./clickSubmit');
|
||||||
exports.closeNotificationInfo = require('./closeNotificationInfo');
|
exports.closeNotificationInfo = require('./closeNotificationInfo');
|
||||||
exports.getActiveElement = require('./getActiveElement');
|
exports.getActiveElement = require('./getActiveElement');
|
||||||
exports.getFormElements = require('./getFormElements');
|
exports.getFormElements = require('./getFormElements');
|
||||||
exports.getFormSubmitElements = require('./getFormSubmitElements');
|
exports.getFormSubmitElements = require('./getFormSubmitElements');
|
||||||
exports.getInputs = require('./getInputs');
|
|
||||||
exports.getTabData = require('./getTabData');
|
exports.getTabData = require('./getTabData');
|
||||||
exports.getTokenInput = require('./getTokenInput');
|
exports.getTokenInput = require('./getTokenInput');
|
||||||
exports.inputFocus = require('./inputFocus');
|
|
||||||
exports.inputToken = require('./inputToken');
|
exports.inputToken = require('./inputToken');
|
||||||
exports.isInFrame = require('./isInFrame');
|
exports.isInFrame = require('./isInFrame');
|
||||||
exports.isVisible = require('./isVisible');
|
|
||||||
exports.loadFonts = require('./loadFonts');
|
exports.loadFonts = require('./loadFonts');
|
||||||
exports.neverShowNotificationInfo = require('./neverShowNotificationInfo');
|
exports.neverShowNotificationInfo = require('./neverShowNotificationInfo');
|
||||||
exports.notification = require('./notification');
|
exports.notification = require('./notification');
|
||||||
@ -39,4 +35,3 @@ exports.openOptionsPage = require('./openOptionsPage');
|
|||||||
exports.portSetup = require('./portSetup');
|
exports.portSetup = require('./portSetup');
|
||||||
exports.showNotificationInfo = require('./showNotificationInfo');
|
exports.showNotificationInfo = require('./showNotificationInfo');
|
||||||
exports.tokenNotification = require('./tokenNotification');
|
exports.tokenNotification = require('./tokenNotification');
|
||||||
exports.updateEventListener = require('./updateEventListener');
|
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
//
|
|
||||||
// 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 browser = require('webextension-polyfill');
|
|
||||||
const { loadFromLocalStorage, saveToLocalStorage } = require('../../localStorage');
|
|
||||||
const storeLog = require('../../partials/storeLog');
|
|
||||||
const { v4: uuidv4 } = require('uuid');
|
|
||||||
|
|
||||||
const inputFocus = async (event, tabID) => {
|
|
||||||
if (!browser?.runtime?.id || !event || !event?.target) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('inputFocus', event, tabID);
|
|
||||||
|
|
||||||
let storage;
|
|
||||||
const el = event.target;
|
|
||||||
|
|
||||||
try {
|
|
||||||
storage = await loadFromLocalStorage([`tabData-${tabID}`]);
|
|
||||||
} catch (err) {
|
|
||||||
return storeLog('error', 16, err, 'inputFocus - no URL/tabID');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const tabData = storage[`tabData-${tabID}`] ? storage[`tabData-${tabID}`] : {};
|
|
||||||
|
|
||||||
if (
|
|
||||||
el?.dataset?.twofasInput?.length > 0 &&
|
|
||||||
(typeof el?.dataset?.twofasInput === 'string' || el?.dataset?.twofasInput instanceof String)
|
|
||||||
) {
|
|
||||||
tabData.lastFocusedInput = el.dataset.twofasInput;
|
|
||||||
} else {
|
|
||||||
if (typeof el?.setAttribute === 'function') {
|
|
||||||
const inputUUID = uuidv4();
|
|
||||||
el.setAttribute('data-twofas-input', inputUUID);
|
|
||||||
tabData.lastFocusedInput = inputUUID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return saveToLocalStorage({ [`tabData-${tabID}`]: tabData }, storage);
|
|
||||||
} catch (err) {
|
|
||||||
return storeLog('error', 16, err, storage[`tabData-${tabID}`]?.url);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = inputFocus;
|
|
@ -1,32 +0,0 @@
|
|||||||
//
|
|
||||||
// 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/>
|
|
||||||
//
|
|
||||||
|
|
||||||
/* global IntersectionObserver */
|
|
||||||
const isVisible = domElement => {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const o = new IntersectionObserver(([entry]) => {
|
|
||||||
resolve(entry.intersectionRatio === 1);
|
|
||||||
o.disconnect();
|
|
||||||
});
|
|
||||||
|
|
||||||
o.observe(domElement);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = isVisible;
|
|
@ -1,44 +0,0 @@
|
|||||||
//
|
|
||||||
// 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 updateEventListener = (input, func) => {
|
|
||||||
const removeListener = () => {
|
|
||||||
if (typeof input.removeEventListener === 'function') {
|
|
||||||
input.removeEventListener('focus', func);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
removeListener();
|
|
||||||
|
|
||||||
if (typeof input.addEventListener === 'function') {
|
|
||||||
input.addEventListener('focus', func);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input && input?.dataset) {
|
|
||||||
input.dataset.twofasInputListener = 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input === document.activeElement || input.matches(':focus')) {
|
|
||||||
func({ target: input });
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('onbeforeunload', removeListener, { once: true });
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = updateEventListener;
|
|
Loading…
Reference in New Issue
Block a user