zikaeroh / Twitch legacy chat replacement

// ==UserScript==
// @namespace     https://openuserjs.org/users/zikaeroh
// @name          Twitch legacy chat replacement
// @description   Replaces the Twitch chat sidebar with the legacy popout
// @copyright     2017, zikaeroh (https://openuserjs.org/users/zikaeroh)
// @license       MIT
// @version       1.3.1
// @include       https://www.twitch.tv/*
// @grant none
// ==/UserScript==

// ==OpenUserJS==
// @author zikaeroh
// ==/OpenUserJS==

(function () {
    function replaceChat() {
        var retryCount = 0;

        var splitPath = window.location.pathname.split('/');

        var sleepTime = splitPath.slice(-1)[0] == "dashboard" ? 500 : 5000;

        var existCondition = setInterval(function () {
            var classes = [
                "chat-room__container",
                "channel-page__right-column"
            ];
            
            var found;
          
            for (var i = 0; i < classes.length; i++) {
                found = document.getElementsByClassName(classes[i]);
                if (found.length) {
                    break;
                }
            }

            if (found.length) {
                clearInterval(existCondition);
                var path = splitPath.slice(0, 2).join('/');
                found[0].innerHTML = '<iframe style="height: 100% !important" src="https://www.twitch.tv' + path + '/chat"/>';
                return;
            }

            retryCount++;

            if (retryCount > 10) {
                clearInterval(existCondition);
            }
        }, sleepTime);
    }

    window.addEventListener("unload", function() {
        setTimeout(replaceChat, 300);
    });

    replaceChat();
})();