-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (65 loc) · 1.95 KB
/
script.js
File metadata and controls
76 lines (65 loc) · 1.95 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
document.getElementById("fileInput").addEventListener("change", processFiles)
document.getElementById('clearButton').addEventListener('click', clearAll);
function processFiles() {
const input = document.getElementById("fileInput")
const resultDiv = document.getElementById("result")
resultDiv.innerHTML = "" // Clear previous results
if (input.files.length === 0) {
resultDiv.innerHTML = "Please select some files."
return
}
Array.from(input.files).forEach((file) => {
let fileName = file.name
// Remove the file extension
fileName = fileName.replace(/\.[^/.]+$/, "")
// Remove specified substrings
const patterns = [
/-720p/,
/-480p/,
/-360p/,
/-v1x/,
/-v1u/,
/-v2x/,
/-v2u/,
/h1x/,
/h1u/,
/h2x/,
/h2u/,
]
patterns.forEach((pattern) => {
fileName = fileName.replace(pattern, "")
})
// Replace remaining dashes with spaces
fileName = fileName.replace(/-/g, " ")
// Capitalize the first letter of each word
fileName = fileName
.split(" ")
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join(" ")
// Create a clickable element for the formatted name
const p = document.createElement("p")
p.textContent = fileName
p.onclick = () => {
copyToClipboard(fileName)
p.style.backgroundColor = "#f3c669" // Change background color on copy
}
resultDiv.appendChild(p)
})
}
function copyToClipboard(text) {
navigator.clipboard
.writeText(text)
.then(() => showToast(`Copied: ${text}`))
.catch((err) => showToast("Failed to copy text."))
}
function showToast(message) {
const toast = document.getElementById("toast")
toast.textContent = message
toast.style.opacity = 1
setTimeout(() => {
toast.style.opacity = 0
}, 2000) // Toast duration
}
function clearAll() {
document.getElementById('result').innerHTML = ''; // Clear the displayed names
}