2024-07-21 21:06:49 +03:00
|
|
|
function load(date) {
|
|
|
|
fetch(`https://api.starlio.space/wallpaper/${date}`).then(res => {
|
|
|
|
res.json().then(data => {
|
|
|
|
if (data.length === 0) return;
|
|
|
|
|
2024-07-22 22:31:18 +03:00
|
|
|
document.querySelector("div.wallpaper img").src = data.hdurl;
|
|
|
|
document.querySelector("div.wallpaper img").alt = data.title;
|
2024-07-21 21:06:49 +03:00
|
|
|
document.querySelector("div.wallpaper div.wallpaper-text div.wallpaper-desc h1").innerHTML = data.title;
|
2024-07-22 22:31:18 +03:00
|
|
|
document.querySelector(".copyright").innerHTML = data.copyright ? `Copyright: ${data.copyright}` : ''
|
2024-07-21 21:06:49 +03:00
|
|
|
document.querySelector(".desc").innerHTML = data.explanation;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseURL() {
|
2024-07-23 17:57:46 +03:00
|
|
|
let pathname = document.location.pathname;
|
2024-07-21 21:39:29 +03:00
|
|
|
pathname = pathname.slice(pathname.lastIndexOf('/')+1)
|
2024-07-21 21:06:49 +03:00
|
|
|
|
2024-07-29 11:22:21 +03:00
|
|
|
if (isNaN(new Date(pathname).getTime())) return window.location.replace("../404.html");
|
|
|
|
if (!isValidDate(pathname)) return window.location.replace("../404.html");
|
2024-07-21 21:06:49 +03:00
|
|
|
|
2024-07-21 21:39:29 +03:00
|
|
|
return pathname;
|
2024-07-21 21:06:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* THX, bro <3
|
|
|
|
https://stackoverflow.com/a/35413963/20781634
|
|
|
|
*/
|
|
|
|
function isValidDate(dateString) {
|
|
|
|
var regEx = /^\d{4}-\d{2}-\d{2}$/;
|
|
|
|
if(!dateString.match(regEx)) return false;
|
|
|
|
var d = new Date(dateString);
|
|
|
|
var dNum = d.getTime();
|
|
|
|
if(!dNum && dNum !== 0) return false;
|
|
|
|
return d.toISOString().slice(0,10) === dateString;
|
|
|
|
}
|
|
|
|
|
|
|
|
load(parseURL());
|