Skip to content

Instantly share code, notes, and snippets.

@iformas
Last active December 6, 2017 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iformas/dda30d976abc164082f4175559396888 to your computer and use it in GitHub Desktop.
Save iformas/dda30d976abc164082f4175559396888 to your computer and use it in GitHub Desktop.
Twitch Chat Filter UserScript
// ==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
Copy link

Hatecat commented Dec 6, 2017

// @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");
        $(".deactivate")[0].childNodes[1].innerText = "Activar Filtro";
        filtroActivo = false;
    } else {
        setClearAllExceptTimer(user);
        $(".deactivate")[0].childNodes[1].innerText = "Desactivar Filtro";
        filtroActivo = true;
    }

});

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment