Counter

Показывает количество символов и слов в текстовом поле

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

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 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         Counter
// @icon         https://www.google.com/s2/favicons?domain=shikimori.me
// @namespace    https://shikimori.one
// @version      2.0
// @description  Показывает количество символов и слов в текстовом поле
// @author       LifeH
// @match        *://shikimori.org/*
// @match        *://shikimori.one/*
// @match        *://shikimori.me/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  "use strict";

  function addCounter(textarea) {
    if (textarea.next("#Counter").length === 0) {
      let counter = $(
        '<div id="Counter" style="position: absolute; right: 5px; bottom: 15px; font-size: 12px; color: gray;"></div>'
      );
      textarea.after(counter);

      textarea.on("input", function () {
        let text = textarea.val().replace(/(\r\n|\n|\r)/g, "  ");
        let charCount = text.length;
        let wordCount = textarea[0].value.trim().split(/\s+/).filter(Boolean).length;

        counter.text(`Символов: ${charCount} | Слов: ${wordCount}`);
      });

      textarea.trigger("input");
    }
  }

  function observeAreas() {
    let areas = [
      $('textarea[name="review[body]"]'),
      $('textarea[name="comment[body]"]'),
      $('textarea[name="critique[text]"]'),
      $('textarea[name="club[description]"]'),
      $('textarea[name="club_page[text]"]'),
      $('textarea[name="message[body]"]'),
      $('textarea[name="article[body]"]'),// добавил "article[body]"
      $('textarea[name="anime[description_ru_text]"]'),// добавил "anime[description_ru_text]"
      $('textarea[name="anime[description_en_text]"]'),// добавил "anime[description_en_text]"
      $('textarea[name="reason"]'),// добавил "reason"
      $('textarea[name="character[description_en_text]"]'),// добавил "character[description_en_text]"
      $('textarea[name="character[description_ru_text]"]'),// добавил "character[description_ru_text]"
      $('textarea[name="manga[description_ru_text]"]'),// добавил "manga[description_en_text]"
      $('textarea[name="manga[description_en_text]"]'),// добавил "manga[description_ru_text]"

      $('textarea[name="collection[text]"]')// добавил "collection[text]"

    ];

    areas.forEach(function (textarea) {
      if (textarea.length && textarea.next("#Counter").length === 0) {
        addCounter(textarea);
      }
    });
  }

  $(document).on("input", function () {
    observeAreas();
  });
})();