<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Twitch Channel Switcher</title>
</head>
<body>
<div id="status"></div>
<script>
const checkInterval = 30000; // Check every 30 seconds
async function checkTwitchStatus() {
try {
// Fetch the response from the server-side PHP script
const response = await fetch('check_twitch_status.php');
const data = await response.json();
if (data.live_channel) {
// If a live channel is found, redirect to it
window.location.href = `https://www.twitch.tv/${data.live_channel}`;
} else {
document.getElementById('status').innerText = 'No live channels found.';
}
} catch (error) {
console.error('Error fetching status:', error);
document.getElementById('status').innerText = 'Error checking status.';
}
}
// Run the function initially
checkTwitchStatus();
// Set an interval to check periodically
setInterval(checkTwitchStatus, checkInterval);
</script>
</body>
</html>