-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
94 lines (83 loc) · 2.77 KB
/
Copy pathscripts.js
File metadata and controls
94 lines (83 loc) · 2.77 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
// ========================================
// Utility Functions and Helpers
// ========================================
// Utility function to escape HTML
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// Utility function to format relative time
function formatRelativeTime(dateString) {
const date = new Date(dateString);
const now = new Date();
const diffMs = now - date;
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
const diffMinutes = Math.floor(diffMs / (1000 * 60));
if (diffDays > 0) {
return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`;
} else if (diffHours > 0) {
return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`;
} else if (diffMinutes > 0) {
return `${diffMinutes} minute${diffMinutes > 1 ? 's' : ''} ago`;
} else {
return 'Just now';
}
}
// Utility function to generate UUID
function 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);
});
}
// Utility function to copy text to clipboard
function copyToClipboard(elementId) {
const element = document.getElementById(elementId);
if (element) {
element.select();
document.execCommand('copy');
showToast('Copied to clipboard!', 'success');
}
}
// Utility function to toggle password visibility
function togglePasswordVisibility(inputId) {
const input = document.getElementById(inputId);
if (input) {
if (input.type === 'password') {
input.type = 'text';
} else {
input.type = 'password';
}
}
}
// Utility function to read file as ArrayBuffer
function readFileAsArrayBuffer(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsArrayBuffer(file);
});
}
// Utility function to clean text
function cleanText(text) {
return text
.replace(/\r\n/g, '\n')
.replace(/\r/g, '\n')
.replace(/\s+/g, ' ')
.trim();
}
// ========================================
// Global Exports
// ========================================
window.escapeHtml = escapeHtml;
window.formatRelativeTime = formatRelativeTime;
window.generateUUID = generateUUID;
window.copyToClipboard = copyToClipboard;
window.togglePasswordVisibility = togglePasswordVisibility;
window.readFileAsArrayBuffer = readFileAsArrayBuffer;
window.cleanText = cleanText;
console.log('Scripts.js loaded successfully');