-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
834 lines (698 loc) · 28.2 KB
/
app.js
File metadata and controls
834 lines (698 loc) · 28.2 KB
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
// Navigation Handler
const navigation = {
init() {
const navItems = document.querySelectorAll('.nav-item');
const toolContainers = document.querySelectorAll('.tool-container');
navItems.forEach(item => {
item.addEventListener('click', () => {
const toolId = item.dataset.tool;
// Update active nav item
navItems.forEach(nav => nav.classList.remove('active'));
item.classList.add('active');
// Show corresponding tool
toolContainers.forEach(container => {
container.classList.remove('active');
});
document.getElementById(toolId).classList.add('active');
});
});
}
};
// Character Counter Tool
const characterCounter = {
init() {
const input = document.getElementById('char-input');
const charCount = document.getElementById('char-count');
const wordCount = document.getElementById('word-count');
const lineCount = document.getElementById('line-count');
const paraCount = document.getElementById('para-count');
input.addEventListener('input', () => {
const text = input.value;
// Character count
charCount.textContent = text.length;
// Word count
const words = text.trim().split(/\s+/).filter(word => word.length > 0);
wordCount.textContent = words.length;
// Line count
const lines = text.split('\n');
lineCount.textContent = lines.length;
// Paragraph count
const paragraphs = text.split(/\n\s*\n/).filter(para => para.trim().length > 0);
paraCount.textContent = paragraphs.length;
});
}
};
// Diff Checker Tool
const diffChecker = {
compare() {
const original = document.getElementById('diff-original').value;
const modified = document.getElementById('diff-modified').value;
const resultDiv = document.getElementById('diff-result');
if (!original && !modified) {
resultDiv.innerHTML = '<p style="color: var(--text-tertiary);">Enter text in both fields to compare.</p>';
return;
}
const diff = this.computeDiff(original, modified);
resultDiv.innerHTML = diff;
},
computeDiff(original, modified) {
const originalLines = original.split('\n');
const modifiedLines = modified.split('\n');
let result = '';
const maxLines = Math.max(originalLines.length, modifiedLines.length);
for (let i = 0; i < maxLines; i++) {
const origLine = originalLines[i] || '';
const modLine = modifiedLines[i] || '';
if (origLine === modLine) {
result += `<div>${this.escapeHtml(origLine) || ' '}</div>`;
} else {
if (origLine) {
result += `<div><span class="diff-removed">- ${this.escapeHtml(origLine)}</span></div>`;
}
if (modLine) {
result += `<div><span class="diff-added">+ ${this.escapeHtml(modLine)}</span></div>`;
}
}
}
return result || '<p style="color: var(--text-tertiary);">No differences found.</p>';
},
escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
},
clear() {
document.getElementById('diff-original').value = '';
document.getElementById('diff-modified').value = '';
document.getElementById('diff-result').innerHTML = '';
}
};
// Case Converter Tool
const caseConverter = {
convert(type) {
const input = document.getElementById('case-input');
let text = input.value;
if (!text) return;
switch(type) {
case 'upper':
text = text.toUpperCase();
break;
case 'lower':
text = text.toLowerCase();
break;
case 'title':
text = text.toLowerCase().replace(/\b\w/g, char => char.toUpperCase());
break;
case 'sentence':
text = text.toLowerCase().replace(/(^\s*\w|[.!?]\s*\w)/g, char => char.toUpperCase());
break;
case 'camel':
text = text.toLowerCase()
.replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase());
break;
case 'pascal':
text = text.toLowerCase()
.replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase())
.replace(/^./, char => char.toUpperCase());
break;
case 'snake':
text = text.toLowerCase()
.replace(/[^a-zA-Z0-9]+/g, '_')
.replace(/^_+|_+$/g, '');
break;
case 'kebab':
text = text.toLowerCase()
.replace(/[^a-zA-Z0-9]+/g, '-')
.replace(/^-+|-+$/g, '');
break;
}
input.value = text;
}
};
// JSON Formatter Tool
const jsonFormatter = {
format() {
const input = document.getElementById('json-input').value;
const output = document.getElementById('json-output');
const status = document.getElementById('json-status');
try {
const parsed = JSON.parse(input);
const formatted = JSON.stringify(parsed, null, 2);
output.textContent = formatted;
this.showStatus('Valid JSON formatted successfully!', 'success');
} catch (error) {
this.showStatus(`Error: ${error.message}`, 'error');
}
},
minify() {
const input = document.getElementById('json-input').value;
const output = document.getElementById('json-output');
const status = document.getElementById('json-status');
try {
const parsed = JSON.parse(input);
const minified = JSON.stringify(parsed);
output.textContent = minified;
this.showStatus('JSON minified successfully!', 'success');
} catch (error) {
this.showStatus(`Error: ${error.message}`, 'error');
}
},
validate() {
const input = document.getElementById('json-input').value;
const status = document.getElementById('json-status');
try {
JSON.parse(input);
this.showStatus('✓ Valid JSON', 'success');
} catch (error) {
this.showStatus(`✗ Invalid JSON: ${error.message}`, 'error');
}
},
clear() {
document.getElementById('json-input').value = '';
document.getElementById('json-output').textContent = '';
document.getElementById('json-status').innerHTML = '';
},
copy() {
const output = document.getElementById('json-output').textContent;
navigator.clipboard.writeText(output).then(() => {
this.showStatus('Copied to clipboard!', 'success');
});
},
showStatus(message, type) {
const status = document.getElementById('json-status');
status.textContent = message;
status.className = `status-message ${type}`;
setTimeout(() => {
status.innerHTML = '';
}, 3000);
}
};
// Markdown Preview Tool
const markdownPreview = {
init() {
const input = document.getElementById('markdown-input');
const output = document.getElementById('markdown-output');
input.addEventListener('input', () => {
const markdown = input.value;
const html = marked.parse(markdown);
output.innerHTML = html;
});
// Initial render
output.innerHTML = marked.parse(input.value);
}
};
// Base64 Encoder Tool
const base64Tool = {
encode() {
const input = document.getElementById('base64-input').value;
const output = document.getElementById('base64-output');
try {
const encoded = btoa(unescape(encodeURIComponent(input)));
output.value = encoded;
} catch (error) {
output.value = 'Error encoding: ' + error.message;
}
},
decode() {
const input = document.getElementById('base64-input').value;
const output = document.getElementById('base64-output');
try {
const decoded = decodeURIComponent(escape(atob(input)));
output.value = decoded;
} catch (error) {
output.value = 'Error decoding: ' + error.message;
}
},
clear() {
document.getElementById('base64-input').value = '';
document.getElementById('base64-output').value = '';
}
};
// Color Picker Tool
const colorPicker = {
init() {
const colorInput = document.getElementById('color-input');
const hexInput = document.getElementById('hex-input');
const display = document.getElementById('color-display');
const updateColor = (hex) => {
display.style.backgroundColor = hex;
this.updateFormats(hex);
};
colorInput.addEventListener('input', (e) => {
const hex = e.target.value;
hexInput.value = hex;
updateColor(hex);
});
hexInput.addEventListener('input', (e) => {
let hex = e.target.value;
if (!hex.startsWith('#')) hex = '#' + hex;
if (/^#[0-9A-F]{6}$/i.test(hex)) {
colorInput.value = hex;
updateColor(hex);
}
});
// Initial update
updateColor(colorInput.value);
},
updateFormats(hex) {
const rgb = this.hexToRgb(hex);
const hsl = this.rgbToHsl(rgb.r, rgb.g, rgb.b);
const cmyk = this.rgbToCmyk(rgb.r, rgb.g, rgb.b);
document.getElementById('rgb-output').value = `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
document.getElementById('hsl-output').value = `hsl(${hsl.h}°, ${hsl.s}%, ${hsl.l}%)`;
document.getElementById('cmyk-output').value = `cmyk(${cmyk.c}%, ${cmyk.m}%, ${cmyk.y}%, ${cmyk.k}%)`;
},
hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : { r: 0, g: 0, b: 0 };
},
rgbToHsl(r, g, b) {
r /= 255;
g /= 255;
b /= 255;
const max = Math.max(r, g, b);
const min = Math.min(r, g, b);
let h, s, l = (max + min) / 2;
if (max === min) {
h = s = 0;
} else {
const d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r: h = ((g - b) / d + (g < b ? 6 : 0)) / 6; break;
case g: h = ((b - r) / d + 2) / 6; break;
case b: h = ((r - g) / d + 4) / 6; break;
}
}
return {
h: Math.round(h * 360),
s: Math.round(s * 100),
l: Math.round(l * 100)
};
},
rgbToCmyk(r, g, b) {
let c = 1 - (r / 255);
let m = 1 - (g / 255);
let y = 1 - (b / 255);
let k = Math.min(c, m, y);
c = k === 1 ? 0 : Math.round(((c - k) / (1 - k)) * 100);
m = k === 1 ? 0 : Math.round(((m - k) / (1 - k)) * 100);
y = k === 1 ? 0 : Math.round(((y - k) / (1 - k)) * 100);
k = Math.round(k * 100);
return { c, m, y, k };
}
};
// UUID Generator Tool
const uuidGenerator = {
generate() {
const uuid = this.generateUUID();
document.getElementById('uuid-value').textContent = uuid;
},
generateMultiple() {
const listDiv = document.getElementById('uuid-list');
listDiv.innerHTML = '';
for (let i = 0; i < 10; i++) {
const uuid = this.generateUUID();
const item = document.createElement('div');
item.className = 'uuid-item';
item.innerHTML = `
${uuid}
<button class="btn-icon" onclick="tools.uuid.copySpecific('${uuid}')" title="Copy">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
<path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/>
</svg>
</button>
`;
listDiv.appendChild(item);
}
},
generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
},
copy() {
const uuid = document.getElementById('uuid-value').textContent;
if (uuid !== 'Click generate to create a UUID') {
navigator.clipboard.writeText(uuid);
}
},
copySpecific(uuid) {
navigator.clipboard.writeText(uuid);
}
};
// Timestamp Converter Tool
const timestampConverter = {
init() {
this.updateCurrentTime();
setInterval(() => this.updateCurrentTime(), 1000);
},
updateCurrentTime() {
const now = Math.floor(Date.now() / 1000);
const date = new Date();
document.getElementById('current-timestamp').textContent = now;
document.getElementById('current-date').textContent = date.toLocaleString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
},
convertTimestamp() {
const timestamp = parseInt(document.getElementById('timestamp-input').value);
const resultDiv = document.getElementById('timestamp-result');
if (isNaN(timestamp)) {
resultDiv.innerHTML = '<p style="color: var(--error);">Please enter a valid timestamp</p>';
return;
}
const date = new Date(timestamp * 1000);
resultDiv.innerHTML = `
<div style="margin-bottom: 12px;"><strong>Local Time:</strong> ${date.toLocaleString()}</div>
<div style="margin-bottom: 12px;"><strong>UTC:</strong> ${date.toUTCString()}</div>
<div style="margin-bottom: 12px;"><strong>ISO 8601:</strong> ${date.toISOString()}</div>
<div><strong>Relative:</strong> ${this.getRelativeTime(date)}</div>
`;
},
convertDate() {
const dateInput = document.getElementById('datetime-input').value;
const resultDiv = document.getElementById('timestamp-result');
if (!dateInput) {
resultDiv.innerHTML = '<p style="color: var(--error);">Please select a date and time</p>';
return;
}
const date = new Date(dateInput);
const timestamp = Math.floor(date.getTime() / 1000);
resultDiv.innerHTML = `
<div style="margin-bottom: 12px;"><strong>Unix Timestamp:</strong> ${timestamp}</div>
<div style="margin-bottom: 12px;"><strong>Milliseconds:</strong> ${date.getTime()}</div>
<div style="margin-bottom: 12px;"><strong>ISO 8601:</strong> ${date.toISOString()}</div>
<div><strong>UTC:</strong> ${date.toUTCString()}</div>
`;
},
getRelativeTime(date) {
const now = new Date();
const diff = now - date;
const seconds = Math.floor(diff / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
if (days > 0) return `${days} day${days > 1 ? 's' : ''} ago`;
if (hours > 0) return `${hours} hour${hours > 1 ? 's' : ''} ago`;
if (minutes > 0) return `${minutes} minute${minutes > 1 ? 's' : ''} ago`;
return `${seconds} second${seconds !== 1 ? 's' : ''} ago`;
}
};
// Bcrypt Hasher Tool
const bcryptHasher = {
async hash() {
const password = document.getElementById('bcrypt-password').value;
const rounds = parseInt(document.getElementById('bcrypt-rounds').value);
const hashOutput = document.getElementById('bcrypt-hash');
if (!password) {
this.showMessage('Please enter a password', 'error');
return;
}
if (rounds < 4 || rounds > 12) {
this.showMessage('Rounds must be between 4 and 12', 'error');
return;
}
try {
// Show loading state
hashOutput.value = 'Generating hash...';
// Generate salt and hash using dcodeIO.bcrypt
const salt = dcodeIO.bcrypt.genSaltSync(rounds);
const hash = dcodeIO.bcrypt.hashSync(password, salt);
hashOutput.value = hash;
this.showMessage(`Hash generated successfully with ${rounds} rounds`, 'success');
} catch (error) {
hashOutput.value = '';
this.showMessage('Error generating hash: ' + error.message, 'error');
}
},
async verify() {
const password = document.getElementById('verify-password').value;
const hash = document.getElementById('verify-hash').value;
const resultDiv = document.getElementById('verify-result');
if (!password || !hash) {
resultDiv.innerHTML = '';
this.showMessage('Please enter both password and hash', 'error');
return;
}
try {
resultDiv.innerHTML = 'Verifying...';
resultDiv.className = 'verify-result';
const isMatch = dcodeIO.bcrypt.compareSync(password, hash);
if (isMatch) {
resultDiv.innerHTML = '✓ Password matches hash';
resultDiv.className = 'verify-result success';
} else {
resultDiv.innerHTML = '✗ Password does not match hash';
resultDiv.className = 'verify-result failed';
}
} catch (error) {
resultDiv.innerHTML = '✗ Invalid hash format';
resultDiv.className = 'verify-result failed';
}
},
copyHash() {
const hash = document.getElementById('bcrypt-hash').value;
if (hash && hash !== 'Generating hash...') {
navigator.clipboard.writeText(hash).then(() => {
this.showMessage('Hash copied to clipboard!', 'success');
});
}
},
showMessage(message, type) {
// Create temporary notification
const notification = document.createElement('div');
notification.className = `status-message ${type}`;
notification.textContent = message;
notification.style.position = 'fixed';
notification.style.top = '20px';
notification.style.right = '20px';
notification.style.zIndex = '1000';
notification.style.minWidth = '300px';
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 3000);
}
};
// Lorem Ipsum Generator Tool
const loremIpsumGenerator = {
loremWords: [
'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit',
'sed', 'do', 'eiusmod', 'tempor', 'incididunt', 'ut', 'labore', 'et', 'dolore',
'magna', 'aliqua', 'enim', 'ad', 'minim', 'veniam', 'quis', 'nostrud',
'exercitation', 'ullamco', 'laboris', 'nisi', 'aliquip', 'ex', 'ea', 'commodo',
'consequat', 'duis', 'aute', 'irure', 'in', 'reprehenderit', 'voluptate',
'velit', 'esse', 'cillum', 'fugiat', 'nulla', 'pariatur', 'excepteur', 'sint',
'occaecat', 'cupidatat', 'non', 'proident', 'sunt', 'culpa', 'qui', 'officia',
'deserunt', 'mollit', 'anim', 'id', 'est', 'laborum', 'semper', 'quis', 'lectus',
'nulla', 'at', 'volutpat', 'diam', 'maecenas', 'ultricies', 'mi', 'eget',
'mauris', 'pharetra', 'magna', 'ac', 'placerat', 'vestibulum', 'lectus',
'mauris', 'ultrices', 'eros', 'integer', 'vitae', 'justo', 'eget', 'arcu',
'dictum', 'varius', 'duis', 'convallis', 'tellus', 'elementum', 'sagittis'
],
generate() {
const type = document.getElementById('lorem-type').value;
const count = parseInt(document.getElementById('lorem-count').value);
const startWithLorem = document.getElementById('lorem-start-with').checked;
const output = document.getElementById('lorem-output');
let result = '';
switch(type) {
case 'paragraphs':
result = this.generateParagraphs(count, startWithLorem);
break;
case 'sentences':
result = this.generateSentences(count, startWithLorem);
break;
case 'words':
result = this.generateWords(count, startWithLorem);
break;
}
output.value = result;
},
generateWords(count, startWithLorem) {
let words = [];
if (startWithLorem) {
words.push('Lorem', 'ipsum', 'dolor', 'sit', 'amet');
count -= 5;
}
for (let i = 0; i < count; i++) {
words.push(this.getRandomWord());
}
return words.join(' ') + '.';
},
generateSentences(count, startWithLorem) {
let sentences = [];
if (startWithLorem) {
sentences.push('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
count -= 1;
}
for (let i = 0; i < count; i++) {
const wordCount = Math.floor(Math.random() * 10) + 5;
let sentence = [];
for (let j = 0; j < wordCount; j++) {
sentence.push(this.getRandomWord());
}
sentence[0] = sentence[0].charAt(0).toUpperCase() + sentence[0].slice(1);
sentences.push(sentence.join(' ') + '.');
}
return sentences.join(' ');
},
generateParagraphs(count, startWithLorem) {
let paragraphs = [];
if (startWithLorem) {
paragraphs.push('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
count -= 1;
}
for (let i = 0; i < count; i++) {
const sentenceCount = Math.floor(Math.random() * 4) + 3;
let paragraph = [];
for (let j = 0; j < sentenceCount; j++) {
const wordCount = Math.floor(Math.random() * 12) + 6;
let sentence = [];
for (let k = 0; k < wordCount; k++) {
sentence.push(this.getRandomWord());
}
sentence[0] = sentence[0].charAt(0).toUpperCase() + sentence[0].slice(1);
paragraph.push(sentence.join(' ') + '.');
}
paragraphs.push(paragraph.join(' '));
}
return paragraphs.join('\n\n');
},
getRandomWord() {
return this.loremWords[Math.floor(Math.random() * this.loremWords.length)];
},
copy() {
const output = document.getElementById('lorem-output').value;
if (output) {
navigator.clipboard.writeText(output).then(() => {
this.showMessage('Copied to clipboard!', 'success');
});
}
},
clear() {
document.getElementById('lorem-output').value = '';
},
showMessage(message, type) {
const notification = document.createElement('div');
notification.className = `status-message ${type}`;
notification.textContent = message;
notification.style.position = 'fixed';
notification.style.top = '20px';
notification.style.right = '20px';
notification.style.zIndex = '1000';
notification.style.minWidth = '300px';
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 3000);
}
};
// QR Code Generator Tool
const qrGenerator = {
currentQR: null,
generate() {
const input = document.getElementById('qr-input').value;
const size = parseInt(document.getElementById('qr-size').value);
const errorLevel = document.getElementById('qr-error').value;
const container = document.getElementById('qr-canvas-container');
if (!input.trim()) {
this.showMessage('Please enter content to generate QR code', 'error');
return;
}
// Clear previous QR code
container.innerHTML = '';
try {
// Create QR code
this.currentQR = new QRCode(container, {
text: input,
width: size,
height: size,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel[errorLevel]
});
this.showMessage('QR code generated successfully!', 'success');
} catch (error) {
this.showMessage('Error generating QR code: ' + error.message, 'error');
}
},
download() {
const container = document.getElementById('qr-canvas-container');
const canvas = container.querySelector('canvas');
if (!canvas) {
this.showMessage('Please generate a QR code first', 'error');
return;
}
try {
// Convert canvas to blob and download
canvas.toBlob((blob) => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'qrcode.png';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
this.showMessage('QR code downloaded!', 'success');
});
} catch (error) {
this.showMessage('Error downloading QR code: ' + error.message, 'error');
}
},
clear() {
document.getElementById('qr-input').value = '';
document.getElementById('qr-canvas-container').innerHTML = '';
this.currentQR = null;
},
showMessage(message, type) {
const notification = document.createElement('div');
notification.className = `status-message ${type}`;
notification.textContent = message;
notification.style.position = 'fixed';
notification.style.top = '20px';
notification.style.right = '20px';
notification.style.zIndex = '1000';
notification.style.minWidth = '300px';
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 3000);
}
};
// Global tools object for onclick handlers
const tools = {
diff: diffChecker,
caseConverter: caseConverter,
json: jsonFormatter,
base64: base64Tool,
uuid: uuidGenerator,
timestamp: timestampConverter,
bcrypt: bcryptHasher,
lorem: loremIpsumGenerator,
qr: qrGenerator
};
// Initialize all tools
document.addEventListener('DOMContentLoaded', () => {
navigation.init();
characterCounter.init();
markdownPreview.init();
colorPicker.init();
timestampConverter.init();
console.log('%c🚀 DevKit Loaded Successfully!', 'color: #6366f1; font-size: 16px; font-weight: bold;');
});