To make the provided text analysis tool code more advanced and aesthetically pleasing, I will introduce some additional styling and a new feature: a basic reading-time estimator. This will estimate how long it might take to read the input text based on an average reading speed.
I will also add some modern design touches with additional CSS for a more polished look. Below is the updated code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Analysis Tool</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Roboto', Arial, sans-serif;
background-color: #eef1f5;
margin: 0;
padding: 20px;
text-align: center;
}
#container {
max-width: 700px;
margin: 20px auto;
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
margin-bottom: 30px;
}
#inputText {
width: 100%;
height: 150px;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
font-family: 'Roboto', Arial, sans-serif;
font-size: 16px;
resize: vertical;
box-sizing: border-box;
}
.counters {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
.counter-item {
flex: 1;
padding: 10px;
background-color: #f9f9f9;
border-radius: 5px;
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.1);
margin: 0 10px;
font-size: 18px;
color: #555;
}
#clearButton {
background-color: #4285f4;
color: #fff;
padding: 12px 25px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
#clearButton:hover {
background-color: #3079ed;
}
</style>
</head>
<body>
<div id="container">
<h1>Text Analysis Tool</h1>
<textarea id="inputText" placeholder="Type or paste your text here..."></textarea>
<div class="counters">
<div id="wordCount" class="counter-item">Words: 0</div>
<div id="charCount" class="counter-item">Characters: 0</div>
<div id="paraCount" class="counter-item">Paragraphs: 0</div>
<div id="lineCount" class="counter-item">Lines: 0</div>
<div id="readTime" class="counter-item">Read Time: 0 min</div>
</div>
<button id="clearButton" onclick="clearText()">Clear</button>
</div>
<script>
function analyzeText() {
var text = document.getElementById('inputText').value;
var wordCount = text.match(/\b[-?(\w+)?]+\b/gi);
if(wordCount) {
document.getElementById('wordCount').innerText = 'Words: ' + wordCount.length;
// Calculate estimated reading time in minutes, assuming average reading speed of 200 words per minute
var readTime = Math.ceil(wordCount.length / 200);
document.getElementById('readTime').innerText = 'Read Time: ' + readTime + ' min';
} else {
document.getElementById('wordCount').innerText = 'Words: 0';
document.getElementById('readTime').innerText = 'Read Time: 0 min';
}
var charCount = text.length;
document.getElementById('charCount').innerText = 'Characters: ' + charCount;
var paragraphs = text.replace(/\n$/, '').split(/\n/);
var paraCount = paragraphs.filter(function(paragraph) {
return paragraph.trim() !== '';
}).length;
document.getElementById('paraCount').innerText = 'Paragraphs: ' + paraCount;
var lines = text.split(/\n/);
var lineCount = lines.filter(function(line) {
return line.trim() !== '';
}).length;
document.getElementById('lineCount').innerText = 'Lines: ' + lineCount;
}
function clearText() {
document.getElementById('inputText').value = '';
analyzeText();
}
document.getElementById('inputText').addEventListener('input', analyzeText);
</script>
</body>
</html>
These enhancements accomplish a few things:
- The Google Font 'Roboto' has been included for a more modern font choice.
- The
#container now has a larger maximum width and is more centrally focused.
- The
#inputText maintains consistent padding and a more user-friendly resizable behavior.
- The counters are now displayed in a flexbox layout to spread out evenly and look more organized.
- A "Read Time" estimator has been added assuming an average reading speed of 200 words per minute.
- Text and button interactions now have better-defined shadows for depth.
You can further customize and enhance this template by adding responsive design features for better mobile-viewing compatibility, implementing more advanced text analysis, or even integrating with a backend server to persist user data and provide more features.