Mudanças entre as edições de "Widget:Twitch"
Ir para navegação
Ir para pesquisar
Linha 1: | Linha 1: | ||
<div id="streamers-ativos"> | <div id="streamers-ativos"> | ||
< | <!-- Streamers aparecerão aqui --> | ||
</div> | </div> | ||
Linha 7: | Linha 6: | ||
const clientId = '3cqgn6bg1ts9bm3pahx51aiivs2u3d'; // Seu Client ID | const clientId = '3cqgn6bg1ts9bm3pahx51aiivs2u3d'; // Seu Client ID | ||
const accessToken = 'v86kvw6tyfvrzv8hkti27ddt21ydjf'; // Seu Access Token | const accessToken = 'v86kvw6tyfvrzv8hkti27ddt21ydjf'; // Seu Access Token | ||
const streamers = ['sayurimei', 'apolotfg', 'Yoshimitsuccs | const streamers = ['sayurimei', 'apolotfg', 'Yoshimitsuccs']; // Lista dos streamers | ||
async function fetchActiveStreamers() { | async function fetchActiveStreamers() { | ||
Linha 28: | Linha 27: | ||
.filter((stream) => stream !== null) // Filtra apenas os streamers ativos | .filter((stream) => stream !== null) // Filtra apenas os streamers ativos | ||
.filter((stream) => /GLA/i.test(stream.title)); // Verifica se o título contém "GLA" (case insensitive) | .filter((stream) => /GLA/i.test(stream.title)); // Verifica se o título contém "GLA" (case insensitive) | ||
// Atualiza o HTML com os streamers ativos que têm "GLA" no título | // Atualiza o HTML com os streamers ativos que têm "GLA" no título | ||
Linha 34: | Linha 32: | ||
if (activeStreamers.length > 0) { | if (activeStreamers.length > 0) { | ||
container.innerHTML = activeStreamers.map((stream) => ` | container.innerHTML = activeStreamers.map((stream) => ` | ||
<div class="streamer"> | <div class="streamer" id="streamer-${stream.user_name}"> | ||
<h3>${stream.user_name}</h3> | <h3>${stream.user_name}</h3> | ||
<p>${stream.title}</p> | <p>${stream.title}</p> | ||
Linha 48: | Linha 46: | ||
`).join(''); | `).join(''); | ||
} else { | } else { | ||
container.innerHTML = ' | container.innerHTML = ''; // Deixa vazio se nenhum streamer ativo for encontrado | ||
} | } | ||
} catch (error) { | } catch (error) { | ||
console.error('Erro ao buscar streamers:', error); | console.error('Erro ao buscar streamers:', error); | ||
document.getElementById('streamers-ativos').innerHTML = ' | document.getElementById('streamers-ativos').innerHTML = ''; // Deixa vazio em caso de erro | ||
} | } | ||
} | } | ||
fetchActiveStreamers(); | // Atualiza os streamers ativos periodicamente (a cada 1 minuto) | ||
fetchActiveStreamers(); // Chamada inicial | |||
setInterval(fetchActiveStreamers, 60000); // Atualiza a cada 60 segundos | |||
</script> | </script> | ||
Linha 80: | Linha 80: | ||
} | } | ||
</style> | </style> | ||
Edição das 14h35min de 28 de dezembro de 2024
<script>
const clientId = '3cqgn6bg1ts9bm3pahx51aiivs2u3d'; // Seu Client ID const accessToken = 'v86kvw6tyfvrzv8hkti27ddt21ydjf'; // Seu Access Token const streamers = ['sayurimei', 'apolotfg', 'Yoshimitsuccs']; // Lista dos streamers
async function fetchActiveStreamers() { try { const headers = { 'Client-ID': clientId, 'Authorization': `Bearer ${accessToken}` };
// Fazer requisições para todos os streamers const streamerRequests = streamers.map(async (streamer) => { const response = await fetch(`https://api.twitch.tv/helix/streams?user_login=${streamer}`, { headers }); const data = await response.json(); return data.data.length > 0 ? data.data[0] : null; // Retorna o streamer se estiver ativo });
// Aguarda todas as requisições serem concluídas const results = await Promise.all(streamerRequests); const activeStreamers = results .filter((stream) => stream !== null) // Filtra apenas os streamers ativos .filter((stream) => /GLA/i.test(stream.title)); // Verifica se o título contém "GLA" (case insensitive)
// Atualiza o HTML com os streamers ativos que têm "GLA" no título const container = document.getElementById('streamers-ativos'); if (activeStreamers.length > 0) { container.innerHTML = activeStreamers.map((stream) => `
${stream.user_name}
${stream.title}
<iframe src="https://player.twitch.tv/?channel=${stream.user_name}&parent=wiki.gla.com.br" height="300" width="400" frameborder="0" scrolling="no" allowfullscreen="true"> </iframe>
`).join(); } else { container.innerHTML = ; // Deixa vazio se nenhum streamer ativo for encontrado } } catch (error) { console.error('Erro ao buscar streamers:', error); document.getElementById('streamers-ativos').innerHTML = ; // Deixa vazio em caso de erro } }
// Atualiza os streamers ativos periodicamente (a cada 1 minuto) fetchActiveStreamers(); // Chamada inicial setInterval(fetchActiveStreamers, 60000); // Atualiza a cada 60 segundos
</script>
<style>
#streamers-ativos { display: flex; flex-wrap: wrap; gap: 20px; } .streamer { border: 1px solid #ccc; padding: 10px; background: #f9f9f9; border-radius: 5px; text-align: center; } .streamer h3 { margin: 0 0 10px; } .streamer p { margin: 0 0 10px; color: #666; }
</style>