Last active
December 6, 2017 14:05
-
-
Save iformas/dda30d976abc164082f4175559396888 to your computer and use it in GitHub Desktop.
Twitch Chat Filter UserScript
This file contains 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
// ==UserScript== | |
// @name Twitch Chat Filter | |
// @namespace http://myloli.moe | |
// @version 1.0 | |
// @description Chat Filter for Twitch | |
// @match http://www.twitch.tv/* | |
// @match https://www.twitch.tv/* | |
// @match http://player.twitch.tv/* | |
// @grant GM_addStyle | |
// @grant GM_getValue | |
// @grant GM_setValue | |
// @require https://code.jquery.com/jquery-3.2.1.js | |
// @copyright 2017+, iformas - Gerald | |
// ==/UserScript== | |
var chatButtonContainer; | |
var clearAllExceptTimer = null; | |
var clearAllExceptButton; | |
var waitForPageReadyTimer = setInterval(function () { | |
chatButtonContainer = $('.chat-input__buttons-container'); | |
clearAllExceptButton = $('.deactivate'); | |
if(chatButtonContainer.length > 0 && clearAllExceptButton.length===0){ | |
if(clearAllExceptTimer!== null){ | |
clearInterval(clearAllExceptTimer); | |
clearAllExceptTimer=null; | |
} | |
//clearInterval(waitForPageReadyTimer); | |
setTimeout(appendButton(), 400); | |
} | |
}, 100); | |
function appendButton() { | |
var panel = document.getElementsByClassName('chat-room__container')[0]; | |
var button = '<button class=\"tw-button deactivate\" >\r\n <span class=\"tw-button__text\" data-a-target=\"tw-button-text\">Activar Filtro<\/span>\r\n<\/button>'; | |
$('.chat-input__buttons-container').append(button); | |
} | |
$(document).on('click', '.deactivate', function(){ | |
stop(); | |
var user = prompt("Por favor, Ingrese el nombre del usuario a conservar en el log de chat:", ""); | |
if (user === null || user.trim().length===0) { | |
alert("andate a la mierda"); | |
} else { | |
setClearAllExceptTimer(user); | |
} | |
}); | |
function setClearAllExceptTimer(user){ | |
clearAllExceptTimer = setInterval(function(){ clearAllExcept(user);}, 1000); | |
} | |
function clearAllExcept(user) { | |
var mensajes = document.getElementsByClassName('chat-author__display-name'); | |
var i = 0; | |
for (i = 0; i < mensajes.length; i++) { | |
if (mensajes[i].innerText != user) { | |
mensajes[i].parentNode.parentNode.parentNode.style.display = 'none'; | |
} | |
} | |
} | |
function stop(){ | |
if(clearAllExceptTimer!== null) clearInterval(clearAllExceptTimer); | |
} |
Hatecat
commented
Dec 6, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment