-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.html
More file actions
71 lines (64 loc) · 2.22 KB
/
Copy pathIndex.html
File metadata and controls
71 lines (64 loc) · 2.22 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Word Cloud</title>
<link rel="stylesheet" href="css/site.css"> <!-- Link to CSS if exists -->
</head>
<body>
<h1>CSM WordCloud</h1>
<p>Anyone with this URL can enter words to generate a unique word cloud. You can also download or reset the word cloud below.</p>
<h2>Add a Word</h2>
<input type="text" id="wordInput" placeholder="Enter a word">
<button onclick="addWord()">Add Word</button>
<h2>Current Word Cloud</h2>
<ul id="wordList"></ul>
<script>
async function addWord() {
const word = document.getElementById('wordInput').value;
if (word) {
try {
const response = await fetch('/api/Word/add-word', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(word)
});
if (response.ok) {
document.getElementById('wordInput').value = '';
fetchWordCloud();
} else {
console.error('Failed to add word');
}
} catch (error) {
console.error('Error:', error);
}
} else {
alert('Please enter a word.');
}
}
async function fetchWordCloud() {
try {
const response = await fetch('/api/Word/generate-wordcloud');
if (response.ok) {
const wordCloud = await response.json();
const wordList = document.getElementById('wordList');
wordList.innerHTML = '';
wordCloud.words.forEach(wordEntry => {
const li = document.createElement('li');
li.innerText = `${wordEntry.word}: ${wordEntry.frequency}`;
wordList.appendChild(li);
});
} else {
console.error('Failed to fetch word cloud');
}
} catch (error) {
console.error('Error:', error);
}
}
window.onload = fetchWordCloud;
</script>
</body>
</html>