Shikme Markdown

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

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 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.

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

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