Counter

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

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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