event.waitUntil(checkKeywordsAndNotify());
});
async function checkKeywordsAndNotify() {
const url = 'https://hostloc.com'; // 要检测的网页URL
const keyword = '全球主机交流'; // 要检测的关键词
const telegramToken = '##'; // TG机器人Token
const chatId = '##'; //要推送的TG用户ID
try {
const urlWithTimestamp = `${url}?t=${Date.now()}`;
const response = await fetch(urlWithTimestamp, {
method: 'GET',
headers: {
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
}
});
const text = await response.text();
if (!text.includes(keyword)) {
await sendTelegramNotification(telegramToken, chatId, `关键词 "${keyword}" 已从 ${url} 上消失`);
}
} catch (error) {
await sendTelegramNotification(telegramToken, chatId, `获取或处理URL时出错: ${error.message}`);
}
}
async function sendTelegramNotification(token, chatId, message) {
const telegramUrl = `https://api.telegram.org/bot${token}/sendMessage`;
const response = await fetch(telegramUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
chat_id: chatId,
text: message
})
});
return response.json();
}[/ol]复制代码
1,无需服务器,丢进cloudflare的workers
2,设定→触发程序→Cron
可以检测传家宝是否补货,也可以检测自己的网站是不是掉线了