-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWord Filtering.html
More file actions
178 lines (153 loc) · 4.52 KB
/
Word Filtering.html
File metadata and controls
178 lines (153 loc) · 4.52 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html>
<head>
<title>Word Filtering</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
border-radius: 5px;
box-sizing: border-box;
}
h1 {
text-align: center;
margin-top: 0;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input[type="file"],
input[type="number"],
input[type="text"] {
width: 100%;
padding: 8px;
border-radius: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
width: 100%;
margin-top: 20px;
}
button:disabled {
background-color: #ccc;
cursor: not-allowed;
}
#result {
margin-top: 20px;
background-color: #f9f9f9;
padding: 10px;
border-radius: 5px;
}
p {
margin: 0;
padding: 5px 0;
}
.download-button-container {
text-align: center;
margin-top: 20px;
}
.download-button {
display: inline-block;
background-color: #008CBA;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
text-decoration: none;
cursor: pointer;
}
.download-button:hover {
background-color: #005c7a;
}
</style>
<script>
function filterWords() {
var fileInput = document.getElementById("fileInput");
var positionInput = document.getElementById("positionInput").value;
var characterInput = document.getElementById("characterInput").value;
var filteredWords = [];
if (fileInput.files.length > 0) {
var file = fileInput.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var words = e.target.result.split(/\s+/);
for (var i = 0; i < words.length; i++) {
var word = words[i].trim();
if (word.length >= positionInput && word.charAt(positionInput - 1) === characterInput) {
filteredWords.push(word);
}
}
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "";
for (var j = 0; j < filteredWords.length; j++) {
var p = document.createElement("p");
p.textContent = filteredWords[j];
resultDiv.appendChild(p);
}
var downloadButton = document.getElementById("downloadButton");
if (filteredWords.length > 0) {
downloadButton.style.display = "inline-block";
} else {
downloadButton.style.display = "none";
}
};
reader.readAsText(file);
}
}
function downloadFile() {
var filteredWords = [];
var resultDiv = document.getElementById("result");
var resultParagraphs = resultDiv.getElementsByTagName("p");
for (var i = 0; i < resultParagraphs.length; i++) {
filteredWords.push(resultParagraphs[i].textContent);
}
var blob = new Blob([filteredWords.join("\n")], { type: "text/plain" });
var url = URL.createObjectURL(blob);
var a = document.createElement("a");
a.href = url;
a.download = "filtered_words.txt";
a.style.display = "none";
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
URL.revokeObjectURL(url);
}, 0);
}
</script>
</head>
<body>
<div class="container">
<h1>Word Filtering</h1>
<label for="fileInput">Choose a File:</label>
<input type="file" id="fileInput" accept=".txt">
<label for="positionInput">Character Position:</label>
<input type="number" id="positionInput">
<label for="characterInput">Target Character:</label>
<input type="text" id="characterInput">
<button onclick="filterWords()">Filter</button>
<div id="result"></div>
<div class="download-button-container">
<a href="#" class="download-button" id="downloadButton" onclick="downloadFile()" style="display: none">Download</a>
</div>
</div>
</body>
</html>