Greasy Fork is available in English.

MyAnimeList(MAL) - BBCODE Editor Character Counter

This script will add a character counter to the MAL BBCODE Editor.

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         MyAnimeList(MAL) - BBCODE Editor Character Counter
// @version      1.0.4
// @description  This script will add a character counter to the MAL BBCODE Editor.
// @author       Cpt_mathix
// @match        https://myanimelist.net/*
// @grant        none
// @run-at document-body
// @namespace    https://greasyfork.org/users/16080
// ==/UserScript==

init();

function init() {
    const observer = new MutationObserver((mutations) => {
        for (const mutation of mutations) {
            if (mutation.type === 'childList') {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains('sceditor-outer')) {
                        var tabs = node.querySelector(".sceditor-tabs");
                        var textarea = node.querySelector("textarea");

                        tabs.insertAdjacentHTML("beforeend", `<li class="character-counter" style="margin-left: auto;">Character count: ${getCharCount(textarea)}</li>`);

                        textarea.addEventListener("input", (event) => {
                            var counter = event.target.closest(".sceditor-outer").querySelector(".character-counter");
                            counter.innerHTML = "Character count: " + getCharCount(event.target);
                        });
                    }
                });
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });

    var interestStackTextArea = document.getElementById("stack_description");
    if (interestStackTextArea) {
        interestStackTextArea.previousElementSibling.insertAdjacentHTML("beforeend", '<small class="character-counter" style="float: right;padding-top: 10px;">Character count: 0</small>');
        interestStackTextArea.addEventListener("input", (event) => {
            var counter = event.target.previousElementSibling.querySelector(".character-counter");
            counter.innerHTML = "Character count: " + getCharCount(event.target);
        });
    }
}

function getCharCount(textarea) {
    return textarea.value.length || 0;
}