Fixed the code. I did the removal of unnecessary reits, the date is no longer transmitted as a number, now as a string

This commit is contained in:
Данил 2024-07-21 21:39:29 +03:00
parent 2478b6907e
commit 2f2046a8ae

View file

@ -1,7 +1,6 @@
function load(date) { function load(date) {
fetch(`https://api.starlio.space/wallpaper/${date}`).then(res => { fetch(`https://api.starlio.space/wallpaper/${date}`).then(res => {
res.json().then(data => { res.json().then(data => {
console.log(data);
if (data.length === 0) return; if (data.length === 0) return;
document.querySelector("div.wallpaper img").src = data.url; document.querySelector("div.wallpaper img").src = data.url;
@ -13,12 +12,13 @@ function load(date) {
} }
function parseURL() { function parseURL() {
const pathname = document.location.pathname let pathname = document.location.pathname
pathname = pathname.slice(pathname.lastIndexOf('/')+1)
if (isNaN(new Date(pathname).getTime())) return null; if (isNaN(new Date(pathname).getTime())) return null;
if (!isValidDate(pathname)) return null; if (!isValidDate(pathname)) return null;
return Number(pathname); return pathname;
} }