Twitchls Dark Chat

change chat to use dark mode

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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 );
}