|
|
|
@ -2,6 +2,8 @@ document.querySelectorAll(".require-script").forEach(function(e) {
|
|
|
|
|
e.style.display = "inline-block";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let oTitle = document.title;
|
|
|
|
|
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
|
xhr.open("GET", "/dummy");
|
|
|
|
|
xhr.send();
|
|
|
|
@ -16,6 +18,7 @@ xhr.upload.addEventListener("progress", function(ev) {
|
|
|
|
|
let p = `${((d / t) * 100).toFixed(2)}%`;
|
|
|
|
|
if (p == "100.00%") {
|
|
|
|
|
document.getElementById("prgTxt").innerHTML = `Processing...`;
|
|
|
|
|
document.getElementById("prgUpload").style.width = p;
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById("prgUpload").style.width = p;
|
|
|
|
|
document.getElementById("prgTxt").innerHTML = `Uploading... <code>(${p})</code>`;
|
|
|
|
@ -37,6 +40,7 @@ xhr.addEventListener("progress", function(ev) {
|
|
|
|
|
document.getElementById("prgTxt").innerHTML = `Please wait, we're processing your file.`;
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById("prgUpload").style.width = p;
|
|
|
|
|
document.title = `[${p}] ${oTitle}`;
|
|
|
|
|
document.getElementById("prgTxt").innerHTML = `Uploading... <code>(${p})</code>`;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -56,40 +60,22 @@ function upload() {
|
|
|
|
|
let fd = new FormData();
|
|
|
|
|
fd.append("file", f);
|
|
|
|
|
fd.append("privacy", document.getElementById("privacy").value);
|
|
|
|
|
if (document.querySelector(".hc-container") && document.querySelector(".hc-container iframe")) {
|
|
|
|
|
if (document.querySelector("[data-hcaptcha-response]")) fd.append("h-captcha-response", document.querySelector("[data-hcaptcha-response]").getAttribute("data-hcaptcha-response"));
|
|
|
|
|
} else if (!document.querySelector(".hc-container iframe") && document.querySelector(".hc-container")) {
|
|
|
|
|
hcaptcha.render("cpt", {
|
|
|
|
|
sitekey: document.querySelector(".hc-container").getAttribute("data-sitekey")
|
|
|
|
|
});
|
|
|
|
|
document.getElementById("prgTxt").style.display = "none";
|
|
|
|
|
let er = document.createElement("div");
|
|
|
|
|
er.classList.add("err");
|
|
|
|
|
let et = document.createElement("p");
|
|
|
|
|
et.innerHTML = `Please solve the captcha.`;
|
|
|
|
|
er.append(et);
|
|
|
|
|
document.getElementById("progress").append(er);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (xhr.readyState !== 1) xhr.abort()
|
|
|
|
|
if (xhr.readyState != 1) xhr.abort()
|
|
|
|
|
xhr.send(fd);
|
|
|
|
|
document.getElementById("progress").style.display = "inline-block";
|
|
|
|
|
document.getElementById("prgUpload").style.width = "0%";
|
|
|
|
|
document.getElementById("prgTxt").style.display = "inline-block";
|
|
|
|
|
document.getElementById("prgBar").style.display = "inline-block";
|
|
|
|
|
document.getElementById("prgTxt").innerHTML = `Preparing to upload...`;
|
|
|
|
|
document.getElementById("jsFileUpload").setAttribute("disabled", "");
|
|
|
|
|
document.querySelectorAll(".err").forEach(function(e) {
|
|
|
|
|
e.remove();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (document.querySelector(".hc-container")) document.querySelector(".hc-container").style.display = "none";
|
|
|
|
|
|
|
|
|
|
xhr.onload = function() {
|
|
|
|
|
if (document.querySelector(".hc-container")) {
|
|
|
|
|
document.querySelector(".hc-container").style.display = "block";
|
|
|
|
|
hcaptcha.reset();
|
|
|
|
|
}
|
|
|
|
|
document.getElementById("jsFileUpload").removeAttribute("disabled");
|
|
|
|
|
console.log(xhr.responseText);
|
|
|
|
|
let j = JSON.parse(xhr.responseText);
|
|
|
|
@ -104,7 +90,25 @@ function upload() {
|
|
|
|
|
} else {
|
|
|
|
|
if (j.success) {
|
|
|
|
|
document.getElementById("prgUpload").style.width = "100%";
|
|
|
|
|
document.getElementById("prgTxt").innerHTML = `Uploaded. <a href="/f/${j.data.id}">${window.location.href.split("/").slice(0, 3).join("/")}/f/${j.data.id}</a>`;
|
|
|
|
|
if (j.requireCaptcha == true) {
|
|
|
|
|
document.querySelector(".hc-container").style.display = "block";
|
|
|
|
|
document.getElementById("prgUpload").style.width = "0%";
|
|
|
|
|
document.getElementById("prgTxt").style.display = "none";
|
|
|
|
|
document.getElementById("prgBar").style.display = "none";
|
|
|
|
|
|
|
|
|
|
let er = document.createElement("div");
|
|
|
|
|
er.classList.add("err");
|
|
|
|
|
let et = document.createElement("p");
|
|
|
|
|
et.innerHTML = "Please complete the CAPTCHA to keep your upload permanent.";
|
|
|
|
|
er.append(et);
|
|
|
|
|
document.getElementById("progress").append(er);
|
|
|
|
|
|
|
|
|
|
hcaptcha.render("cpt", {
|
|
|
|
|
sitekey: document.querySelector(".hc-container").getAttribute("data-sitekey")
|
|
|
|
|
});
|
|
|
|
|
document.title = `[CAPTCHA] ${oTitle}`;
|
|
|
|
|
sessionStorage.setItem(`current-upload-id`, j.data.id);
|
|
|
|
|
} else document.getElementById("prgTxt").innerHTML = `Uploaded. <a href="/f/${j.data.id}">${window.location.href.split("/").slice(0, 3).join("/")}/f/${j.data.id}</a>`;
|
|
|
|
|
} else {
|
|
|
|
|
console.log(j);
|
|
|
|
|
document.getElementById("prgTxt").style.display = "none";
|
|
|
|
@ -119,10 +123,6 @@ function upload() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xhr.onerror = function(e) {
|
|
|
|
|
if (document.querySelector(".hc-container")) {
|
|
|
|
|
document.querySelector(".hc-container").style.display = "block";
|
|
|
|
|
hcaptcha.reset();
|
|
|
|
|
}
|
|
|
|
|
document.getElementById("jsFileUpload").removeAttribute("disabled");
|
|
|
|
|
console.log(e, xhr.statusText);
|
|
|
|
|
document.getElementById("prgTxt").style.display = "none";
|
|
|
|
@ -133,4 +133,43 @@ function upload() {
|
|
|
|
|
er.append(et);
|
|
|
|
|
document.getElementById("progress").append(er);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sendCaptcha(response) {
|
|
|
|
|
let fd = new FormData();
|
|
|
|
|
fd.append("h-captcha-response", response);
|
|
|
|
|
|
|
|
|
|
document.querySelector(".hc-container").style.display = "none";
|
|
|
|
|
hcaptcha.reset();
|
|
|
|
|
|
|
|
|
|
document.getElementById("prgBar").style.display = "inline-block";
|
|
|
|
|
document.getElementById("progress").style.display = "inline-block";
|
|
|
|
|
document.getElementById("prgUpload").style.width = "0%";
|
|
|
|
|
document.getElementById("prgTxt").style.display = "inline-block";
|
|
|
|
|
document.getElementById("prgTxt").innerHTML = `Preparing to send CAPTCHA...`;
|
|
|
|
|
|
|
|
|
|
document.querySelectorAll(".err").forEach(function(e) {
|
|
|
|
|
e.remove();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
xhr.open(`POST`, `/f/${sessionStorage.getItem(`current-upload-id`)}/confirm`);
|
|
|
|
|
xhr.send(fd);
|
|
|
|
|
xhr.onload = function() {
|
|
|
|
|
console.log(xhr.responseText);
|
|
|
|
|
let j = JSON.parse(xhr.responseText);
|
|
|
|
|
|
|
|
|
|
if (j.success == true) {
|
|
|
|
|
document.getElementById("prgTxt").innerHTML = `Uploaded. <a href="/f/${sessionStorage.getItem("current-upload-id")}">${window.location.href.split("/").slice(0, 3).join("/")}/f/${sessionStorage.getItem("current-upload-id")}</a>`;
|
|
|
|
|
sessionStorage.removeItem("current-upload-id");
|
|
|
|
|
} else {
|
|
|
|
|
hcaptcha.reset();
|
|
|
|
|
document.getElementById("prgTxt").style.display = "none";
|
|
|
|
|
let er = document.createElement("div");
|
|
|
|
|
er.classList.add("err");
|
|
|
|
|
let et = document.createElement("p");
|
|
|
|
|
et.innerHTML = j.err;
|
|
|
|
|
er.append(et);
|
|
|
|
|
document.getElementById("progress").append(er);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|