Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
44 lines (34 loc) · 1.37 KB
/
Copy pathmain.js
File metadata and controls
44 lines (34 loc) · 1.37 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
const text = document.querySelector ("textarea");
document.getElementById ("upper-case").addEventListener ("click", function () {
text.value = text.value.toUpperCase ();
});
document.getElementById ("lower-case").addEventListener ("click", function () {
text.value = text.value.toLowerCase ();
});
document.getElementById ("proper-case").addEventListener ("click", function () {
UpperFirstChar (' ');
});
document.getElementById ("sentence-case").addEventListener ("click", function () {
UpperFirstChar ('. ');
});
document.getElementById ("save-text-file").addEventListener ("click", function () {
function download(filename, text) {
let element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// Start file download.
download("text.txt",text.value);
});
function UpperFirstChar (separator) {
let string = text.value.toLowerCase ().split (separator);
console.log (string.length);
for (let i = 0; i < string.length; i++) {
string[i] = string[i].charAt (0).toUpperCase () + string[i].substring (1);
}
text.value = string.join (separator);
}