// ************************************************************************* // * (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.ts'; 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 { 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 { 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();