2024-09-30 12:55:03 +00:00
|
|
|
const form = document.getElementById('merge-form');
|
2024-10-01 23:16:42 +00:00
|
|
|
const calendars = document.getElementById('calendars');
|
|
|
|
const addCalendarButton = document.getElementById('add-calendar');
|
|
|
|
const result = document.getElementById('result');
|
2024-09-30 12:55:03 +00:00
|
|
|
|
2024-10-01 23:16:42 +00:00
|
|
|
let calendarIndex = 1;
|
2024-09-30 12:55:03 +00:00
|
|
|
|
2024-10-01 23:16:42 +00:00
|
|
|
addCalendarButton.addEventListener('click', () => {
|
|
|
|
const newCalendar = document.createElement('div');
|
|
|
|
newCalendar.className = 'calendar';
|
|
|
|
newCalendar.innerHTML = `
|
|
|
|
<input type="text" id="prefix-${calendarIndex}" placeholder="Prefix">
|
2024-10-04 12:55:31 +00:00
|
|
|
<input type="checkbox" id="override-${calendarIndex}">
|
|
|
|
<label for="override-${calendarIndex}">Override</label>
|
2024-10-01 23:16:42 +00:00
|
|
|
<input type="url" id="url-${calendarIndex}" placeholder="Calendar URL">
|
|
|
|
`;
|
|
|
|
calendars.appendChild(newCalendar);
|
|
|
|
calendarIndex++;
|
|
|
|
});
|
|
|
|
|
|
|
|
form.addEventListener('submit', (event) => {
|
|
|
|
event.preventDefault();
|
2024-10-15 11:42:37 +00:00
|
|
|
const linkGroupName = document.getElementById('link-group-name').value;
|
2024-10-01 23:16:42 +00:00
|
|
|
const calendarsData = [];
|
|
|
|
for (let i = 0; i < calendarIndex; i++) {
|
|
|
|
const prefix = document.getElementById(`prefix-${i}`).value;
|
2024-10-04 12:57:38 +00:00
|
|
|
const override = document.getElementById(`override-${i}`).checked;
|
2024-10-01 23:16:42 +00:00
|
|
|
const url = document.getElementById(`url-${i}`).value;
|
2024-10-21 12:15:26 +00:00
|
|
|
if (prefix && override && url) {
|
|
|
|
calendarsData.push({
|
|
|
|
prefix: prefix.value,
|
|
|
|
override: override.checked,
|
|
|
|
url: url.value
|
|
|
|
});
|
|
|
|
}
|
2024-10-01 23:16:42 +00:00
|
|
|
}
|
|
|
|
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!');
|
2024-10-01 23:16:42 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error(error);
|
|
|
|
result.innerHTML = 'Error merging calendars';
|
|
|
|
});
|
2024-10-02 11:09:51 +00:00
|
|
|
});
|
2024-10-14 12:46:58 +00:00
|
|
|
|
2024-10-02 22:15:01 +00:00
|
|
|
const refreshInterval = 60 * 60 * 1000; // 1 hour
|
2024-10-02 22:15:49 +00:00
|
|
|
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
|
|
|
|