This repository has been archived on 2024-06-10. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Backend/src/main/resources/static/assets/script.js
Liam c8e91ba949
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m45s
Publish Docker Image / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m14s
add hastebin compatibility
2024-06-04 19:16:10 +01:00

50 lines
1.2 KiB
JavaScript

// Handle custom key binds behavior
document.addEventListener("keydown", function (event) {
// Upload the paste when Ctrl + Enter is pressed
if (event.ctrlKey && event.key === "Enter") {
event.preventDefault();
upload();
}
});
// Upload the paste when the paste button is clicked
document.getElementById("paste-button").addEventListener("click", () => upload());
// Upload the paste to the server
const upload = async () => {
var pasteInput = document.getElementById("paste-input");
var paste = pasteInput.value;
if (!paste || paste.trim() === "") {
pasteInput.focus();
toast("Please enter a paste to upload.");
return;
}
console.log("Uploading paste...");
try {
const response = await fetch("/api/upload", {
method: "POST",
body: paste,
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.message);
}
window.location.href = "/" + data.id;
} catch (error) {
console.error("Error:", error);
toast(`${error.message || "An error occurred while uploading the paste."}`);
}
};
const toast = (message, duration = 3000) => {
Toastify({
text: message,
duration: duration,
gravity: "bottom",
position: "right"
}).showToast();
};