const startDate = new Date('2020-05-31'); const endDate = new Date(); let currentDate = new Date(); function generateCalendar(year, month) { const calendarDiv = document.getElementById('calendar'); calendarDiv.innerHTML = ''; const table = document.createElement('table'); const header = document.createElement('tr'); const headers = ['الأحد', 'الإثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت']; headers.forEach(day => { const th = document.createElement('th'); th.innerText = day; header.appendChild(th); }); table.appendChild(header); const firstDay = new Date(year, month, 1); const lastDay = new Date(year, month + 1, 0); const formattedMonth = String(month + 1).padStart(2, '0'); const monthYear = firstDay.toLocaleString('default', { year: 'numeric' }); document.getElementById('currentMonth').innerText = formattedMonth + ' / ' + monthYear; let row = document.createElement('tr'); for (let i = 0; i < firstDay.getDay(); i++) { const cell = document.createElement('td'); row.appendChild(cell); } for (let day = 1; day <= lastDay.getDate(); day++) { if (row.children.length === 7) { table.appendChild(row); row = document.createElement('tr'); } const cell = document.createElement('td'); const linkDate = new Date(year, month, day); const formattedMonth = String(month + 1).padStart(2, '0'); const formattedDay = String(day).padStart(2, '0'); if (linkDate >= startDate && linkDate < endDate) { const link = document.createElement('a'); link.href = 'https://www.gold-price-daily.com/gold-dk/'+year+'-'+formattedMonth+'-'+formattedDay+'/'; link.innerText = formattedDay; cell.appendChild(link); } else { cell.innerText = formattedDay; } row.appendChild(cell); } while (row.children.length < 7) { const cell = document.createElement('td'); row.appendChild(cell); } table.appendChild(row); calendarDiv.appendChild(table); updateButtonStates(); } function prevMonth() { currentDate.setMonth(currentDate.getMonth() - 1); generateCalendar(currentDate.getFullYear(), currentDate.getMonth()); } function nextMonth() { currentDate.setMonth(currentDate.getMonth() + 1); generateCalendar(currentDate.getFullYear(), currentDate.getMonth()); } function updateButtonStates() { const prevBtn = document.getElementById('prevBtn'); const nextBtn = document.getElementById('nextBtn'); if (currentDate <= startDate) { prevBtn.disabled = true; } else { prevBtn.disabled = false; } if (currentDate.getFullYear() === endDate.getFullYear() && currentDate.getMonth() === endDate.getMonth()) { nextBtn.disabled = true; } else { nextBtn.disabled = false; } } generateCalendar(currentDate.getFullYear(), currentDate.getMonth());