-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
210 lines (205 loc) · 5.79 KB
/
index.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html>
<html lang="en">
<head>
<title>ROT13</title>
<meta charset="utf-8" />
<meta name="description" content="A simple ROT13 decoder made with Bulma" />
<meta name="keywords" content="ROT13" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="manifest" href="/manifest.json" />
<link
rel="icon"
type="image/png"
href="https://cdn.glitch.com/099c999b-a97f-4135-919b-4d3e89217859%2Ffavicon16.png?v=1585903086782"
sizes="16x16"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css"
/>
<link
href="https://fonts.googleapis.com/css2?family=Varela+Round&display=swap"
rel="stylesheet"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bulma-tooltip@3/dist/css/bulma-tooltip.min.css"
/>
<style>
body {
font-family: "Varela Round", sans-serif;
}
.footer-dark-theme {
background-color: #363636;
color: #fff;
}
.a-dark-theme {
color: #29b6f6;
}
.a-dark-theme:hover {
background-color: #eceff1;
color: #212121;
}
</style>
</head>
<body>
<section class="hero is-dark is-fullheight">
<div class="hero-body">
<div class="container">
<h1 class="title">ROT13 encoder/decoder</h1>
<textarea
class="textarea"
id="inputField"
placeholder="Input your text here"
oninput="encode()"
onmouseover="this.focus()"
onmouseout="deselectField()"
aria-label="Input field"
></textarea>
<br />
<textarea
class="textarea"
id="outputField"
readonly
placeholder="The output will appear here"
onmouseover="selectField(this)"
onmouseout="deselectField()"
aria-label="Output field"
></textarea>
<br />
<div class="extra-margin has-text-centered">
<button
class="button is-light is-rounded has-tooltip-success"
type="button"
onclick="copyValue(this)"
onmouseout="hideTooltip(this)"
>
📋 Copy output to clipboard
</button>
<button
class="button is-light is-rounded"
type="button"
onclick="switchFields()"
>
🔃 Switch fields
</button>
<button
class="button is-light is-rounded"
type="button"
onclick="cleanFields()"
>
🗑️ Clean fields
</button>
</div>
</div>
</div>
</section>
<footer class="footer footer-dark-theme">
<div class="content has-text-centered is-dark">
<p>
<b>ROT13 Decoder</b> by
<a
href="https://github.com/ahi6"
target="_blank"
rel="noreferrer"
class="a-dark-theme"
>ahi6</a
>.
<a
href="https://glitch.com/edit/#!/rot13-decoder"
target="_blank"
rel="noreferrer"
class="a-dark-theme"
>Source code</a
>
</p>
<p>
Made with
<a
href="https://bulma.io"
target="_blank"
rel="noreferrer"
class="a-dark-theme"
>Bulma</a
>
and
<a
href="https://github.com/Wikiki/bulma-tooltip"
target="_blank"
rel="noreferrer"
class="a-dark-theme"
>Bulma-tooltip</a
>.
</p>
</div>
</footer>
</body>
<script>
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
let input,
output = "";
const inputField = document.getElementById("inputField");
const outputField = document.getElementById("outputField");
function encode() {
input = inputField.value;
input = input.split("");
output = "";
input.forEach(encodeForeach);
outputField.value = output;
}
function encodeForeach(item, index) {
let isLowercase = false;
if (item === item.toLowerCase()) {
isLowercase = true;
}
let position = alphabet.indexOf(item.toUpperCase());
if (position != -1) {
position += 13;
if (position >= alphabet.length) {
position -= alphabet.length;
}
item = alphabet[position];
}
if (isLowercase) {
item = item.toLowerCase();
}
output += item;
}
const selectField = function(element) {
element.select();
element.setSelectionRange(0, 99999);
};
const deselectField = function() {
document.activeElement.selectionStart =
document.activeElement.selectionEnd;
};
const copyValue = function(element) {
// copy to clipboard
selectField(outputField);
document.execCommand("copy");
deselectField();
showTooltip(element, "Copied!");
};
const switchFields = function() {
// switch output and input text
input = inputField.value;
output = outputField.value;
inputField.value = output;
outputField.value = input;
};
const cleanFields = function() {
// wipe all field values
inputField.value = "";
outputField.value = "";
};
const showTooltip = function(element, message) {
// shows the tooltip
element.setAttribute("data-tooltip", message);
};
const hideTooltip = function(element) {
// hides the tooltip
element.removeAttribute("data-tooltip");
};
</script>
</html>