Add bot protection warning, 30-sec intervals, longer page wait

- Send Discord ping when 0 products found (likely bot protection)
- Allow 0.5 minute (30 second) check intervals
- Increase page wait from 5s to 10s for slow loads

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-03-24 18:11:27 -04:00
parent 4864aa3af4
commit 4fa50809dd
+47 -3
View File
@@ -40,10 +40,12 @@ chrome.alarms.onAlarm.addListener((alarm) => {
// Setup periodic alarm
function setupAlarm() {
// Chrome minimum is 0.5 minutes (30 seconds) for packed extensions
const interval = Math.max(0.5, config.checkIntervalMinutes);
chrome.alarms.create("stockCheck", {
periodInMinutes: config.checkIntervalMinutes
periodInMinutes: interval
});
console.log(`Alarm set for every ${config.checkIntervalMinutes} minute(s)`);
console.log(`Alarm set for every ${interval} minute(s) (${interval * 60} seconds)`);
}
// Load config from storage
@@ -87,6 +89,15 @@ async function runStockCheck() {
for (const url of config.urls) {
try {
const products = await fetchAndParseProducts(url);
// Alert if 0 products found - likely bot protection
if (products.length === 0) {
console.warn("WARNING: 0 products found - possible bot protection!");
await sendWarningNotification("Bot Protection Detected",
"Found 0 products - you may need to manually verify you're human on PokemonCenter.com");
continue;
}
const { newProducts, restockedProducts } = processProducts(products);
// Send notifications
@@ -147,7 +158,7 @@ async function fetchAndParseProducts(url) {
// Give extra time for dynamic content to load
console.log("Waiting for dynamic content...");
await new Promise(r => setTimeout(r, 5000));
await new Promise(r => setTimeout(r, 10000)); // 10 seconds for slow loads
// Send message to content script to extract products
let products = [];
@@ -225,6 +236,39 @@ function processProducts(products) {
return { newProducts, restockedProducts };
}
// Send warning notification (for bot protection, errors, etc.)
async function sendWarningNotification(title, message) {
if (!config.discordWebhook) {
console.log("No Discord webhook configured");
return;
}
const embed = {
title: `⚠️ ${title}`,
description: message,
color: 0xFF6600, // Orange for warnings
footer: { text: "Pokemon Stock Monitor (Chrome Extension)" },
timestamp: new Date().toISOString()
};
try {
const response = await fetch(config.discordWebhook, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
content: "@everyone",
embeds: [embed]
})
});
if (response.ok) {
console.log(`Warning notification sent: ${title}`);
}
} catch (error) {
console.error("Error sending warning notification:", error);
}
}
// Send Discord notification
async function sendDiscordNotification(product, alertType) {
if (!config.discordWebhook) {