@copoko/space
Version:
CoPoKo Space
101 lines • 2.99 kB
HTML
<script>
Space = {}
Space.helper = {
headers_json: {
"content-type": "application/json",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",
}
}
Space.KV = {}
Space.KV.Get = (key) => {
return fetch("/space/api/kv/get", {
method: "POST",
headers: Space.helper.headers_json,
body: JSON.stringify({
"key": key,
})
}).then(function (response) {
return response.json();
})
}
Space.KV.Delete = (key) => {
return fetch("/space/api/kv/delete", {
method: "POST",
headers: Space.helper.headers_json,
body: JSON.stringify({
"key": key,
})
}).then(function (response) {
return response.json();
})
}
Space.KV.Put = (key, value) => {
return fetch("/space/api/kv/put", {
method: "POST",
headers: Space.helper.headers_json,
body: JSON.stringify({
"key": key,
"value": value,
})
}).then(function (response) {
return response.json();
})
}
var Toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 3000
});
Space.GoogleSearch = (question) => {
return fetch("/space/api/GoogleSearch?s=" + question, {
method: "Get",
headers: Space.helper.headers_json,
}).then(function (response) {
return response.json();
})
}
Space.WolframAlpha = (question) => {
return fetch("/space/api/WolframAlpha?s=" + question, {
method: "Get",
headers: Space.helper.headers_json,
}).then(function (response) {
return response.json();
})
}
Space.friendlyFeatureTime = (dateTimeStamp) => {
const minute = 1e3 * 60, hour = minute * 60, day = hour * 24, week = day * 7, month = day * 30;
const now = new Date().getTime();
const diffValue = dateTimeStamp - now;
const minC = Math.round(diffValue / minute),
hourC = Math.round(diffValue / hour),
dayC = Math.round(diffValue / day),
weekC = Math.round(diffValue / week),
monthC = Math.round(diffValue / month);
if (diffValue <= 0) {
result = ""
} else if (weekC >= 1 && weekC <= 4) {
result = " " + weekC + " week"
if (weekC > 1) result += "s"
} else if (dayC >= 1 && dayC < 7) {
result = " " + dayC + " day"
if (dayC > 1) result += "s"
} else if (hourC >= 1 && hourC < 24) {
result = " " + hourC + " hour"
if (hourC > 1) result += "s"
} else if (minC >= 1 && minC < 60) {
result = " " + minC + " min"
if (minC > 1) result += "s"
} else {
result = " " + monthC + " month"
if (monthC > 1) result += "s"
}
return result;
}
Space.UUID = () => {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
</script>