-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDensity Checker.html
More file actions
145 lines (126 loc) · 3.88 KB
/
Copy pathDensity Checker.html
File metadata and controls
145 lines (126 loc) · 3.88 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Keyword Density Checker</title>
<link rel="icon" href="favicon.png">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f7fc;
margin: 0;
padding: 0;
text-align: center;
}
h2 {
color: #007bff;
margin-top: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.input-box {
width: 100%;
padding: 10px;
margin: 10px 0;
border-radius: 8px;
border: 1px solid #ccc;
font-size: 16px;
min-height: 100px;
resize: none;
overflow-y: auto;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border-radius: 8px;
border: none;
font-size: 16px;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background-color: #0056b3;
}
.result {
margin-top: 20px;
font-size: 18px;
color: #333;
}
.note {
margin-top: 10px;
font-size: 14px;
color: #555;
}
footer {
margin-top: 30px;
font-size: 14px;
color: #888;
}
footer a {
text-decoration: none;
color: #007bff;
}
</style>
</head>
<body>
<h2>Keyword Density Checker</h2>
<div class="container">
<label for="textInput">Enter Text:</label>
<div id="textInput" class="input-box" contenteditable="true" placeholder="Paste your text here..."></div>
<label for="keywordInput">Enter Keyword:</label>
<input type="text" id="keywordInput" class="input-box" placeholder="Enter keyword to check density">
<button id="checkButton">Check Density</button>
<div id="resultContainer" class="result" style="display:none;">
<p><strong>Keyword Density:</strong> <span id="densityResult">0</span>%</p>
<p><strong>Keyword Count:</strong> <span id="keywordCount">0</span> occurrences</p>
<p><strong>Total Word Count:</strong> <span id="totalWords">0</span> words</p>
</div>
<p class="note">This tool calculates the percentage of a given keyword in the text you provide.</p>
</div>
<footer>
<p>Designed by <a href="https://example.com" target="_blank">YourName</a></p>
</footer>
<script>
const textInput = document.getElementById('textInput');
const keywordInput = document.getElementById('keywordInput');
const checkButton = document.getElementById('checkButton');
const resultContainer = document.getElementById('resultContainer');
const densityResult = document.getElementById('densityResult');
const keywordCount = document.getElementById('keywordCount');
const totalWords = document.getElementById('totalWords');
// Function to calculate keyword density
function calculateKeywordDensity() {
const text = textInput.textContent.trim();
const keyword = keywordInput.value.trim().toLowerCase();
if (!text || !keyword) {
alert("Please enter both text and a keyword.");
return;
}
const words = text.split(/\s+/);
const totalWordCount = words.length;
let keywordCountValue = 0;
words.forEach(word => {
if (word.toLowerCase() === keyword) {
keywordCountValue++;
}
});
const density = (keywordCountValue / totalWordCount) * 100;
// Display the results
keywordCount.textContent = keywordCountValue;
totalWords.textContent = totalWordCount;
densityResult.textContent = density.toFixed(2);
resultContainer.style.display = 'block';
}
// Event listener to trigger the density calculation
checkButton.addEventListener('click', calculateKeywordDensity);
</script>
</body>
</html>