pIcartoRC

Add an IRC chat to picarto channels

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         pIcartoRC
// @namespace    https://wolvan.at/
// @version      1.1.1
// @description  Add an IRC chat to picarto channels
// @author       Wolvan
// @match        https://picarto.tv/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function createElementFromHTML(htmlString) {
        var div = document.createElement('div');
        div.innerHTML = htmlString.trim();

        // Change this to div.childNodes to support multiple top-level nodes
        return div.firstChild;
    }

    const ircBtnStr = `
        <div class="headingBtns ml-1" data-marker-type="irc" title="IRC" data-i18n="[title]chat.titles.irc" data-original-title="IRC">
            <i class="fas fa-fw fa-hashtag headerTabBtn clickThru" id="irc-fa">
                <div class="marker" id="markerIRC" style="display: none;"></div>
            </i>
        </div>
    `;

    const ircChatEmbbedStr = `
        <div class="scrollwrapperirc bg-dark functionsMenu ps ps--theme_default" id="irc-chat" data-perfectbar="" style="display: none;width:100%;height:100%;z-index:100">
            <iframe src="https://kiwiirc.com/client/irc.rizon.net/?&theme=cli#picartorc_%%CHANNEL" style="border:0; width:100%; height:100%;"></iframe>
        </div>
	`

    if (!document.querySelector("#irc-fa")) {
        const channelName = window.location.href.match(/picarto.tv\/([a-zA-Z0-9]*)\/?/)[1];
        const ircChat = createElementFromHTML(ircChatEmbbedStr.replace(/%%CHANNEL/g, channelName.toLowerCase()));
        document.querySelector("#mainContainer").append(ircChat);

        const ircBtn = createElementFromHTML(ircBtnStr);
        const headerBar = document.querySelector("#chatHeader > span.ml-auto.d-flex");
        headerBar.append(ircBtn);
        for (let el of headerBar.querySelectorAll(".headingBtns")) {
            el.addEventListener("click", function (e) {
                if (e.target === ircBtn) {
                    ircBtn.querySelector(".marker").style.display = "block";
                    ircChat.style.display = "block";
                } else {
                    ircBtn.querySelector(".marker").style.display = "none";
                    ircChat.style.display = "none";
                }
            });
        }
    }
})();