Greasy Fork

Greasy Fork is available in English.

Picarto Markup

Enable markups in Picarto chats

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Picarto Markup
// @description Enable markups in Picarto chats
// @include     *//picarto.tv/*
// @version     1
// @grant       none
// @license     MIT
// @namespace http://greasyfork.icu/users/184200
// ==/UserScript==

function markup(str) {

	var matches = ("i>" + str).match(/[a|i|"|n]>(.*?)(?=<)/gm);
	var nonmatches = str.match(/<(.*?)(?=[a|i|"|n]>)/gm);

    var star = /\*(\S(.*?\S)?)\*/gm;
	var double_star = /\*\*(\S(.*?\S)?)\*\*/gm;
	var undersc = /\_(\S(.*?\S)?)\_/gm;
	var double_undersc = /\_\_(\S(.*?\S)?)\_\_/gm;
	var tilde = /\~(\S(.*?\S)?)\~/gm;
	var double_tilde = /\~\~(\S(.*?\S)?)\~\~/gm;

	matches[0] = matches[0].substring(2);

	var newstring = "";

	for (i = 0; i < matches.length; i++) {
        if( !(i+1<matches.length && matches[i+1].startsWith("a")) ) {
            matches[i] = matches[i].replace(double_star, '<b>$1</b>');
            matches[i] = matches[i].replace(double_undersc, '<u>$1</u>');
            matches[i] = matches[i].replace(star, '<i>$1</i>');
            matches[i] = matches[i].replace(undersc, '<i>$1</i>');
            matches[i] = matches[i].replace(double_tilde, '<s>$1</s>');
        }
        newstring = newstring + matches[i] + nonmatches[i];
	}

    newstring += "n>";
    return newstring;
}

$(document).ready(() => {
    let targetNode = document.getElementById("chatContainer");
    let options = {childList:true,subtree:true};
    let observer = new MutationObserver((mutationList)=>{
        let msgs = document.getElementsByClassName("theMsg");
        for(let a = msgs.length-1; a >= 0; a--){
            let m = msgs[a];
            if(!m.classList.contains("MarkUp")){
                m.classList.add("MarkUp");
                m.innerHTML = markup(m.innerHTML);
            }
        }
    });
    observer.observe(targetNode, options);
});