location-status.js 721 B

1234567891011121314151617181920212223242526
  1. class LocationStatus extends HTMLElement {
  2. connectedCallback() {
  3. this.url = this.getAttribute('url');
  4. this.updateStatus();
  5. }
  6. async updateStatus() {
  7. const data = await this.fetchPage();
  8. if (!data || typeof data.is_open !== 'boolean') {
  9. this.textContent =
  10. "Sorry, we couldn't retrieve the status of this location.";
  11. } else if (data.is_open) {
  12. this.textContent = 'This location is currently open.';
  13. } else {
  14. this.textContent = 'Sorry, this location is currently closed.';
  15. }
  16. }
  17. fetchPage() {
  18. return fetch(this.url)
  19. .then((response) => response.json())
  20. .catch(() => null);
  21. }
  22. }
  23. window.customElements.define('location-status', LocationStatus);