Skip to content

Instantly share code, notes, and snippets.

@Dregu
Last active June 15, 2023 02:32
Show Gist options
  • Save Dregu/fe8e3bfd2e2957f15abe7e4c14d18de8 to your computer and use it in GitHub Desktop.
Save Dregu/fe8e3bfd2e2957f15abe7e4c14d18de8 to your computer and use it in GitHub Desktop.
Userscript to hide stupid fucking streamers or games from Twitch
// ==UserScript==
// @name Fuck Twitch
// @namespace FuckTwitch
// @description Hide stupid fucking streamers or games from Twitch
// @version 1.0
// @author Dregu
// @match https://*.twitch.tv/*
// @run-at document-start
// ==/UserScript==
var fuck = (window.localStorage.fuck ? JSON.parse(window.localStorage.fuck) : { names: ['amouranth'], games: [] })
save()
Array.from = function( arg ) {
var O = Object( arg )
var len = O.length >>> 0
var A = new Array()
var k = 0
while( k < len ) {
var kValue;
if ( k in O ) {
kValue = O[ k ]
A[ k ] = kValue
}
k++
}
return A;
}
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling)
}
function hide(name) {
if(!name) return
var el
// recommended channel
el = document.querySelector('a[data-a-target="recommended-channel"][href="/'+name+'"]')
if(el) {
el = el.parentElement.parentElement
shitBucket.appendChild(el)
}
// channel preview card, frontpage
el = document.querySelector('a[data-a-target="preview-card-image-link"][href="'+name+'"]')
if(el) {
while(Array.from(el.parentElement.classList).indexOf('tw-tower') < 0) {
el = el.parentElement
}
shitBucket.appendChild(el)
}
// channel preview card, directory
el = document.querySelector('a[data-a-target="preview-card-image-link"][href="/'+name+'"]')
if(el) {
while(Array.from(el.parentElement.classList).indexOf('tw-tower') < 0) {
el = el.parentElement
}
shitBucket.appendChild(el)
}
}
function hideGeneric() {
var el
// channel trailers, just gtfo
el = document.querySelector("div.channel-trailer-player__wrapper button")
if(el && el.textContent == "Skip Trailer") {
el.click()
}
// fucking reruns
el = document.querySelector('div.stream-type-indicator--rerun')
if(el) {
while(Array.from(el.parentElement.classList).indexOf('tw-tower') < 0) {
el = el.parentElement
}
shitBucket.appendChild(el)
}
// autoplay, fucking stupid idea
el = document.querySelector('div.front-page-carousel video')
if(el) {
el.pause()
}
}
function hideGame(name) {
if(!name) return
var el
// channel preview card, directory
el = document.querySelector('.preview-card a[href="/directory/game/'+name+'"]')
if(el) {
while(Array.from(el.parentElement.classList).indexOf('tw-tower') < 0) {
el = el.parentElement
}
shitBucket.appendChild(el)
}
}
function hideAll() {
for(var name of fuck.names) {
hide(name)
}
for(var name of fuck.games) {
hideGame(name)
}
hideGeneric()
}
function addButton() {
if(document.getElementsByClassName('fuck').length) return
var follow = document.querySelector('div.channel-header__follow-button')
if(!follow) return
console.log('adding button')
var div = document.createElement('div')
div.classList.add('tw-mg-1-1')
div.classList.add('fuck')
var button = document.createElement('button')
button.classList.add('tw-button')
var text = document.createTextNode('Fuck this streamer')
button.appendChild(text)
button.onclick = function(e) {
add(window.location.pathname.split('/')[1].toLowerCase())
}
button.style.padding = '4px'
div.appendChild(button)
var right = document.querySelector('div.channel-header__right')
console.log(right, div)
right.insertBefore(div, follow)
}
function addButtons() {
for(let link of document.querySelectorAll('[data-a-target=preview-card-channel-link]')) {
if(link.parentElement.children.length > 1) {
continue
}
var name = link.pathname.split('/')[1]
var blockLink = document.createElement('a')
blockLink.style.marginLeft = '10px'
blockLink.style.color = 'firebrick'
blockLink.dataset.name = name
blockLink.href = '#'
var text = document.createTextNode('Fuck')
blockLink.appendChild(text)
blockLink.onclick = function(e) {
e.preventDefault()
add(this.dataset.name)
}
insertAfter(blockLink, link)
if(link.parentElement.parentElement.nextSibling) {
var game = link.parentElement.parentElement.nextSibling.firstChild.firstChild
var gamename = game.pathname.split('/')[3]
var gameLink = document.createElement('a')
gameLink.style.marginLeft = '10px'
gameLink.style.color = 'firebrick'
gameLink.dataset.name = gamename
gameLink.href = '#'
var text = document.createTextNode('Fuck')
gameLink.appendChild(text)
gameLink.onclick = function(e) {
e.preventDefault()
addGame(this.dataset.name)
}
insertAfter(gameLink, game)
}
}
}
function add(name) {
fuck.names.push(name)
save()
}
function addGame(name) {
fuck.games.push(name)
save()
}
function save() {
window.localStorage.fuck = JSON.stringify(fuck)
}
setInterval(() => {
hideAll()
addButtons()
addButton()
watchForRaid()
}, 500)
var shitBucket = document.createElement('div')
www.twitch.tv##.tw-z-above.tw-relative.tw-full-width.tw-c-text.blue-bar
www.twitch.tv##.tw-tower > div:has(div.stream-type-indicator--rerun)
www.twitch.tv##.tw-tower > div:has(h3[title="Untitled Broadcast"])
www.twitch.tv##.tw-tower > div:has(div.ffz-hide-thumbnail)
www.twitch.tv##a[data-a-target="try-prime-link"]
www.twitch.tv##a[data-a-target="get-desktop-link"]
www.twitch.tv##.front-page-carousel
www.twitch.tv##.stream-type-indicator--live
www.twitch.tv##.tw-z-above.tw-relative.tw-full-width.tw-c-text-base.blue-bar
www.twitch.tv#$#.video-player__container--theatre-whispers { bottom: 0!important; }
www.twitch.tv##.whispers--theatre-mode
www.twitch.tv##.extensions-dock__dock
www.twitch.tv##.subtember-callout
www.twitch.tv##.pl-notif
www.twitch.tv##.extension-frame-wrapper
www.twitch.tv##.top-nav__prime
www.twitch.tv##.extensions-video-overlay-size-container
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment