build clean, v0.1 firefox only, pre-test

This commit is contained in:
2026-08-10 14:29:54 -03:00
parent 42638eaaf9
commit d01238a9f1
11 changed files with 1061 additions and 3 deletions

79
src/popup.ts Normal file
View File

@@ -0,0 +1,79 @@
// *************************************************************************
// * (C)opyright 2026 by Ruben Carlo Benante *
// * *
// * 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 *
// * (at your option) 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 http://www.gnu.org/licenses/. *
// * *
// * Contact author at: *
// * Ruben Carlo Benante *
// * rcb@beco.cc *
// *************************************************************************
// The manual escape hatch: fill (and optionally submit) on demand, for when
// the automatic submit is switched off, rate limited, or suppressed after a
// logout.
import { isConfigured, loadConfig, matchesSite } from './config';
const state = document.getElementById('state') as HTMLParagraphElement;
const detail = document.getElementById('detail') as HTMLParagraphElement;
const fillButton = document.getElementById('fill') as HTMLButtonElement;
const optionsButton = document.getElementById('options') as HTMLButtonElement;
optionsButton.addEventListener('click', () => {
void chrome.runtime.openOptionsPage();
});
async function activeTabOnSite(): Promise<number | null> {
const config = await loadConfig();
if (!isConfigured(config)) return null;
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (!tab?.id || !tab.url) return null;
return matchesSite(config, tab.url) ? tab.id : null;
}
async function refresh(): Promise<void> {
const config = await loadConfig();
if (!isConfigured(config)) {
state.textContent = 'Não configurado';
detail.textContent = 'Informe o endereço do portal e os três dados de acesso.';
return;
}
const tabId = await activeTabOnSite();
if (tabId === null) {
state.textContent = 'Configurado';
detail.textContent = 'Esta aba não é o portal configurado.';
return;
}
state.textContent = 'Pronto';
detail.textContent = config.autoSubmit
? 'Login automático ligado.'
: 'Login automático desligado: preencha e clique em Entrar.';
fillButton.disabled = false;
}
fillButton.addEventListener('click', () => {
void (async () => {
const tabId = await activeTabOnSite();
if (tabId === null) return;
fillButton.disabled = true;
// Fill only. Pressing "Entrar" stays with the user here, which is the
// point of a manual button.
await chrome.tabs.sendMessage(tabId, { type: 'fill', submit: false });
window.close();
})();
});
void refresh();