-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
266 lines (236 loc) · 8.52 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!doctype html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SQL List Converter</title>
<link rel="icon" href="data:image/svg+xml;utf8,<svg height='21' viewBox='0 0 21 21' width='21' xmlns='http://www.w3.org/2000/svg'><g fill='none' fill-rule='evenodd' transform='translate(4 5)'><g stroke='currentColor' stroke-linecap='round' stroke-linejoin='round'><path d='m11.5 5.5h-7'/><path d='m11.5 9.5h-7'/><path d='m11.5 1.5h-7'/></g><path d='m1.49884033 2.5c.5 0 1-.5 1-1s-.5-1-1-1-.99884033.5-.99884033 1 .49884033 1 .99884033 1zm0 4c.5 0 1-.5 1-1s-.5-1-1-1-.99884033.5-.99884033 1 .49884033 1 .99884033 1zm0 4c.5 0 1-.5 1-1s-.5-1-1-1-.99884033.5-.99884033 1 .49884033 1 .99884033 1z' fill='currentColor'/></g></svg>">
<style>
html, body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
#pageContainer {
box-sizing: border-box;
display: grid;
height: 100vh;
width: 100%;
max-width: 1200px;
margin-inline: auto;
grid-template-rows: min-content min-content 1fr 1fr min-content;
grid-template-areas:
"description"
"options"
"input"
"output"
"actions"
;
gap: 0.75rem;
padding: 0.75rem;
}
#toolDescription {
grid-area: description;
}
h1 {
font-size: 2.5rem;
line-height: 1;
margin-block: 0 0.75rem;
text-align: center;
}
p {
margin-block: 0;
text-align: center;
}
noscript p {
background-color: #efeea1;
padding: 0.5rem 0.75rem;
margin-block-end: 0.75rem;
}
#optionsContainer {
grid-area: options;
text-align: center;
}
#inputContainer, #outputContainer {
display: grid;
gap: 0.25rem;
grid-template-rows: min-content 1fr;
}
#inputContainer {
grid-area: input;
}
#outputContainer {
grid-area: output;
}
#input {
font-size: 1.3rem;
resize: none;
border: 1px solid black;
padding: 0.75rem;
}
#output {
font-size: 1.3rem;
font-family: monospace;
line-height: 1;
overflow: auto;
border: 1px solid black;
padding: 0.75rem;
overflow-wrap: break-word;
}
#actionsContainer {
text-align: center;
grid-area: actions;
}
button {
font-size: 1.3rem;
padding: 0.5rem 2rem;
border: unset;
}
button.blue {
background-color: #006494;
color: #ffffff;
}
button.blue:hover,
button.blue:focus,
button.blue:active {
background-color: #13293d;
}
button.red {
background-color: #b10000;
color: #ffffff;
}
button.red:hover,
button.red:focus,
button.red:active {
background-color: #630000;
}
button[disabled] {
background-color: #777;
color: #eee;
}
button[disabled]:hover,
button[disabled]:focus,
button[disabled]:active {
background-color: #777;
color: #eee;
}
@media screen and (min-aspect-ratio: 3/2) {
#pageContainer {
max-width: 1500px;
grid-template-rows: min-content min-content 1fr;
grid-template-columns: repeat(6, 1fr);
grid-template-areas:
"description description description description description actions"
"options options options options options actions"
"input input input output output output"
;
}
#toolDescription, h1, p, #optionsContainer {
text-align: left;
}
#actionsContainer {
align-self: end;
}
button {
width: 100%;
}
button + button {
margin-top: 0.25rem;
}
}
</style>
</head>
<body>
<div id="pageContainer">
<div id="toolDescription">
<h1>SQL List Converter</h1>
<noscript><p>This tool requires JavaScript to work correctly.</p></noscript>
<p>This tool accepts a list of values separated by any whitespace and converts them into a SQL list.</p>
</div>
<div id="optionsContainer">
<input type="checkbox" id="commaBehavior" name="commaBehavior" disabled>
<label for="commaBehavior">Also treat commas as a separator</label><br>
<input type="checkbox" id="autoCopyBehavior" name="autoCopyBehavior" disabled>
<label for="autoCopyBehavior">Automatically copy output to clipboard</label>
</div>
<div id="inputContainer">
<label for="input"><strong>Input</strong></label>
<textarea id="input" disabled></textarea>
</div>
<div id="outputContainer">
<label for="output"><strong>Output</strong></label>
<output id="output" for="input"></output>
</div>
<div id="actionsContainer">
<button id="copy" class="blue" disabled>Copy</button>
<button id="clear" class="red" disabled>Clear</button>
</div>
</div>
<script>
const input = document.getElementById('input');
const output = document.getElementById('output');
const commaBehaviorOption = document.getElementById('commaBehavior');
const autoCopyOption = document.getElementById('autoCopyBehavior');
const copyButton = document.getElementById('copy');
const clearButton = document.getElementById('clear');
// Initialize Options
const options = {
treatCommasAsSeparator: {
defaultValue: 'true',
type: 'checkbox',
element: commaBehaviorOption
},
autoCopy: {
defaultValue: 'true',
type: 'checkbox',
element: autoCopyOption
}
};
for (const [optionName, optionDetails] of Object.entries(options)) {
if (localStorage.getItem(optionName) === null) {
localStorage.setItem(optionName, optionDetails.defaultValue);
}
switch (optionDetails.type) {
case 'checkbox':
if (localStorage.getItem(optionName) === 'true') {
optionDetails.element.checked = true;
}
optionDetails.element.addEventListener('change', () => {
localStorage.setItem(optionName, optionDetails.element.checked ? 'true' : 'false');
});
break;
}
}
//Initialize Interactivity
function copyOutput() {
navigator.clipboard.writeText(output.innerText);
}
function convertList() {
output.innerText = input.value
.split(localStorage.getItem('treatCommasAsSeparator') === 'true' ? /[,\s]/ : /\s/)
.filter(value => value !== '')
.map(value => `'${value}'`)
.join(',');
if (localStorage.getItem('autoCopy') === 'true') {copyOutput();}
}
let delayConversionTimeout;
input.addEventListener('input', () => {
clearTimeout(delayConversionTimeout);
delayConversionTimeout = setTimeout(convertList, 400);
});
commaBehaviorOption.addEventListener('change', convertList);
copyButton.addEventListener('click', copyOutput);
clearButton.addEventListener('click', () => {
input.value = '';
output.innerText = '';
input.focus();
});
commaBehaviorOption.disabled = false;
autoCopyOption.disabled = false;
copyButton.disabled = false;
clearButton.disabled = false;
input.disabled = false;
input.focus();
</script>
</body>
</html>