Rewrite home page in svelte

This commit is contained in:
2021-06-22 17:14:21 +02:00
parent d8e4fe3cb2
commit 14bc345ec8
12 changed files with 830 additions and 126 deletions

View File

@@ -36,12 +36,12 @@ const minute = second*60
const hour = minute*60
const day = hour*24
export const formatDuration = (ms) => {
export const formatDuration = (ms, decimals) => {
let res = ""
if (ms >= day) { res += Math.floor(ms/day) + "d " }
if (ms >= hour) { res += Math.floor((ms%day)/hour) + "h " }
if (ms >= minute) { res += Math.floor((ms%hour)/minute) + "m " }
return res + ((ms%minute)/second).toFixed(3) + "s"
return res + ((ms%minute)/second).toFixed(decimals) + "s"
}
export const formatDate = (date, hours, minutes, seconds) => {

View File

@@ -0,0 +1,38 @@
<script context="module">
export function print_date(date, hours, minutes, seconds) {
let dateStr = date.getFullYear()
+ "-" + ("00" + (date.getMonth() + 1)).slice(-2)
+ "-" + ("00" + date.getDate()).slice(-2)
if (hours) { dateStr += " " + ("00" + date.getHours()).slice(-2) }
if (minutes) { dateStr += ":" + ("00" + date.getMinutes()).slice(-2) }
if (seconds) { dateStr += ":" + ("00" + date.getMinutes()).slice(-2) }
return dateStr
}
export function copy_text(text) {
// Create a textarea to copy the text from
let ta = document.createElement("textarea");
ta.setAttribute("readonly", "readonly")
ta.style.position = "absolute";
ta.style.left = "-9999px";
ta.value = text; // Put the text in the textarea
// Add the textarea to the DOM so it can be seleted by the user
document.body.appendChild(ta);
ta.select() // Select the contents of the textarea
let success = document.execCommand("copy"); // Copy the selected text
document.body.removeChild(ta); // Remove the textarea
return success;
}
export function domain_url() {
let url = window.location.protocol + "//" + window.location.hostname;
if (window.location.port != "") {
url = url + ":" + window.location.port;
}
return url;
}
</script>