Files
pokemon-stock-checker/chrome-extension/popup.js
T
mmcghen d03f963e7b Allow check intervals as low as 10 seconds
- Switch from Chrome alarms (30s min) to setTimeout loops
- Config now uses checkIntervalSeconds instead of minutes
- Default: 15 seconds, minimum: 10 seconds
- Prevents overlapping checks with isChecking flag
- Updated popup UI to show seconds

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-24 18:24:38 -04:00

76 lines
2.9 KiB
JavaScript

// Pokemon Stock Monitor - Popup Script
document.addEventListener("DOMContentLoaded", async () => {
// Load current config
const config = await chrome.runtime.sendMessage({ type: "getConfig" });
const stats = await chrome.runtime.sendMessage({ type: "getStats" });
// Populate form
document.getElementById("webhook").value = config.discordWebhook || "";
document.getElementById("urls").value = (config.urls || []).join("\n");
document.getElementById("keywords").value = (config.keywords || []).join(", ");
document.getElementById("interval").value = config.checkIntervalSeconds || 15;
document.getElementById("enabled").checked = config.enabled !== false;
document.getElementById("notifyNew").checked = config.notifyNewProducts !== false;
document.getElementById("notifyRestock").checked = config.notifyRestocks !== false;
// Update stats
document.getElementById("productCount").textContent = stats.totalProducts || 0;
updateStatus(stats.enabled !== false);
// Save button
document.getElementById("saveBtn").addEventListener("click", async () => {
const urlsText = document.getElementById("urls").value;
const keywordsText = document.getElementById("keywords").value;
const newConfig = {
discordWebhook: document.getElementById("webhook").value.trim(),
urls: urlsText.split("\n").map(u => u.trim()).filter(u => u),
keywords: keywordsText.split(",").map(k => k.trim()).filter(k => k),
checkIntervalSeconds: parseInt(document.getElementById("interval").value) || 15,
enabled: document.getElementById("enabled").checked,
notifyNewProducts: document.getElementById("notifyNew").checked,
notifyRestocks: document.getElementById("notifyRestock").checked
};
await chrome.runtime.sendMessage({ type: "saveConfig", config: newConfig });
updateStatus(newConfig.enabled);
showSaved();
});
// Check Now button
document.getElementById("checkNowBtn").addEventListener("click", async () => {
await chrome.runtime.sendMessage({ type: "runCheck" });
showSaved("Check started!");
});
// Clear button
document.getElementById("clearBtn").addEventListener("click", async () => {
if (confirm("Clear all tracked products? This will treat all products as new on next check.")) {
await chrome.runtime.sendMessage({ type: "clearProducts" });
document.getElementById("productCount").textContent = "0";
showSaved("History cleared!");
}
});
});
function updateStatus(enabled) {
const dot = document.getElementById("statusDot");
const text = document.getElementById("statusText");
if (enabled) {
dot.className = "status-dot active";
text.textContent = "Active";
} else {
dot.className = "status-dot inactive";
text.textContent = "Disabled";
}
}
function showSaved(msg = "Settings saved!") {
const el = document.getElementById("savedMsg");
el.textContent = msg;
el.classList.add("show");
setTimeout(() => el.classList.remove("show"), 2000);
}