Bitcointalk Post Word/Char Counter

Adds a live word, character, and estimated reading time counter to Bitcointalk reply boxes.

Versione datata 22/08/2025. Vedi la nuova versione l'ultima versione.

// ==UserScript==
// @name         Bitcointalk Post Word/Char Counter
// @namespace    Royal Cap
// @version      1.0.0
// @description  Adds a live word, character, and estimated reading time counter to Bitcointalk reply boxes.
// @match        https://bitcointalk.org/index.php?*
// @run-at       document-start
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function createCounterBox(textarea) {
        if (textarea.dataset.counterAdded) return;
        textarea.dataset.counterAdded = "1";

        const counter = document.createElement('div');
        counter.style.fontSize = '12px';
        counter.style.marginTop = '4px';
        counter.style.color = '#333';
        counter.textContent = 'Words: 0 | Characters: 0 | Reading time: 0 min';

        textarea.parentNode.insertBefore(counter, textarea.nextSibling);

        function updateCounter() {
            const text = textarea.value.trim();
            const words = text.length ? text.split(/\s+/).length : 0;
            const chars = text.length;
            const readingTime = words ? Math.ceil(words / 200) : 0; // Avg 200 words/min
            counter.textContent = `Words: ${words} | Characters: ${chars} | Reading time: ${readingTime} min`;
        }

        textarea.addEventListener('input', updateCounter);
        updateCounter();
    }

    function init() {
        document.querySelectorAll("textarea[name='message']").forEach(createCounterBox);

        // Observe for new reply boxes (like quick reply)
        const observer = new MutationObserver(() => {
            document.querySelectorAll("textarea[name='message']").forEach(createCounterBox);
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    init();
})();
长期地址
遇到问题?请前往 GitHub 提 Issues。