Twitchls Dark Chat

change chat to use dark mode

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Twitchls Dark Chat
// @namespace    tampermonkey_twitchls
// @version      0.4
// @description  change chat to use dark mode
// @author       dixbutts
// @match        https://twitchls.com/*
// @grant        none
// ==/UserScript==

window.addEventListener("load", function( ) { updateEmbeddedChat( ); });
window.addEventListener("popstate", function( ) { updateEmbeddedChat( ); });

function updateEmbeddedChat( ) {
    var interVar = setInterval( function( ) {
        var iframes = document.querySelectorAll("iframe");

        for( var i = 0; i < iframes.length; ++i )
        {
            var embedSrc = iframes[ i ].getAttribute( "src" );
            var bindSrc = iframes[ i ].getAttribute( "x-bind:src" );

            if( !embedSrc || !bindSrc || !embedSrc.length || !bindSrc.length )
            {
                continue;
            }

            var findStr = '/chat?';
            var insStr = 'darkpopout';
            var embedStrPos = embedSrc.indexOf( findStr );
            var bindStrPos = bindSrc.indexOf( findStr );

            if( embedStrPos == -1 || bindStrPos == -1 )
            {
                continue;
            }

            var finalEmbedStr = embedSrc.indexOf( findStr + insStr + '&' ); // make sure darkpopout mode is not already on
            var finalBindStr = bindSrc.indexOf( findStr + insStr + '&' );

            if( finalEmbedStr != -1 || finalBindStr != -1 )
            {
                continue;
            }

            embedStrPos += findStr.length;
            bindStrPos += findStr.length;

            iframes[ i ].setAttribute( "src", embedSrc.substring( 0, embedStrPos ) + insStr + embedSrc.substring( embedStrPos ) );
            iframes[ i ].setAttribute( "x-bind:src", bindSrc.substring( 0, bindStrPos ) + insStr + bindSrc.substring( bindStrPos ) );
            clearInterval(interVar);
        }

    }, 100 );
}