Время на прочтение статьи LZT

Добавляет время прочтения статьи на форуме

// ==UserScript==
// @name         Время на прочтение статьи LZT
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Добавляет время прочтения статьи на форуме
// @match        https://zelenka.guru/*
// @match        https://lolz.live/*
// @match        https://lolz.guru/*
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function isInRequiredSection() {
        const breadcrumbs = Array.from(document.querySelectorAll('.breadcrumb .crust a.crumb span[itemprop="name"]')).map(crumb => crumb.textContent.trim());
        return breadcrumbs.includes("Форум") && breadcrumbs.some(crumb => crumb === "Статьи");
    }

    if (!isInRequiredSection()) {
        return;
    }

    function calculateReadingTime() {
        let text = '';
        if (document.querySelector('blockquote.messageText')) {
            text += document.querySelector('blockquote.messageText').textContent + ' ';
        }
        document.querySelectorAll('.SpoilerTarget').forEach(spoiler => {
            text += spoiler.textContent + ' ';
        });
        const words = text.split(/\s+/).filter(Boolean).length;
        const readingSpeed = 200; // Средняя скорость чтения слов в минуту
        return Math.ceil(words / readingSpeed);
    }

    function addReadingTimeToPage(readingTime) {
        const pageDescription = document.getElementById("pageDescription");
        const mutedDiv = document.querySelector('.muted');
        const targetContainer = pageDescription || mutedDiv;

        if (!targetContainer) {
            console.error('Место для вставки информации о времени чтения не найдено.');
            return;
        }

        const readingTimeElement = document.createElement("div");
        readingTimeElement.innerHTML = `Время на прочтение: ${readingTime} минут(ы)`;
        readingTimeElement.style.marginTop = "10px";

        targetContainer.insertAdjacentElement('afterend', readingTimeElement);
    }

    window.addEventListener('load', () => {
        const readingTime = calculateReadingTime();
        addReadingTimeToPage(readingTime);
    });
})();