2023-08-28 20:38:49 -04:00
|
|
|
import 'core-js/stable/url';
|
2023-09-15 12:58:01 -04:00
|
|
|
import 'core-js/stable/function';
|
2023-08-28 20:38:49 -04:00
|
|
|
|
|
|
|
import './ipad.html';
|
|
|
|
import './modal.css';
|
|
|
|
|
|
|
|
console.log = function (message) {
|
|
|
|
let div = document.createElement('div');
|
|
|
|
div.textContent = message;
|
|
|
|
document.getElementById('errorContainer')!.appendChild(div);
|
|
|
|
};
|
|
|
|
console.error = console.log;
|
|
|
|
console.info = console.log;
|
|
|
|
|
|
|
|
window.onerror = function (message, url, line) {
|
|
|
|
console.log(`${message} ${url} ${line}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
document.body.addEventListener('touchmove', (e) => e.preventDefault(), {
|
|
|
|
passive: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const calendarImg = document.getElementById('calendar')! as HTMLImageElement;
|
|
|
|
const spinner = document.getElementById('loadingSpinner')!;
|
|
|
|
const errorModal = document.getElementById('errorModal')!;
|
2023-11-03 15:08:29 -04:00
|
|
|
let loadTimeoutId = -1;
|
2023-08-28 20:38:49 -04:00
|
|
|
|
|
|
|
calendarImg.addEventListener('load', () => {
|
2023-11-03 15:08:29 -04:00
|
|
|
clearTimeout(loadTimeoutId);
|
2023-08-28 20:38:49 -04:00
|
|
|
spinner.style.display = 'none';
|
|
|
|
errorModal.style.display = 'none';
|
|
|
|
});
|
|
|
|
|
|
|
|
calendarImg.addEventListener('error', (event) => {
|
|
|
|
spinner.style.display = 'none';
|
|
|
|
errorModal.style.display = '';
|
|
|
|
const message = errorModal.querySelector('.modal-message')!;
|
2023-11-03 14:42:28 -04:00
|
|
|
message.textContent = `Failed to fetch events. Displayed events may not be accurate.`;
|
2023-08-28 20:38:49 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
function refresh() {
|
|
|
|
spinner.style.display = '';
|
|
|
|
|
|
|
|
const url = new URL('/ipad.png', window.location.href);
|
2023-11-03 14:43:29 -04:00
|
|
|
url.searchParams.set(
|
|
|
|
'viewport',
|
|
|
|
`${window.innerWidth}x${window.innerHeight}x${window.devicePixelRatio}`
|
|
|
|
);
|
2023-08-28 20:38:49 -04:00
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
if (urlParams.has('tool')) {
|
|
|
|
url.searchParams.set('tool', urlParams.get('tool')!);
|
|
|
|
}
|
|
|
|
|
|
|
|
calendarImg.src = url.toString();
|
|
|
|
calendarImg.width = window.innerWidth;
|
|
|
|
calendarImg.height = window.innerHeight;
|
2023-11-03 15:08:29 -04:00
|
|
|
|
|
|
|
loadTimeoutId = window.setTimeout(() => {
|
|
|
|
spinner.style.display = 'none';
|
|
|
|
errorModal.style.display = '';
|
|
|
|
const message = errorModal.querySelector('.modal-message')!;
|
|
|
|
message.textContent =
|
|
|
|
'Timed out loading events. Displayed events may not be accurate.';
|
|
|
|
}, 11000);
|
2023-08-28 20:38:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('load', () => refresh());
|
|
|
|
|
|
|
|
// refresh data every five minutes
|
|
|
|
window.setInterval(refresh, 5 * 60 * 1000);
|
|
|
|
|
|
|
|
// refresh page every hour
|
|
|
|
window.setInterval(() => window.location.reload(), 60 * 60 * 1000);
|