Shikme Markdown

Добавляет базовую разметку маркдаун в чат

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

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

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         Shikme Markdown
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Добавляет базовую разметку маркдаун в чат
// @author       You
// @match        https://shikme.ru/
// @grant        none
// ==/UserScript==

/*jshint esversion: 6 */

(function() {
    'use strict';

    const container = document.querySelector("#chat_logs_container");
    if (!container) return;



    function markdownIt(textEl) {
        let text = textEl.innerHTML;
        let newText = text.replace(/\*\*(.+)\*\*/, "<b>$1</b>");
        newText = newText.replace(/\*(.+)\*/, "<em>$1</em>");
        newText = newText.replace(/~~(.+)~~/, "<s>$1</s>");
        newText = newText.replace(/__(.+)__/, "<u>$1</u>");
        textEl.innerHTML = newText;
    }

    setTimeout(() => {
        container.querySelectorAll('.chat_message').forEach(msg => markdownIt(msg));
    }, 500);

    var mutationObserver = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            // console.log(mutation);
            if (!mutation.addedNodes.length) return;
            mutation.addedNodes.forEach(node => markdownIt(node.querySelector(".chat_message")));
        });
    });

    mutationObserver.observe(container, {
        attributes: false,
        characterData: false,
        childList: true,
        subtree: false,
        attributeOldValue: false,
        characterDataOldValue: false
    });
})();