pIcartoRC

Add an IRC chat to picarto channels

Від 15.07.2020. Дивіться остання версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         pIcartoRC
// @namespace    http://tampermonkey.net/
// @version      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";
                }
            });
        }
    }
})();