-
Notifications
You must be signed in to change notification settings - Fork 1
/
string_case_changer.html
81 lines (81 loc) · 2.77 KB
/
string_case_changer.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
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
<div class="supertool">
<style>
.supertool textarea{
white-space: pre;
overflow: auto;
border: solid #ddd 2px;
width: 100%;
}
.supertool a, .supertool button {
background-color: #d0d0d0;
border: none;
color: #5b5b57 !important;
padding: 10px 8px;
text-align: center;
text-decoration: none;
display: inline-block;
cursor: pointer;
margin-top: 2px;
margin-bottom: 2px;
font-size: 14px;
}
.supertool a:hover, .supertool button:hover{
background-color: #757575;
color: #fff !important;
}
</style>
<div class="col-md-12">
<div>
<label><input type="radio" name="case" value="U" checked> Upper Case</label>
<label><input type="radio" name="case" value="L"> Lower Case</label>
</div>
<textarea autocomplete="off" id="string" cols="80" rows="10" name="string" placeholder="Enter your text..." spellcheck="true"></textarea><br>
<button type="button" id="convert" name="convert" value="convert">Convert</button>
<button type="button" name="reload" onclick="location.reload()" value="reload">Reload</button>
</div>
<div class="col-md-12">
<textarea autocomplete="off" id="result" cols="80" rows="10" name="code" placeholder="Result..." readonly></textarea><br>
<button type="button" id="copy" name="copy" value="Copy">Copy</button>
<a type="button" id="download" name="download" >Download</a>
<span id="status" ></span>
</div>
<script>
const converter = document.querySelector('#convert');
converter.addEventListener("click", function () {
var stringCase = document.querySelector("input[name=case]:checked");
var string = document.querySelector('#string'), result = document.querySelector('#result'), data;
if (stringCase.value == 'L') {
data = string.value.toLowerCase();
} else {
data = string.value.toUpperCase()
}
result.value = data;
});
const copy = document.querySelector('#copy');
copy.addEventListener("click", function() {
elm=document.querySelector("#result");
elm.select();
elm.setSelectionRange(0,99999);
document.execCommand('copy');
});
const download = document.querySelector('#download');
download.addEventListener("click", function () {
var stringCase = document.querySelector("input[name=case]:checked");
var string = document.querySelector('#string'), data, file;
if (stringCase.value == 'L') {
data = string.value.toLowerCase();
this.download='lowercase_text.txt'; //download
} else {
this.download='uppercase_text.txt'; //download
data = string.value.toUpperCase()
}
file = data;
var blobData = new Blob([file], {type: 'text/plain'});
var url = window.URL.createObjectURL(blobData);
this.href = url;
});
const superTools = {
title: "Upper Case and Lower Case converter"
};
</script>
</div>