- Mesajlar
- 2
- Beğeni
- 0
- Puan
- 1
wikipedia.org dan otomatik çeker kendim için hazırlamıştım sitemi kapattım belki birine lazım olur
Demo : https://1ad-blog.blogspot.com/p/on-this-day.html
Demo : https://1ad-blog.blogspot.com/p/on-this-day.html
Kod:
<script>document.addEventListener("DOMContentLoaded", function() { var today = new Date(); var month = today.getMonth() + 1; var day = today.getDate(); var apiUrl = `https://en.wikipedia.org/api/rest_v1/feed/onthisday/events/${month}/${day}`; var pageTitle = document.title || "On This Day in History"; fetch(apiUrl) .then(response => response.json()) .then(data => { if (data.events && data.events.length > 0) { var eventsList = `<div class="custom-header"><i class='fas fa-calendar-day'></i> ${pageTitle}</div> <ul style='list-style-type: none; padding: 0;'>`; var eventDetailsPromises = data.events.map((event, index) => { var icon = "<i class='fas fa-info-circle'></i>"; var eventTextLower = event.text.toLowerCase(); if (eventTextLower.includes("born") || eventTextLower.includes("birth")) { icon = "<i class='fas fa-birthday-cake'></i>"; } else if (eventTextLower.includes("death")) { icon = "<i class='fas fa-skull'></i>"; } else if (eventTextLower.includes("discovered") || eventTextLower.includes("invented")) { icon = "<i class='fas fa-flask'></i>"; } else if (eventTextLower.includes("won")) { icon = "<i class='fas fa-trophy'></i>"; } var eventYear = event.year; var formattedDate = `${day}/${month}/${eventYear}`; var imageUrl = event.pages && event.pages.length > 0 && event.pages[0].thumbnail ? event.pages[0].thumbnail.source : null; var imageAlt = event.pages && event.pages.length > 0 ? event.pages[0].title : "Historical event image"; var imageIcon = imageUrl ? `<img src="${imageUrl}" alt="${imageAlt}" style="width:20px; height:20px; vertical-align:middle; border-radius:50%; margin-right:5px;">` : ""; var eventPageTitle = event.pages && event.pages.length > 0 ? event.pages[0].title : null; var shareUrl = encodeURIComponent(`https://www.1ad.com.tr/p/on-this-day.html?date=${day}-${month}-${eventYear}`); var shareText = encodeURIComponent(`${formattedDate}: ${event.text}`); var shareIcons = ` <div class="share-icons"> <a href="https://www.facebook.com/sharer/sharer.php?u=${shareUrl}" target="_blank"><i class="fab fa-facebook"></i></a> <a href="https://twitter.com/intent/tweet?text=${shareText}&url=${shareUrl}" target="_blank"><i class="fab fa-twitter"></i></a> <a href="https://api.whatsapp.com/send?text=${shareText} ${shareUrl}" target="_blank"><i class="fab fa-whatsapp"></i></a> <a href="https://www.instagram.com/" target="_blank"><i class="fab fa-instagram"></i></a> </div> `; if (eventPageTitle) { var eventPageUrl = `https://en.wikipedia.org/api/rest_v1/page/summary/${encodeURIComponent(eventPageTitle)}`; return fetch(eventPageUrl) .then(response => response.json()) .then(eventPageData => { var content = eventPageData.extract || "No detailed information available."; eventsList += ` <li style="margin-bottom: 15px;"> <h2 class="event-title">${eventPageTitle}</h2> ${imageIcon} ${icon} <strong>${formattedDate}:</strong> ${event.text} <p>${content}</p> ${shareIcons} </li> ${index < data.events.length - 1 ? "<hr style='border: 0; height: 1px; background: #ccc; margin: 10px 0;'>" : ""} `; }) .catch(error => console.error("Error fetching event details:", error)); } else { eventsList += ` <li style="margin-bottom: 15px;"> <h2 class="event-title">${event.text.substring(0, 50)}...</h2> ${imageIcon} ${icon} <strong>${formattedDate}:</strong> ${event.text} ${shareIcons} </li> ${index < data.events.length - 1 ? "<hr style='border: 0; height: 1px; background: #ccc; margin: 10px 0;'>" : ""} `; } }); Promise.all(eventDetailsPromises).then(() => { eventsList += "</ul>"; var eventContainer = document.createElement("div"); eventContainer.className = "event-container"; eventContainer.innerHTML = eventsList; var postBody = document.querySelector('.post-body'); if (postBody) { postBody.appendChild(eventContainer); } }); } }) .catch(error => console.error("Wikipedia API error:", error));});</script><style>.share-icons { margin-top: 10px;}.share-icons a { margin-right: 10px; font-size: 18px; color: #ffffff; text-decoration: none;}.share-icons a:hover { color: #fbbc05;}</style>