-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
95 lines (77 loc) · 3.64 KB
/
Copy pathscript.js
File metadata and controls
95 lines (77 loc) · 3.64 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
// 1. Word Counter
const wordInput = document.getElementById('wordInput');
const wordCount = document.getElementById('wordCount');
const charCount = document.getElementById('charCount');
if(wordInput) {
wordInput.addEventListener('input', () => {
const text = wordInput.value.trim();
// Count words by splitting by spaces, filter empty strings
const words = text.length > 0 ? text.split(/\s+/).filter(word => word.length > 0).length : 0;
wordCount.innerText = words;
charCount.innerText = text.length;
});
}
// 2. Case Converter
const caseInput = document.getElementById('caseInput');
function convertUpperCase() {
if(caseInput) caseInput.value = caseInput.value.toUpperCase();
}
function convertLowerCase() {
if(caseInput) caseInput.value = caseInput.value.toLowerCase();
}
// 3. Password Generator
function generatePassword() {
const length = document.getElementById('passLength').value;
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()";
let password = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
password += charset[randomIndex];
}
document.getElementById('passwordOutput').innerText = password;
}
// 4. Random Color Generator
function generateColor() {
const randomColor = "#" + Math.floor(Math.random()*16777215).toString(16).padStart(6, '0');
document.getElementById('colorDisplay').style.backgroundColor = randomColor;
document.getElementById('colorCode').innerText = randomColor;
// Set text color to black or white for contrast (simple logic)
document.getElementById('colorDisplay').style.color = "transparent";
}
// Initialize with a random color
generateColor();
// 5. Lorem Ipsum Generator
function generateLorem() {
const loremText = "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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.";
// Shuffle words slightly to make it look "generated" or just repeat it
document.getElementById('loremOutput').innerText = loremText;
}
// 6. Image Info Tool
const imageInput = document.getElementById('imageInput');
const imageDetails = document.getElementById('imageDetails');
const imagePreview = document.getElementById('imagePreview');
const imgSize = document.getElementById('imgSize');
const imgDim = document.getElementById('imgDim');
if(imageInput) {
imageInput.addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
// Show details container
imageDetails.classList.remove('hidden');
// Set Size (KB)
imgSize.innerText = (file.size / 1024).toFixed(2);
// Create Preview and get Dimensions
const reader = new FileReader();
reader.onload = function(e) {
imagePreview.src = e.target.result;
// Create an off-screen image to get natural dimensions
const img = new Image();
img.src = e.target.result;
img.onload = function() {
imgDim.innerText = `${this.naturalWidth} x ${this.naturalHeight}`;
};
};
reader.readAsDataURL(file);
}
});
}