-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchar-counter.html
31 lines (31 loc) · 1.16 KB
/
char-counter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html>
<html>
<head>
<title>Character Counter</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<style>
body {background-color: #222; position: relative; left: 10px; width: 90vw; height: 90vh;}
a, div, h1, p, span {color: #fff; font-family: verdana;}
#count {margin: 16px 0px; font-size: 125%}
#text {resize: none; width: 1200px; height: 600px;}
</style>
</head>
<body>
<h1>Character Counter</h1>
<p>A simple character counter with no character limit. Word counter also included.</p>
<div id="count"></div>
<textarea id="text" placeholder="Enter Text..."></textarea>
<script>
setInterval(function() {
let chars = text.value.length;
if (chars > 0) {
words = text.value.trim().replace(/\s+/g, " ").replaceAll("\u00a0", " ").split(/ /g).length;
} else {
words = 0;
}
let lines = text.value.split(/\n/g).length;
count.innerHTML = "<b>" + chars + " characters, " + words + " words, " + lines + " lines</b>"
});
</script>
</body>
</html>