Content Time Estimator

Estimate reading time for content.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Content Time Estimator
// @namespace    http://yournamespace.com/
// @version      0.2
// @description  Estimate reading time for content.
// @author       icycoldveins
// @include      *://*/*
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Style for the reading time box
    GM_addStyle(`
        #reading-time-box {
            position: fixed;
            bottom: 10px;
            right: 10px;
            padding: 5px 10px;
            background-color: #000;
            color: #FFF;
            border-radius: 5px;
            font-size: 14px;
            z-index: 10000;
            display: none;
        }
    `);

    const estimateReadingTime = () => {
        // Grab all the paragraphs on the page
        let paragraphs = document.querySelectorAll('p');
        let totalWords = 0;

        paragraphs.forEach(paragraph => {
            totalWords += paragraph.innerText.split(' ').length;
        });

        // Average reading speed is roughly 200-250 words per minute
        let readingTime = Math.ceil(totalWords / 225);
        return readingTime;
    };

    const displayReadingTime = () => {
        let readingTime = estimateReadingTime();

        if (readingTime > 1) { // Show the estimator only if reading time is more than a minute
            let timeBox = document.createElement('div');
            timeBox.id = 'reading-time-box';
            timeBox.innerHTML = `Estimated Reading Time: ${readingTime} mins`;
            document.body.appendChild(timeBox);
            timeBox.style.display = 'block';
        }
    };

    window.addEventListener('load', displayReadingTime);

})();