<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>File Converter</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f4f7fc;
margin: 0;
padding: 0;
display: flex;
min-height: 100vh;
flex-direction: column;
align-items: center;
justify-content: flex-start;
}
header {
background-color: #2f80ed;
width: 100%;
color: white;
padding: 1rem;
text-align: center;
font-size: 1.6rem;
font-weight: bold;
box-shadow: 0 2px 6px rgba(47,128,237,.3);
}
main {
flex: 1;
padding: 2rem;
width: 100%;
max-width: 500px;
text-align: center;
background: white;
margin-top: 2rem;
border-radius: 8px;
box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
form {
margin-bottom: 1.5rem;
}
input[type="file"] {
display: block;
margin: 1rem auto;
}
.loading-container {
margin: 1rem 0;
height: 24px;
background: #eee;
border-radius: 12px;
overflow: hidden;
display: none;
}
.loading-bar {
height: 100%;
width: 0%;
background-color: #2f80ed;
transition: width 0.25s linear;
}
#file-info {
margin-bottom: 1rem;
min-height: 1.5rem;
}
button {
background-color: #2f80ed;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
padding: 0.6rem 1.3rem;
transition: background-color 0.3s ease;
}
button:disabled {
background-color: #8fb9f7;
cursor: not-allowed;
}
button:hover:not(:disabled) {
background-color: #1366d6;
}
#download-links {
margin-top: 1rem;
text-align: left;
}
#download-links a {
display: block;
margin-bottom: 0.5rem;
text-decoration: none;
color: #2f80ed;
word-break: break-all;
}
</style>
</head>
<body>
<header>Universal File Converter</header>
<main>
<form id="uploadForm">
<label for="fileInput">Select file(s) to convert:</label>
<input type="file" id="fileInput" name="files" multiple />
<button type="submit" id="uploadBtn">Upload & Convert</button>
</form>
<div class="loading-container" id="loadingContainer" aria-label="Uploading progress">
<div class="loading-bar" id="loadingBar"></div>
</div>
<div id="file-info" aria-live="polite"></div>
<div id="download-links"></div>
</main>
<script>
/*
This is a demo "file converter" — since converting arbitrary files is complex and files could
be anything, this demo just lets you upload any file(s), simulates a 10-second upload with a progress bar,
and then provides download links to the exact same files (simulating a conversion).
In a real app, you'd send files to a server to convert and provide real converted file downloads.
*/
const form = document.getElementById("uploadForm");
const fileInput = document.getElementById("fileInput");
const loadingContainer = document.getElementById("loadingContainer");
const loadingBar = document.getElementById("loadingBar");
const fileInfo = document.getElementById("file-info");
const downloadLinks = document.getElementById("download-links");
const uploadBtn = document.getElementById("uploadBtn");
form.addEventListener("submit", async (e) => {
e.preventDefault();
if (!fileInput.files.length) {
alert("Please select at least one file to upload.");
return;
}
// Reset UI elements
downloadLinks.innerHTML = "";
fileInfo.textContent = "";
loadingBar.style.width = "0%";
loadingContainer.style.display = "block";
uploadBtn.disabled = true;
fileInput.disabled = true;
// Simulate 10 second upload with progress bar
const totalDuration = 10000; // 10 seconds
const updateInterval = 100; // ms
let elapsed = 0;
await new Promise((resolve) => {
const interval = setInterval(() => {
elapsed += updateInterval;
let percent = Math.min((elapsed / totalDuration) * 100, 100);
loadingBar.style.width = percent + "%";
if (percent >= 100) {
clearInterval(interval);
resolve();
}
}, updateInterval);
});
loadingContainer.style.display = "none";
uploadBtn.disabled = false;
fileInput.disabled = false;
fileInfo.textContent = `Upload complete! You can download the converted file(s) below:`;
// Since no real conversion, just provide a download link to the original files.
// Create blob URLs for each file.
downloadLinks.innerHTML = "";
Array.from(fileInput.files).forEach((file, index) => {
// Simulate conversion by appending "-converted" before extension
let name = file.name;
let dotIndex = name.lastIndexOf(".");
let convertedName;
if (dotIndex === -1) {
// No extension
convertedName = name + "-converted";
} else {
convertedName = name.slice(0, dotIndex) + "-converted" + name.slice(dotIndex);
}
// Create a fake converted file Blob by reading the original file as ArrayBuffer
// and returning the exact same data (i.e. no modification)
// Note: file objects can be reused for Blob URLs without processing, but for simulation we wrap.
// Here, just reuse the original file object for download URL directly.
const url = URL.createObjectURL(file);
const a = document.createElement("a");
a.href = url;
a.download = convertedName;
a.textContent = `Download: ${convertedName}`;
a.rel = "noopener";
a.target = "_blank";
downloadLinks.appendChild(a);
});
});
</script>
</body>
</html>