bin/templates/index.html.tera
Gunwant Jain 150bade1e5 css: change placeholder and made the UI generally tighter
Also I have encouraged the user to change their monospace font
accordingly for the best personal satisfaction.

Signed-off-by: Gunwant Jain <mail@wantguns.dev>
2021-06-19 08:07:25 +05:30

150 lines
3.4 KiB
Plaintext

{% extends "base" %}
{% block styles %}
html, body {
overflow-y:hidden;
}
body {
height: 100vh;
font-family: monospace;
display: flex;
}
form { flex: 1; }
textarea {
height: 90%;
width: 100%;
background: none;
border: none;
resize: none;
overflow: auto;
color: inherit;
font-family: monospace;
line-height: inherit;
}
button[type="submit"] {
position: absolute;
bottom: 1rem;
right: 1rem;
height: 4rem;
width: 4rem;
border: none;
border-radius: 50%;
background: #F29718;
font-size: 0rem;
cursor: pointer;
}
*:focus {
outline: none;
}
button[type="submit"].hidden { display: none; }
{% endblock styles %}
{% block body %}
<form action="/submit" method="post">
<textarea name="val" style="resize: none" ondrop="dropHandler(event);" ondragover="dragOverHandler(event);" placeholder="
bin(3) Bin Manual bin(3)
NAME
bin - A highly opinionated and minamalistic Pastebin
WEB USAGE
Drag a file and drop it here, or
After typing, press the big yellow button to paste, or
Just press Ctrl + Enter once done.
CLI USAGE
curl -Ls -o /dev/null -w %{url_effective} --data-binary @file.txt https://bin.wantguns.dev
Better use cases of CLI mentioned at Github
SEE ALSO
github.com/wantguns/bin
AUTHOR
Gunwant Jain
2021-06-19 bin(3)
" autofocus autocomplete="off" autocorrect="off" autocapitalize="off"
spellcheck="false"></textarea>
<button type="submit" title="Paste">&#x2398</button>
</form>
<script>
const form = document.querySelector('form');
const input = document.querySelector('textarea');
const button = document.querySelector('button[type="submit"]');
const onInput = () => button.classList.toggle('hidden', !input.value);
input.addEventListener('input', onInput);
onInput();
document.body.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && e.ctrlKey) {
form.submit();
}
});
async function postData(url = '', data) {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: data
});
return response;
}
function dropHandler(ev) {
console.log('File(s) dropped');
ev.preventDefault();
if (ev.dataTransfer.items) {
for (var i = 0; i < ev.dataTransfer.items.length; i++) {
if (ev.dataTransfer.items[i].kind === 'file') {
var file = ev.dataTransfer.items[i].getAsFile();
console.log('... file[' + i + '].name = ' + file.name);
var url = window.location.href;
postData(url, file)
.then(data => {
window.location.href = data.url;
})
.catch(function (err) {
console.info(err + " url: " + url);
});
}
}
} else {
for (var i = 0; i < ev.dataTransfer.files.length; i++) {
console.log('... file[' + i + '].name = ' + ev.dataTransfer.files[i].name);
}
}
}
function dragOverHandler(ev) {
console.log('File(s) in drop zone');
ev.preventDefault();
}
</script>
{% endblock body %}