const startDate = new Date(); const endDate = new Date(); const ids = []; let id = ids.length; const apiKEY = "1gI9G84ZafKDEnrbydviGknReOGiVK9jqrQBE3et"; function wallpaperLoad(data) { $(".preloader").hide(); for (let i = 0; id < data.length; i++, id++) { ids.push(data[i]); if (ids.filter((item) => item['url'] === data[i]['url']).length > 1) continue; const image = new Image(); image.src = ids[id]['media_type'] === "video" ? `https://ytproxy.dc09.ru/vi/${ids[id]['url'].slice(30, 41)}/maxresdefault.jpg?host=i.ytimg.com` : ids[id]['url']; image.onload = function () { if (image.width + image.height !== 210) { $(`img[data-src="${image.src}"]`) .attr("src", `${image.src}`) .removeAttr("data-src"); } } if (ids[id]['media_type'] === "image") { $(".header-row").append(`
`) } else { $(".header-row").append(` `) } } $(".card-img-top").on("load", function () { $(this).removeClass("shimmer"); }); const button_modal_window = document.querySelector(".header-row"); button_modal_window.addEventListener("click", function (event) { if (event.target === button_modal_window) return; const card_id = event.target.getAttribute("id"); const modale_window = document.querySelector(".modal-body"); const title = document.querySelector(".w-modal-title"); const button = document.querySelector(".modal-footer"); button.innerHTML = `${ids[card_id]['explanation']}
`; setWallpaper.addEventListener("click", function () { updateWallpaper(card_id[card_id]['hdurl']); }); } else { const host = new URL(ids[card_id]['url']); if (["youtube.com", "youtu.be", "yt.be"].includes(host.hostname.replace("www.", ""))) { ids[card_id]['url'] = `https://yt.dc09.ru${host.pathname}` } modale_window.innerHTML = `${ids[card_id]['explanation']}
` setWallpaper.addEventListener("click", function () { updateWallpaper(`https://ytproxy.dc09.ru/vi/${ids[card_id]['url'].substring(25)}/maxresdefault.jpg?host=i.ytimg.com`) }); } if (ids[card_id]['copyright'] !== undefined) { return modale_window.innerHTML += `© ${ids[card_id]['copyright']}
`; } }); $(window).scroll(function () { if (($(window).scrollTop() > $(document).height() - $(window).height() - 100)) { $(".preloader").show(); $(window).off("scroll"); startDate.setDate(startDate.getDate() - 1); endDate.setDate(endDate.getDate() - 15); endDate.setMonth(endDate.getMonth() - 1); $.ajax({ url: "https://api.nasa.gov/planetary/apod", data: { api_key: apiKEY, start_date: `${endDate.getUTCFullYear()}-${endDate.getUTCMonth() + 1}-${endDate.getUTCDate()}`, end_date: `${startDate.getUTCFullYear()}-${startDate.getUTCMonth() + 1}-${startDate.getUTCDate()}`, }, success: function (data) { wallpaperLoad(data); $(window).on("scroll"); }, }); } }); } function updateWallpaper(url) { $.ajax({ url: "http://localhost:4000/api/update/wallpaper", type: "POST", data: { url: url }, success: function (data) { if (data.status) notify(data.message) }, }); } function notify(message) { if (!("Notification" in window)) return; else if (Notification.permission === "granted") { new Notification(message); } else if (Notification.permission !== "denied") { Notification.requestPermission(function (permission) { if (permission === "granted") { new Notification(message); } }); } }