61 lines
2.4 KiB
Plaintext
61 lines
2.4 KiB
Plaintext
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link rel="stylesheet" href="style.css">
|
|
<title>New Paste</title>
|
|
<script>
|
|
function alert(text) {
|
|
var alert = document.createElement("div");
|
|
alert.className = "alert";
|
|
alert.innerHTML = text;
|
|
document.body.appendChild(alert);
|
|
setTimeout(function() {
|
|
document.body.removeChild(alert);
|
|
}, 3000);
|
|
}
|
|
function savePaste() {
|
|
document.getElementById('save-button').style = 'display: none';
|
|
let xhr = new XMLHttpRequest();
|
|
xhr.open("POST", "/write");
|
|
|
|
xhr.setRequestHeader("Accept", "application/json");
|
|
xhr.setRequestHeader("Content-Type", "application/json");
|
|
|
|
let text = document.getElementById('editor').value;
|
|
let name = document.getElementById('name').value;
|
|
|
|
let data = JSON.stringify({"text": text, "name": name});
|
|
|
|
xhr.send(data);
|
|
|
|
xhr.onload = () => {
|
|
let rq = xhr.responseText;
|
|
if (xhr.status == 200) {
|
|
alert("Paste saved! Redirecting...");
|
|
setTimeout(() => {window.location.href = "/paste/" + rq;}, 1000);
|
|
} else {
|
|
document.getElementById('save-button').style = 'display: block';
|
|
}
|
|
};
|
|
}
|
|
function goToHome() {
|
|
window.location.href = "/";
|
|
}
|
|
</script>
|
|
</head>
|
|
<body style="overflow-y:hidden">
|
|
<div class="editor-box">
|
|
<div class="editor-header">
|
|
<div class="button-custom-box"><button type="button" class="button-custom" onclick="savePaste()" id="save-button">Save</button></div>
|
|
<div class="button-custom-box"><button type="button" class="button-custom" onclick="goToHome()" id="save-button">Home</button></div>
|
|
<div class="name-box"><input placeholder="<Empty>" type="text" id="name" autocomplete="off" spellcheck="off"></input></div>
|
|
</div>
|
|
<div class="editor">
|
|
<textarea placeholder="Enter some text to get started!" id="editor" spellcheck="off" autofocus="on" autocomplete="off"></textarea>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |