Twitchls Dark Chat

change chat to use dark mode

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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