1
0
Fork 0
CalMerger/script.js

61 lines
2.6 KiB
JavaScript
Raw Normal View History

2024-09-30 12:55:03 +00:00
const form = document.getElementById('merge-form');
const calendars = document.getElementById('calendars');
const addCalendarButton = document.getElementById('add-calendar');
const result = document.getElementById('result');
2024-09-30 12:55:03 +00:00
let calendarIndex = 1;
2024-09-30 12:55:03 +00:00
addCalendarButton.addEventListener('click', () => {
const newCalendar = document.createElement('div');
newCalendar.className = 'calendar';
newCalendar.innerHTML = `
<input type="text" id="prefix-${calendarIndex}" placeholder="Prefix">
<input type="checkbox" id="override-${calendarIndex}">
<label for="override-${calendarIndex}">Override</label>
<input type="url" id="url-${calendarIndex}" placeholder="Calendar URL">
`;
calendars.appendChild(newCalendar);
calendarIndex++;
});
form.addEventListener('submit', (event) => {
event.preventDefault();
const linkGroupName = document.getElementById('link-group-name').value;
const calendarsData = [];
for (let i = 0; i < calendarIndex; i++) {
const prefix = document.getElementById(`prefix-${i}`).value;
const override = document.getElementById(`override-${i}`).checked;
const url = document.getElementById(`url-${i}`).value;
2024-10-15 11:07:32 +00:00
calendarsData.push({ linkGroupName, prefix, override, url });
}
fetch('/merge', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ calendars: calendarsData })
})
.then((response) => response.json())
.then((data) => {
result.innerHTML = `Merged calendar URL: <a href="${data.url}">${data.url}</a>`;
2024-10-15 11:01:04 +00:00
console.log('Links added successfully!');
})
.catch((error) => {
console.error(error);
result.innerHTML = 'Error merging calendars';
});
});
2024-10-02 22:15:01 +00:00
const refreshInterval = 60 * 60 * 1000; // 1 hour
setInterval(() => {
fetch('/merge')
.then((response) => response.json())
.then((data) => {
result.innerHTML = `Merged calendar URL: <a href="${data.url}">${data.url}</a>`;
})
.catch((error) => {
console.error(error);
result.innerHTML = 'Error merging calendars';
});
}, refreshInterval);
2024-10-02 11:20:21 +00:00