This repository has been archived on 2023-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
Uloz.to-rychle/public/index.html
2023-02-07 14:02:37 +01:00

78 lines
3.1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Ulož.to Rychle</title>
<style>
body {display: flex; justify-content: center; align-items: center; height: 100vh; font-family: sans-serif; text-align: center; font-size: 17px; background: #4a0f4d; color: #fff; line-height: 1.5;}
.page {max-width: 550px; width: 100%;}
.input {display: flex; gap: 5px; flex-flow: row; justify-content: space-between; width: 100%; margin-top: 30px;}
.input *, .result {background-color: #702673; border: 2px solid #330a35; border-radius: 5px; padding: 10px 15px; font-size: 17px; outline: 0; color: #fff;}
.input input {width: 100%;}
.input button {background: #702673;}
.input button:hover {background-color: #4a0f4d; cursor: pointer;}
.result {padding: 15px; margin-top: 20px; display: none; text-align: left; flex-direction: column; gap: 10px;}
.result a {color: #fff8;}
.result .info {display: flex; flex-direction: column; gap: 5px;}
.result .download {display: flex; gap: 10px; flex-wrap: wrap; font-size: 15px;}
.result :is(small, .linkback) {font-size: 14px;}
.status {display: none; text-align: center; margin-top: 20px;}
</style>
</head>
<body>
<div class="page">
<h1>Ulož.to Rychle</h1>
<p>Stahujte z Ulož.to vysokou rychlostí</p>
<div class="input">
<input placeholder="Vložte odkaz z Ulož.to" /> <button onclick="download();">Získat</button>
</div>
<div class="result"></div>
<div class="status">Získávám informace o souboru...</div>
</div>
<script>
async function download() {
let url = document.querySelector("input").value;
let regex = new RegExp(/https:\/\/.*(ulozto\.cz|uloz\.to)\/file\/(.*?)\/.*/gm);
let res = regex.exec(url);
if(!res) return alert("Neplatná URL!");
let id = res[2];
let new_url = new URL(`/u/${id}`, location.origin);
let result = document.querySelector(".result");
let status = document.querySelector(".status");
status.style.display = "block";
try {
let info = await api(`/status/${id}`);
result.style.display = "flex";
result.innerHTML = `<div class="info"><div><b>${info.file.name}</b> <a target="_blank" class="linkback" href="https://uloz.to/file/${id}">ulož.to</a></div><small>${parse_size(info.file.size)}</small></div><div class="download"><code>${new_url}</code> <a href="${new_url}" download="${info.file.name}">Stáhnout</a></div>`;
} catch {
alert("Neplatná URL!");
}
status.style.display = "none";
}
async function api(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(this.readyState !== 4) return;
if(!this.responseText) reject(this);
try {
resolve(JSON.parse(this.responseText));
} catch(e) {
resolve({error: "api"});
}
};
xhr.open("GET", url, true);
xhr.send();
});
}
function parse_size(bytes) {
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
let unitIndex = 0;
while (bytes >= 1024) {
bytes /= 1024;
unitIndex++;
}
return `${bytes.toFixed(2)} ${units[unitIndex]}`;
}
</script>
</body>
</html>