$.ajax({ url: `https://api.nasa.gov/planetary/apod?api_key=1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et&start_date=${new Date().toLocaleString().slice(6, 10)}-${new Date().toLocaleString().slice(3, 5)}-01&end_date=${new Date().toLocaleString().slice(6,10)}-${new Date().toLocaleString().slice(3, 5)}-${new Date().toLocaleString().slice(0,2)}`, type: "GET", success: function(data){ Wallpaper(data) }, error: function(){ let prev_date = Number(new Date().toLocaleString().slice(0,2)) this.url = `https://api.nasa.gov/planetary/apod?api_key=1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et&start_date=${new Date().toLocaleString().slice(6, 10)}-${new Date().toLocaleString().slice(3, 5)}-01&end_date=${new Date().toLocaleString().slice(6,10)}-${new Date().toLocaleString().slice(3, 5)}-${prev_date-1}`, $.ajax({ url: this.url, type: "GET", success: function(data){ Wallpaper(data) } }) } }); const myModal = new bootstrap.Modal('#Wallpaper', { keyboard: false }) myModal.show() function Wallpaper(data) { $(".preloader").fadeOut(0) for (let i = 0; i < data.length; i++) { if (data[i].media_type === "image") { $(".header-row").append(`
`) } else { $(".header-row").append(` `) } let buttons = document.querySelector(".header-row") buttons.addEventListener("click", function (event) { if (event.target.tagName === "IMG") { let id = event.target.getAttribute("idi") let img = document.querySelector(".modal-body") let title = document.querySelector(".w-modal-title") let button = document.querySelector(".modal-footer") button.innerHTML = ` ` let setWallpaper = document.querySelector("#setWallpaper") if(data[id-1].media_type === "image") { img.innerHTML = `Author: ${data[id - 1].copyright}
Date of shooting: ${data[id - 1].date}
Explanation: ${data[id - 1].explanation}
`.replace("undefined", "Unknown") title.innerHTML = `Author: ${data[id - 1].copyright}
Date of shooting: ${data[id - 1].date}
Explanation: ${data[id - 1].explanation}
`.replace("undefined", "Unknown") title.innerHTML = `