-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
412 lines (374 loc) · 15.6 KB
/
app.js
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
const utilityConverterInput = document.querySelector("#utilityConverterInput");
const utilityConverterOutput = document.querySelector("#utilityConverterOutput");
const encode = document.querySelector("#encode");
const decode = document.querySelector("#decode");
const reset = document.querySelector("#reset");
const base64Encode = document.querySelector("#base64Encode");
const base64Decode = document.querySelector("#base64Decode");
const generateMD5Hash = document.querySelector("#generateMD5Hash");
const generateSHA1Hash = document.querySelector("#generateSHA1Hash");
const generateSHA256Hash = document.querySelector("#generateSHA256Hash");
const generateSHA512Hash = document.querySelector("#generateSHA512Hash");
const ipV4 = document.querySelector("#ipv4");
const ipV6 = document.querySelector("#ipv6");
const binaryToDecimal = document.querySelector("#binaryDecimal");
const binaryToOctal = document.querySelector("#binaryOctal");
const binaryToHex = document.querySelector("#binaryHex");
const decimalToBinary = document.querySelector("#decimalBinary");
const decimalToOctal = document.querySelector("#decimalOctal");
const decimaltoHex = document.querySelector("#decimalHex");
const hexToBinary = document.querySelector("#hexBinary");
const hextoDecimal = document.querySelector("#hexDecimal");
const hextoOctal = document.querySelector("#hexOctal");
const octalToBinary = document.querySelector("#octalBinary");
const octalToDecimal = document.querySelector("#octalDecimal");
const octalToHex = document.querySelector("#octalHex");
const rgbHex = document.querySelector("#rgbHex");
const hexrgb = document.querySelector("#hexRgb");
const showHexRgbButton = document.querySelector("#showHexRgb");
const showRgbHexButton = document.querySelector("#showRgbHex");
const redInput = document.querySelector("#redInput");
const greenInput = document.querySelector("#greenInput");
const blueInput = document.querySelector("#blueInput");
const hexOutputVal = document.querySelector("#hexOutputVal");
const hexOutputBtn = document.querySelector("#hexOutputBtn");
const rgbOutputBtn = document.querySelector("#rgbOutput");
const resetRgbHexValuesbtn = document.querySelector("#resetRgbHexValues");
const redOutput = document.querySelector("#redOutput");
const greenOutput = document.querySelector("#greenOutput");
const blueOutput = document.querySelector("#blueOutput");
const hexInput = document.querySelector("#hexInput");
const resetHexRgbValues = document.querySelector("#resetHexRgbValues");
const langTextInput = document.querySelector("#translateInput");
const langTextOutput = document.querySelector("#translateOutput");
const selectLangInput=document.querySelector("#inputLang");
const selectLangOutput=document.querySelector("#outputLang");
const translateBtn = document.querySelector("#translateLanguage");
/*encode decode url */
if (typeof (encode) != 'undefined' && encode != null) {
encode.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = encodeURIComponent(utilityConverterInput.value);
} else {
alert("Please enter a Url value to encode");
}
}
}
if (typeof (decode) != 'undefined' && decode != null) {
decode.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = decodeURIComponent(utilityConverterInput.value);
} else {
alert("Please enter encoded Url value to decode");
}
}
}
/*reset */
if (typeof (reset) != 'undefined' && reset != null) {
reset.onclick = () => {
utilityConverterOutput.value = "";
utilityConverterOutput.disabled = true;
utilityConverterInput.value = "";
}
}
/*base64 encode decode */
if (typeof (base64Encode) != 'undefined' && base64Encode != null) {
base64Encode.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = btoa(utilityConverterInput.value);
} else {
alert("Please enter a vale to encode to base64");
}
}
}
if (typeof (base64Decode) != 'undefined' && base64Decode != null) {
base64Decode.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = atob(utilityConverterInput.value);
} else {
alert("Please enter encoded base64 value to decode");
}
}
}
/*hash generators */
if (typeof (generateMD5Hash) != 'undefined' && generateMD5Hash != null) {
generateMD5Hash.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = CryptoJS.MD5(utilityConverterInput.value);
} else {
alert("Please enter a value to generate MD5 hash");
}
}
}
if (typeof (generateSHA1Hash) != 'undefined' && generateSHA1Hash != null) {
generateSHA1Hash.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = CryptoJS.SHA1(utilityConverterInput.value);
} else {
alert("Please enter a value to generate SHA-1 hash");
}
}
}
if (typeof (generateSHA256Hash) != 'undefined' && generateSHA256Hash != null) {
generateSHA256Hash.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = CryptoJS.SHA256(utilityConverterInput.value);
} else {
alert("Please enter a value to generate SHA-256 hash");
}
}
}
if (typeof (generateSHA512Hash) != 'undefined' && generateSHA512Hash != null) {
generateSHA512Hash.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = CryptoJS.SHA512(utilityConverterInput.value);
;
} else {
alert("Please enter a value to generate SHA-512 hash");
}
}
}
/*Binary to Decimal */
if (typeof (binaryToDecimal) != 'undefined' && binaryToDecimal != null) {
binaryToDecimal.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value, 2);
} else {
alert("Please enter a Binary value to get Decimal Value");
}
}
}
/*Binary to hex */
if (typeof (binaryToHex) != 'undefined' && binaryToHex != null) {
binaryToHex.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value, 2).toString(16);
} else {
alert("Please enter a Binary value to get hex Value");
}
}
}
/*Binary to octal */
if (typeof (binaryToOctal) != 'undefined' && binaryToOctal != null) {
binaryToOctal.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value, 2).toString(8);
} else {
alert("Please enter a Binary value to get octal Value");
}
}
}
/*hex to Binary */
if (typeof (hexToBinary) != 'undefined' && hexToBinary != null) {
hexToBinary.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value, 16).toString(2);
} else {
alert("Please enter a Hex value to get Binary Value");
}
}
}
/*hex to Decimal */
if (typeof (hextoDecimal) != 'undefined' && hextoDecimal != null) {
hextoDecimal.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value, 16);
} else {
alert("Please enter a Hex value to get Decimal Value");
}
}
}
/*hex to Octal */
if (typeof (hextoOctal) != 'undefined' && hextoOctal != null) {
hextoOctal.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value, 16).toString(8);
} else {
alert("Please enter a Hex value to get Octal Value");
}
}
}
/*octal to Decimal */
if (typeof (octalToDecimal) != 'undefined' && octalToDecimal != null) {
octalToDecimal.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value, 8);
} else {
alert("Please enter a octal value to get Decimal Value");
}
}
}
/*octal to Binary */
if (typeof (octalToBinary) != 'undefined' && octalToBinary != null) {
octalToBinary.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value, 8).toString(2);
} else {
alert("Please enter a octal value to get Binary Value");
}
}
}
/*octal to hex */
if (typeof (octalToHex) != 'undefined' && octalToHex != null) {
octalToHex.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value, 8).toString(16);
} else {
alert("Please enter a octal value to get Hex Value");
}
}
}
/*decimal to binary */
if (typeof (decimalToBinary) != 'undefined' && decimalToBinary != null) {
decimalToBinary.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value).toString(2);
} else {
alert("Please enter a Decimal value to get Binary Value");
}
}
}
/*decimal to hex */
if (typeof (decimaltoHex) != 'undefined' && decimaltoHex != null) {
decimaltoHex.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value).toString(16);
} else {
alert("Please enter a Decimal value to get Hex Value");
}
}
}
/*decimal to octal */
if (typeof (decimalToOctal) != 'undefined' && decimalToOctal != null) {
decimalToOctal.onclick = () => {
if (utilityConverterInput.value !== "") {
utilityConverterOutput.disabled = false;
utilityConverterOutput.value = parseInt(utilityConverterInput.value).toString(8);
} else {
alert("Please enter a Decimal value to get Octal Value");
}
}
}
/*RGB HEX */
if (typeof (showHexRgbButton) != 'undefined' && showHexRgbButton != null) {
showHexRgbButton.onclick = () => {
rgbHex.classList.add("hide");
hexrgb.classList.remove("hide");
hexrgb.classList.add("rgb-hex-converters");
window.scrollTo(0, 0);
document.querySelector("#rgb-hex-converter-section").style.backgroundColor = "";
}
}
if (typeof (showRgbHexButton) != 'undefined' && showRgbHexButton != null) {
showRgbHexButton.onclick = () => {
hexrgb.classList.add("hide");
rgbHex.classList.remove("hide");
rgbHex.classList.add("rgb-hex-converters");
window.scrollTo(0, 0);
document.querySelector("#rgb-hex-converter-section").style.backgroundColor = "";
}
}
if (typeof (hexOutputBtn) != 'undefined' && hexOutputBtn != null) {
hexOutputBtn.onclick = () => {
if (redInput.value.match("[0-9]") && greenInput.value.match("[0-9]") && blueInput.value.match("[0-9]") &&
redInput.value != "" && blueInput.value != "" && greenInput.value != "") {
hexOutputVal.disabled = false
hexOutputVal.value = rgbToHex(parseInt(redInput.value), parseInt(greenInput.value), parseInt(blueInput.value));
document.querySelector("#rgb-hex-converter-section").style.backgroundColor = hexOutputVal.value;
}
else {
alert("Please enter all valid rgb values to get a valid Hex value");
}
}
}
if (typeof (rgbOutputBtn) != 'undefined' && rgbOutputBtn != null) {
rgbOutputBtn.onclick = () => {
if (hexInput.value != null && hexInput.value!= "") {
redOutput.disabled = false;
greenOutput.disabled = false;
blueOutput.disabled = false
hexInput.value = hexInput.value.startsWith("#")?hexInput.value.substring(1):hexInput.value;
const bigint = parseInt(hexInput.value, 16);
redOutput.value = (bigint >> 16) & 255;
greenOutput.value = (bigint >> 8) & 255;
blueOutput.value = bigint & 255;
document.querySelector("#rgb-hex-converter-section").style.backgroundColor = "rgb(" + redOutput.value + "," + greenOutput.value + "," + blueOutput.value + ")";
}
else {
alert("Please enter valid hex value to get a valid red , green , blue values");
}
}
}
const rgbToHex = (r, g, b) => '#' + [r, g, b].map(x => {
const hexv = x.toString(16)
console.log(hexv);
return hexv.length === 1 ? '0' + hexv : hexv
}).join('')
if (typeof (resetRgbHexValuesbtn) != 'undefined' && resetRgbHexValuesbtn != null) {
resetRgbHexValuesbtn.onclick = () => {
redInput.value = "";
greenInput.value = "";
blueInput.value = "";
hexOutputVal.value = "";
hexOutputBtn.disabled = true;
document.querySelector("#rgb-hex-converter-section").style.backgroundColor = "";
}
}
if (typeof (resetHexRgbValues) != 'undefined' && resetHexRgbValues != null) {
resetHexRgbValues.onclick = () => {
redOutput.value = "";
redOutput.disabled = true;
greenOutput.value = "";
greenOutput.disabled = true;
blueOutput.value = "";
blueOutput.disabled = true;
hexInput.value = "";
document.querySelector("#rgb-hex-converter-section").style.backgroundColor = "";
}
}
if(typeof(ipv4) != 'undefined' && ipv4!= null){
fetch("https://api.ipify.org/?format=json").then(response => response.json()).then(data=>
ipv4.innerHTML = data.ip);
}
if(typeof(ipv6) != 'undefined' && ipv6!= null){
fetch("https://api64.ipify.org/?format=json").then(response => response.json()).then(data=>
ipv6.innerHTML = data.ip);
}
if(typeof(translateBtn)!='undefined' && translateBtn!= null){
translateBtn.onclick = () =>{
let inputText = langTextInput.value;
let sourcLang = selectLangInput.value;
let destlang = selectLangOutput.value;
translatedTextOutput(inputText,sourcLang,destlang);
}
}
function translatedTextOutput(inputText,langSymbolInput,langSymbolOutput){
const params = new URLSearchParams();
params.append("q",inputText);
params.append("langpair", langSymbolInput + "|" + langSymbolOutput);
let url = `https://api.mymemory.translated.net/get?${params.toString()}`;
console.log(url);
fetch(url)
.then(response => response.json())
.then(data => {langTextOutput.value = data.responseData.translatedText});
}
// console.log(translatedTextOutput("hello Praful!","en","de"));