Created
February 8, 2022 19:00
-
-
Save jonmircha/07e9fdfc68b3ca985714d896eef44bef to your computer and use it in GitHub Desktop.
Código para la rifa de los 100ks en el canal de YouTube
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Selector del comentario: ytd-comment-thread-renderer | |
//Selector del nombre usuario: ytd-comment-thread-renderer #author-text span | |
//Selector del texto comentario: ytd-comment-thread-renderer yt-formatted-string#content-text | |
const rifarMicro = () => { | |
const d = document, | |
$comentarios = d.querySelectorAll("ytd-comment-thread-renderer"); | |
const participantes = []; | |
$comentarios.forEach(el => participantes.push({ | |
nombre: el.querySelector("#author-text span").textContent.trim(), | |
comentario: el.querySelector("yt-formatted-string#content-text").textContent.trim() | |
})); | |
console.log("PARTICIPANTES"); | |
console.log(participantes); | |
const depurados = participantes.reduce((acc, participante) => { | |
acc[participante.nombre] = ++acc[participante.nombre] || 1; | |
return acc; | |
}, {}); | |
console.log("DEPURADOS"); | |
console.log(depurados); | |
const duplicados = participantes.filter((participante) => { | |
return depurados[participante.nombre] !== 1; | |
}); | |
console.log("DUPLICADOS"); | |
console.log(duplicados); | |
const unicos = participantes.filter((participante) => { | |
return depurados[participante.nombre] === 1; | |
}); | |
console.log("ÚNICOS"); | |
console.log(unicos); | |
let aleatorio = Math.floor(Math.random() * unicos.length), | |
ganador = unicos[aleatorio]; | |
console.log(`😱El ganador del micrófono es...😱`); | |
setTimeout(() => { | |
console.log(`🥳🎉${ganador.nombre}🎉🥳`); | |
console.log(`📝Su comentario fue...📝`); | |
console.log(`🌟✨${ganador.comentario}✨🌟`); | |
}, 10000); | |
} | |
rifarMicro(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment