fix: background.js, remove: unnecessary permissions
This commit is contained in:
@@ -4,15 +4,12 @@
|
||||
"version": "4.0",
|
||||
"description": "Rellena automáticamente el código 2FA en la Universidad de Sevilla.",
|
||||
"permissions": [
|
||||
"activeTab",
|
||||
"scripting",
|
||||
"tabs",
|
||||
"storage"
|
||||
],
|
||||
"background": {
|
||||
"service_worker": "background.js",
|
||||
"service_worker": "scripts/background.js",
|
||||
"type": "module",
|
||||
"scripts": ["background.js"]
|
||||
"scripts": ["scripts/background.js"]
|
||||
},
|
||||
"action": {
|
||||
"default_popup": "index.html"
|
||||
@@ -22,9 +19,9 @@
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["https://sso.us.es/*"],
|
||||
"matches": ["*://sso.us.es/*"],
|
||||
"js": ["scripts/content.js"],
|
||||
"run_at": "document_start"
|
||||
"run_at": "document_idle"
|
||||
}
|
||||
],
|
||||
"host_permissions": [
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import * as OTPAuth from 'otpauth';
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
const api = typeof browser !== "undefined" ? browser : chrome;
|
||||
|
||||
api.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
||||
if (request.action === "GENERATE_TOKEN") {
|
||||
api.storage.local.get(['shasecret'], (data) => {
|
||||
if (data.shasecret) {
|
||||
const totp = new OTPAuth.TOTP({
|
||||
issuer: 'US',
|
||||
label: '2FA',
|
||||
algorithm: 'SHA1',
|
||||
digits: 6,
|
||||
period: 30,
|
||||
secret: OTPAuth.Secret.fromBase32(data.shasecret.trim().toUpperCase()),
|
||||
});
|
||||
sendResponse({ token: totp.generate() });
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -1,39 +0,0 @@
|
||||
(async function() {
|
||||
// eslint-disable-next-line no-undef
|
||||
const api = typeof browser !== "undefined" ? browser : chrome;
|
||||
|
||||
const fillCode = (code) => {
|
||||
const input = document.getElementById("input2factor");
|
||||
const button = document.getElementById('btn-login') || document.querySelector("#notification_2factor_button_ok");
|
||||
const error = document.querySelector("#otp_authn_wrong_code")?.offsetHeight > 0;
|
||||
|
||||
if (!input || error) return;
|
||||
|
||||
input.value = code;
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
|
||||
setTimeout(() => {
|
||||
if (button) button.click();
|
||||
}, 200);
|
||||
console.log("Autofill");
|
||||
};
|
||||
|
||||
api.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
if (request.action === "autofill") {
|
||||
fillCode(request.code);
|
||||
sendResponse({ status: "ok" });
|
||||
}
|
||||
});
|
||||
|
||||
const data = await api.storage.local.get(['shasecret']);
|
||||
if (data.shasecret) {
|
||||
const input = document.getElementById("input2factor");
|
||||
if (input && input.value.length === 0) {
|
||||
api.runtime.sendMessage({ action: "GENERATE_TOKEN" }, response => {
|
||||
if (response?.token) {
|
||||
fillCode(response.token);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user