forked from ShoroukAziz/notion_widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.html
493 lines (426 loc) · 11.5 KB
/
converter.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<!DOCTYPE HTML>
<!-- original : https://codepen.io/jenjen9/pen/yLBNOKB -->
<html>
<head>
<title>Unit Converter</title>
<link href="https://fonts.googleapis.com/css?family=Oxygen&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<style>
body{
background-color:#3a3a3a;
}
.container{
margin: 0 25px;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
align-content: center;
}
h1 {
font-family: 'Oxygen', sans-serif;
font-size: 40px;
text-align:center;
color: #fff;
}
button {
border-radius: 9px;
background-color: #999;
margin: 10px;
font-family: 'Oxygen', sans-serif;
border: none;
padding: 10px ;
color: #fff;
text-align: center;
width: 90px;
}
#mass{
background-color: #60688b;
}
#volume{
background-color: #4CAF50;
;
}
#temperature{
background-color: #ff9233;
}
button:hover{
background-color: #b3b3b3;
}
.categoryButtons{
margin: auto;
width: fit-content;
}
.content{
width: 1000px;
margin: auto;
}
.metricImperial, .temp-unit-buttons, .speed-units, .time-units{
display: flex;
justify-content: center;
align-items:center;
align-content: center;
}
#toImperial, #toMetric, #toCelsius, #toFahrenheit, #toKelvin, #mileToKm, #kmToMile, #hours, #days {
background-color:#009688;
font-size: 15px;
/* width: 90px; */
}
#toImperial:hover, #toMetric:hover, #toCelsius:hover, #toFahrenheit:hover, #toKelvin:hover, #mileToKm:hover, #kmToMile:hover, #hours:hover, #days:hover{
background-color: #ffad66;
}
input {
width: 300px;
padding: 10px;
border-radius: 9px;
text-align: center;
font-family: 'Oxygen', sans-serif;
margin: auto;
border: none;
}
#output {
font-family: monospace;
font-size: 15px;
text-align: left;
margin: auto;
padding: 10px;
width: 300px;
background-color: #fff;
border-radius: 9px;
}
#reset{
background-color: #c34a41;
color: #fff;
border: none;
margin: 15px auto;
width: 325px;
}
#reset:hover{
background-color: #b3b3b3;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<div class="categoryButtons">
<button id="mass" title="Mass"><i class="fas fa-balance-scale fa-2x"></i></button>
<button id="volume" title="Volume"><i class="fas fa-glass-whiskey fa-2x"></i></button>
<button id="temperature" title="Temperature"><i class="fa fa-thermometer-2 fa-2x"></i></button>
</div>
<input type="number" style="display: none" placeholder="Enter a number" >
<div class="metricImperial">
<button id="toMetric" style="display:none">Imperial to metric</button>
<button id="toImperial" style="display:none">Metric to imperial</button>
</div>
<div class="temp-unit-buttons">
<button id="toCelsius" style="display:none">Celsius</button>
<button id="toFahrenheit" style="display:none">Fahrenheit</button>
<button id="toKelvin" style="display:none">Kelvin</button>
</div>
<div class="speed-units">
<button id="mileToKm" style="display:none">mph</button>
<button id="kmToMile" style="display:none">km/hr</button>
</div>
<div class="time-units">
<button id="hours" style="display:none">Hours</button>
<button id="days" style="display:none">Days</button>
</div>
</div>
</div>
<br>
<div id="output" style="display:none"></div>
<div>
<input type="reset" id="reset" style="display:none">
</div>
</div>
<script >
let input = document.querySelector('input');
let output = document.getElementById('output');
const toMetric = document.getElementById('toMetric');
const toImperial = document.getElementById('toImperial');
const toCelsius = document.getElementById('toCelsius');
const toFahrenheit = document.getElementById('toFahrenheit');
const toKelvin = document.getElementById('toKelvin');
const mileToKm = document.getElementById('mileToKm');
const kmToMile = document.getElementById('kmToMile');
const hours = document.getElementById('hours');
const days = document.getElementById('days');
const resetButton = document.getElementById('reset');
const massButton = document.getElementById('mass').addEventListener('click', (e) => {
input.style.display = 'block';
toFahrenheit.style.display = 'none';
toCelsius.style.display = 'none';
toKelvin.style.display = 'none';
hours.style.display = 'none';
days.style.display = 'none';
mileToKm.style.display = 'none';
kmToMile.style.display = 'none';
toMetric.style.display = 'block';
toImperial.style.display='block';
resetButton.style.display = 'block';
toMetric.addEventListener('click', (e) => {
output.innerHTML = `${input.value} ounce → ${massUnits.imperial.ounce()} gram <br>
${input.value} pound → ${massUnits.imperial.pound()} kg <br>
${input.value} stone → ${massUnits.imperial.stone()} kg <br>
${input.value} ton → ${massUnits.imperial.imperialTon()} tonne
`;
});
toImperial.addEventListener('click', (e) => {
output.innerHTML = `${input.value} gram → ${massUnits.metric.gram()} ounce <br>
${input.value} kg → ${massUnits.metric.kglb()} pound <br>
${input.value} kg → ${massUnits.metric.kgst()} stone <br>
${input.value} tonne → ${massUnits.metric.metricTonne()} ton
`;
});
output.style.display = 'block';
output.innerHTML = "";
input.value = null;
});
const volumeButton = document.getElementById('volume').addEventListener('click', (e) => {
input.style.display = 'block';
toFahrenheit.style.display = 'none';
toCelsius.style.display = 'none';
toKelvin.style.display = 'none';
hours.style.display = 'none';
days.style.display = 'none';
mileToKm.style.display = 'none';
kmToMile.style.display = 'none';
toMetric.style.display = 'block';
toImperial.style.display='block';
resetButton.style.display = 'block';
toMetric.addEventListener('click', (e) => {
output.innerHTML = `${input.value} fl. ounce → ${volumeUnits.imperial.fluidOunce()} ml <br>
${input.value} pint → ${volumeUnits.imperial.pint()} litre <br>
${input.value} quart → ${volumeUnits.imperial.quart()} litre <br>
${input.value} gallon → ${volumeUnits.imperial.gallon()} litre
`;
});
toImperial.addEventListener('click', (e) =>{
output.innerHTML = `${input.value} ml → ${volumeUnits.metric.ml()} fluid ounce <br>
${input.value} litre → ${volumeUnits.metric.lToPt()} pint <br>
${input.value} litre → ${volumeUnits.metric.lToQt()} quart <br>
${input.value} litre → ${volumeUnits.metric.lToGallon()} gallon
`;
});
output.style.display = 'block';
output.innerHTML = "";
input.value = null;
});
const temperatureButton = document.getElementById('temperature').addEventListener('click', (e) => {
toMetric.style.display = 'none';
toImperial.style.display = 'none';
hours.style.display = 'none';
days.style.display = 'none';
mileToKm.style.display = 'none';
kmToMile.style.display = 'none';
input.style.display = 'block';
toCelsius.style.display = 'block';
toFahrenheit.style.display = 'block';
toKelvin.style.display = 'block';
resetButton.style.display = 'block';
toCelsius.addEventListener('click', (e) =>{
output.innerHTML =`${input.value} °F → ${temperatureUnits.fahrenheit.fToC()} °C <br>
${input.value} °K → ${temperatureUnits.kelvin.kToC()} °C`;
});
toFahrenheit.addEventListener('click', (e) =>{
output.innerHTML = `${input.value} °C → ${temperatureUnits.celsius.cToF()} °F <br>
${input.value} °K → ${temperatureUnits.kelvin.kToF()} °F <br>
`;
});
toKelvin.addEventListener('click', (e) =>{
output.innerHTML = `${input.value} °F → ${temperatureUnits.fahrenheit.fToK()} °K <br>
${input.value} °C → ${temperatureUnits.celsius.cToK()} °K <br>
`;
});
output.style.display = 'block';
output.innerHTML = "";
input.value = null;
});
resetButton.addEventListener('click', (e) =>{
location.reload();
});
const lengthUnits = {
imperial: {
inch(){
let inchToMm = (input.value * 25.4).toFixed(2);
return inchToMm;
},
foot(){
let footToCm = (input.value * 30.48).toFixed(2);
return footToCm;
},
yard(){
let yardToM = (input.value / 1.094).toFixed(2);
return yardToM;
},
mile(){
let mileToKm = (input.value * 1.609).toFixed(2);
return mileToKm;
}
},
metric: {
mm(){
let mmToInch = (input.value / 25.4).toFixed(2);
return mmToInch;
},
cm(){
let cmToFoot = (input.value / 30.48).toFixed(2);
return cmToFoot;
},
m(){
let mToYard = (input.value * 1.094).toFixed(2);
return mToYard;
},
km(){
let kmToMile = (input.value / 1.609).toFixed(2);
return kmToMile;
}
}
};
const massUnits = {
imperial: {
ounce(){
let ounceToGram = (input.value * 28.35).toFixed(2);
return ounceToGram;
},
pound(){
let poundToKg = (input.value / 2.205).toFixed(2);
return poundToKg;
},
stone(){
let stoneToKg = (input.value * 6.35).toFixed(2);
return stoneToKg;
},
imperialTon(){
let tonToTonne = (input.value * 1.016).toFixed(2);
return tonToTonne;
}
},
metric: {
gram(){
let gramToOunce = (input.value / 28.35).toFixed(2);
return gramToOunce;
},
kglb(){
let kgToPound = (input.value * 2.205).toFixed(2);
return kgToPound;
},
kgst(){
let kgToStone = (input.value / 6.35).toFixed(2);
return kgToStone;
},
metricTonne(){
let tonneToTon = (input.value / 1.016).toFixed(2);
return tonneToTon;
}
}
};
const volumeUnits = {
imperial: {
fluidOunce(){
let flozToMl = (input.value * 28.413).toFixed(2);
return flozToMl;
},
pint(){
let pintToL = (input.value / 1.76).toFixed(2);
return pintToL;
},
quart(){
let quartToL = (input.value * 1.137).toFixed(2);
return quartToL;
},
gallon(){
let gallonToL = (input.value * 4.546).toFixed(2);
return gallonToL;
}
},
metric: {
ml(){
let mlToFloz = (input.value / 28.413).toFixed(2);
return mlToFloz;
},
lToPt(){
let lToPt = (input.value * 1.76).toFixed(2);
return lToPt;
},
lToQt(){
let lToQt = (input.value / 1.137).toFixed(2);
return lToQt;
},
lToGallon(){
let lToGallon = (input.value / 4.546).toFixed(2);
return lToGallon;
}
}
};
const temperatureUnits = {
fahrenheit: {
fToC(){
let c = ((input.value - 32)* 5/9).toFixed(2);
return c;
},
fToK(){
let k = ((input.value - 32) * 5/9 + 273.15).toFixed(2);
return k;
}
},
celsius: {
cToF(){
let f = ((input.value * 9/5) + 32).toFixed(2);
return f;
},
cToK(){
//let kconst = 273.15;
let ck = (parseFloat(input.value) + 273.15).toFixed(2);
return ck;
}
},
kelvin: {
kToF(){
let kf = ((input.value - 273.15)* 9/5 + 32).toFixed(2);
return kf;
},
kToC(){
let kc = (input.value - 273.15).toFixed(2);
return kc;
}
}
};
const speedUnits = {
mphToKmph(){
let kmph = (input.value * 1.609).toFixed(2);
return kmph;
},
kmphToMph() {
let mph = (input.value / 1.609).toFixed(2);
return mph;
}
};
const timeUnits = {
hours: {
minTohr(){
let mhr = (input.value/60).toFixed(3);
return mhr;
},
dayTohr(){
let dhr = input.value*24;
return dhr;
}
},
days: {
minToDay(){
let mday = (input.value / 1440).toFixed(4);
return mday;
},
hrToDay(){
let hrday = (input.value / 24).toFixed(2);
return hrday;
}
}
};
</script>
</body>
</html>