var validdates =[ { "Date": "2024-03-15", "Month": 3, "Day": 15, "ProductCount": "4件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240315/comiket_deadline_to:20240315" }, { "Date": "2024-03-19", "Month": 3, "Day": 19, "ProductCount": "11件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240319/comiket_deadline_to:20240319" }, { "Date": "2024-03-22", "Month": 3, "Day": 22, "ProductCount": "11件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240322/comiket_deadline_to:20240322" }, { "Date": "2024-03-26", "Month": 3, "Day": 26, "ProductCount": "7件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240326/comiket_deadline_to:20240326" }, { "Date": "2024-03-27", "Month": 3, "Day": 27, "ProductCount": "50件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240327/comiket_deadline_to:20240327" }, { "Date": "2024-03-28", "Month": 3, "Day": 28, "ProductCount": "1件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240328/comiket_deadline_to:20240328" }, { "Date": "2024-03-29", "Month": 3, "Day": 29, "ProductCount": "6件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240329/comiket_deadline_to:20240329" }, { "Date": "2024-04-01", "Month": 4, "Day": 1, "ProductCount": "16件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240401/comiket_deadline_to:20240401" }, { "Date": "2024-04-02", "Month": 4, "Day": 2, "ProductCount": "23件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240402/comiket_deadline_to:20240402" }, { "Date": "2024-04-03", "Month": 4, "Day": 3, "ProductCount": "186件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240403/comiket_deadline_to:20240403" }, { "Date": "2024-04-04", "Month": 4, "Day": 4, "ProductCount": "49件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240404/comiket_deadline_to:20240404" }, { "Date": "2024-04-05", "Month": 4, "Day": 5, "ProductCount": "16件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240405/comiket_deadline_to:20240405" }, { "Date": "2024-04-08", "Month": 4, "Day": 8, "ProductCount": "12件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240408/comiket_deadline_to:20240408" }, { "Date": "2024-04-09", "Month": 4, "Day": 9, "ProductCount": "16件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240409/comiket_deadline_to:20240409" }, { "Date": "2024-04-10", "Month": 4, "Day": 10, "ProductCount": "31件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240410/comiket_deadline_to:20240410" }, { "Date": "2024-04-11", "Month": 4, "Day": 11, "ProductCount": "72件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240411/comiket_deadline_to:20240411" }, { "Date": "2024-04-12", "Month": 4, "Day": 12, "ProductCount": "10件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240412/comiket_deadline_to:20240412" }, { "Date": "2024-04-15", "Month": 4, "Day": 15, "ProductCount": "3件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240415/comiket_deadline_to:20240415" }, { "Date": "2024-04-17", "Month": 4, "Day": 17, "ProductCount": "15件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240417/comiket_deadline_to:20240417" }, { "Date": "2024-04-18", "Month": 4, "Day": 18, "ProductCount": "14件", "URL": "https://goods.ryokuyou.co.jp/search/comiket_deadline_from:20240418/comiket_deadline_to:20240418" } ] var event1 = "Sat May 04 2024"; var event2 = "Sun May 05 2024"; var eventname1 = "SUPER COMIC CITY 31 1日目"; var eventname2 = "SUPER COMIC CITY 31 2日目"; $(document).ready(function () { function createMonth(month, year) { var monthElement = document.createElement("div"); monthElement.className = "dp-month"; monthElement.innerHTML = "

" + year + "年" + getMonthName(month) + "

"; // Add row for day names var dayNamesRow = document.createElement("div"); dayNamesRow.className = "dp-day-names"; var dayNames = ["日", "月", "火", "水", "木", "金", "土"]; for (var i = 0; i < 7; i++) { var dayNameElement = document.createElement("div"); dayNameElement.className = "dp-day-name"; dayNameElement.textContent = dayNames[i]; dayNamesRow.appendChild(dayNameElement); } monthElement.appendChild(dayNamesRow); var daysInMonth = getDaysInMonth(month, year); var firstDay = new Date(year, month, 1).getDay(); for (var i = 0; i < firstDay; i++) { monthElement.innerHTML += "
"; } for (var i = 1; i <= daysInMonth; i++) { var dayElement = document.createElement("div"); dayElement.className = "dp-day"; dayElement.setAttribute("data-date", new Date(year, month, i).toDateString()); // Check Saturday or Sunday if (new Date(year, month, i).getDay() === 6 || new Date(year, month, i).getDay() === 0) { dayElement.classList.add("dp-wknd"); } var dateValue = dayElement.getAttribute("data-date"); // Set event day if (dateValue === event1 || dateValue === event2) { // if (dateValue === event1) { dayElement.classList.remove("dp-wknd"); dayElement.classList.add("dp-event"); // Set the event name based on the matching date if (dateValue === event1) { dayElement.title = eventname1; } else { dayElement.title = eventname2; } } if (dayElement.getAttribute("data-date") === "Fri Nov 03 2023" || dayElement.getAttribute("data-date") === "Thu Nov 23 2023") { dayElement.classList.add("dp-wknd"); } var currentDate = dayElement.getAttribute("data-date"); var matchingDate = validdates.find(function (item) { return item.Month - 1 === new Date(currentDate).getMonth() && item.Day === new Date(currentDate).getDate(); }); if (matchingDate) { dayElement.classList.add("highlight"); var linkElement = document.createElement("a"); linkElement.href = matchingDate.URL; linkElement.textContent = i; dayElement.innerHTML = ""; dayElement.appendChild(linkElement); } else { dayElement.textContent = i; } monthElement.appendChild(dayElement); } // Add empty days for the remaining cells in the last row var lastDay = new Date(year, month, daysInMonth).getDay(); for (var i = lastDay + 1; i < 7; i++) { monthElement.innerHTML += "
"; } return monthElement; } function getDayName(day) { var dayNames = [ "日", "月", "火", "水", "木", "金", "土"]; return dayNames[day]; } function getMonthName(month) { var monthNames = [ "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]; return monthNames[month]; } function getDaysInMonth(month, year) { return new Date(year, month + 1, 0).getDate(); } function createCalendar() { var calendar = document.getElementById("dp-calendar"); var currentDate = new Date(); var currentMonth = currentDate.getMonth(); var currentYear = currentDate.getFullYear(); var months = []; for (var i = 0; i < monthsahead; i++) { var month = currentMonth + i; var year = currentYear; if (month >= 12) { month -= 12; year += 1; } var monthElement = createMonth(month, year); months.push(monthElement); } months.forEach(function (month) { calendar.appendChild(month); }); applyLinkUrls(); } createCalendar(); }); function applyLinkUrls() { var dayElements = document.getElementsByClassName("dp-day"); for (var i = 0; i < dayElements.length; i++) { var dayElement = dayElements[i]; var currentDate = dayElement.getAttribute("data-date"); // console.log(currentDate); var matchingDate = validdates.find(function (item) { if (currentDate) { var dateParts = currentDate.split("-"); var itemDate = new Date(item.Month + "/" + item.Date + "/" + dateParts[0]); return itemDate.toISOString().split("T")[0] === currentDate; } else { console.log("data-date attribute is null for the current dayElement"); } }); if (matchingDate) { dayElement.classList.add("highlight"); // Check if the day element has the "dp-wknd" class if (dayElement.classList.contains("dp-wknd")) { dayElement.classList.add("dp-wknd"); } if (!dayElement.querySelector("a")) { var linkElement = document.createElement("a"); linkElement.href = matchingDate.URL; linkElement.textContent = dayElement.textContent; dayElement.innerHTML = ""; dayElement.appendChild(linkElement); } } else { // Remove any existing elements var linkElement = dayElement.querySelector("a"); if (linkElement) { dayElement.innerHTML = dayElement.textContent; } } } }