// ==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 // @downloadURL 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 = `
`; const ircChatEmbbedStr = ` ` 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"; } }); } } })();