Skip to main content

✅ | Word-Time-Count.php

Here's a page that can count your word and calculate the reading time.

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=0.8">
    <title>Word Count</title>
    <style>
        textarea {
            width: 25%;
            height: 125px;
            align-items: center;
            background-color: #00000055;
            border-radius: 5px;
            padding: 5px 15px
        }
        @media (max-width: 980px) {
          body {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background-color: #007eca;
          }
        }
        @media (min-width: 981px) {
          body {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background-color: #007eca;
            background-image: url("https://dl.itslittlekevin.com/projects/5069.png");
            background-repeat: no-repeat;
            background-position: right center;
            background-size: auto 100%;
          }
        }
        h1, p, h4 {
          text-shadow: 2px 2px 2px #00000055;
          align-items: center;
        }
        
        #input-container, #btn-container {
            display: flex;
            justify-content: center;
            align-items: center;
            margin-bottom: 20px;
        }
        input[type="text"] {
            color: black;
            margin: 10px;
            border-radius: 5px;
            padding: 5px 15px
        }
        * {
            color: white;
        }
        #qrcode,#btn-container {
            display: none;
        }
        button {
            font-size: 15px;
            background-color: #00325565;
            padding: 5px 15px;
            border-radius: 5px;
            border-width: 0px;
            margin: 5px;
            cursor: pointer;
        }
        #refresh-btn {
            margin-left: 10px;
        }
        /* 添加间距 */
        .spacer {
            height: 55px;
        }
        h4 a {
            text-decoration: none;
        }
    </style>
</head>
<body>
    <h1 align=center>字数统计<br>Word Count Tool</h1>
    <textarea id="textInput" placeholder="Enter your text here..."></textarea><br>
    <p><button onclick="countWords()">计算 | Calculate</button><button onclick="clearText()">清空 | Clear</button></p>
    <p>字数 | Word count: <span id="wordCount">0</span></p>
    <p>阅读时间 | Reading time: <span id="readingTime">0</span>min</p>
    <script>
        function countWords() {
            var text = document.getElementById('textInput').value;
            // This regex matches any ASCII word or any Unicode character
            var regex = /[\w]+|[\u00ff-\uffff]/g;
            var matches = text.match(regex);
            var wordCount = matches ? matches.length : 0;
            document.getElementById('wordCount').innerText = wordCount;
            var readingSpeed = 255; // Average reading speed in words per minute
            var readingTime = Math.ceil(wordCount / readingSpeed); // Reading time in minutes
            document.getElementById('readingTime').innerText = readingTime;
        }

        function clearText() {
            document.getElementById('textInput').value = '';
            document.getElementById('wordCount').innerText = '0';
        }
    </script>
</body>
</html>