Content Time Estimator

Estimate reading time for content.

目前為 2023-10-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Content Time Estimator
// @namespace    http://yournamespace.com/
// @version      0.1
// @description  Estimate reading time for content.
// @author       YourName
// @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);

})();