49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
//Clipboard stuff
|
|
const baseurl = "https://kauft.es";
|
|
const btn = document.getElementById("shorturl_copy");
|
|
const clipboard = new ClipboardJS(btn);
|
|
clipboard.on('success', function (e) {
|
|
console.info('Action:', e.action);
|
|
console.info('Text:', e.text);
|
|
new Notification('Notification title', {
|
|
icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
|
|
body: 'Hey there! You\'ve been notified!',
|
|
});
|
|
});
|
|
|
|
document.getElementById("create").onclick = createUrl;
|
|
// Calls the api to create a new short url
|
|
function createUrl() {
|
|
shorturl = {
|
|
target: window.location.href,
|
|
shortcode: document.getElementById("shortcode").value
|
|
};
|
|
if (shorturl.shortcode == "" | !shorturl.shortcode) {
|
|
delete shorturl.shortcode;
|
|
}
|
|
|
|
fetch(`${baseurl}/api`, {
|
|
method: "POST",
|
|
body: JSON.stringify(shorturl),
|
|
headers: new Headers({
|
|
'Content-Type': 'application/json'
|
|
})
|
|
})
|
|
.then(res => res.json())
|
|
.then(res => {
|
|
document.getElementById("shorturl").innerText = res.url;
|
|
document.getElementById("shorturl_container").className = "";
|
|
document.getElementById("shortcode_container").className = "hidden";
|
|
document.getElementById("create").classList.add("hidden");
|
|
document.getElementById("reset").classList.remove("hidden");
|
|
});
|
|
}
|
|
|
|
document.getElementById("reset").onclick = reset;
|
|
function reset() {
|
|
document.getElementById("shorturl").innerText = "";
|
|
document.getElementById("shortcode_container").className = "";
|
|
document.getElementById("shorturl_container").className = "hidden";
|
|
document.getElementById("reset").classList.add("hidden");
|
|
document.getElementById("create").classList.remove("hidden");
|
|
} |