pIcartoRC

Add an IRC chat to picarto channels

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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