Last active
December 12, 2021 10:51
-
-
Save absindx/3d623ee42cde7bd99930beb06ad61835 to your computer and use it in GitHub Desktop.
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 theater color fix | |
// @version 0.20 | |
// @description Apply color themes in Twitch's theater mode (and channel point auto receive) | |
// @author absindx | |
// @match https://www.twitch.tv/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function setColorTheme(){ | |
// get color theme | |
// find `div[data-target="persistent-player-content"]` element | |
const divs = document.getElementsByTagName('div'); | |
let theme = null; | |
for(let i=0; i<divs.length; i++){ | |
if(divs[i].getAttribute('data-target') === 'persistent-player-content'){ | |
const elemTheme = divs[i]; | |
// find 'tw-root--theme-***' | |
for(let j=0; j<elemTheme.classList.length; j++){ | |
if(elemTheme.classList[j].indexOf('tw-root--theme-') >= 0){ | |
theme = elemTheme.classList[j]; | |
break; | |
} | |
} | |
break; | |
} | |
} | |
if(theme){ | |
// gets color theme element to set | |
const elemThemeDst = document.getElementsByTagName('html')[0]; | |
// remove theme class | |
const removeClasses = ['tw-root--theme-light', 'tw-root--theme-dark']; | |
for(let i=0; i<removeClasses.length; i++){ | |
elemThemeDst.classList.remove(removeClasses[i]); | |
} | |
elemThemeDst.classList.add(theme); | |
// TODO : change color of comment usernames... | |
// MEMO : twitch resets colors when changing | |
} | |
} | |
function autoReceiveChannelPoint(){ | |
// find `.community-points-summary button:nth-child(2)` | |
const points = document.getElementsByClassName('community-points-summary'); | |
if(points && points[0]){ | |
const buttons = points[0].getElementsByTagName('button'); | |
if(buttons && buttons[1]){ | |
const receiveButton = buttons[1]; | |
if(receiveButton){ | |
receiveButton.click(); | |
} | |
} | |
} | |
} | |
function tick(){ | |
setColorTheme(); | |
autoReceiveChannelPoint(); | |
// TODO : detect view change... | |
setTimeout(tick, 500); | |
} | |
tick(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment