Skip to content

lightweight, client-only calendar web application. All data persists in the URL hash for instant sharing, No backend required. Optional AES-GCM password protection keeps shared links locked without a server

JavaScript

feat(readonly): hide edit/share controls in read-only mode and persist in URL

Supun Lakmal8063fe259b69
diff --git a/index.html b/index.html
index f2954b7..c20ec98 100644
--- a/index.html
+++ b/index.html
@@ -219,7 +219,7 @@
day</button>
</div>
- <div class="side-card">
+ <div id="share-export-section" class="side-card">
<h4 class="side-title" data-i18n="panel.shareExport">Share and export</h4>
<div class="status-row">
<span data-i18n="panel.urlLength">URL length</span>
@@ -234,7 +234,7 @@
</div>
</div>
- <div class="side-card danger">
+ <div id="danger-zone-section" class="side-card danger">
<h4 class="side-title" data-i18n="panel.dangerZone">Danger zone</h4>
<button id="clear-all" type="button" class="danger-btn" data-i18n="btn.clearCalendar">Clear calendar</button>
</div>
@@ -520,7 +520,7 @@
</a>
</div>
- <div class="mobile-drawer-section">
+ <div id="mobile-share-export-section" class="mobile-drawer-section">
<span class="mobile-drawer-label" data-i18n="panel.shareExport">Share and export</span>
<div class="side-card">
<div class="status-row">
@@ -536,7 +536,7 @@
</div>
</div>
- <div class="mobile-drawer-section">
+ <div id="mobile-danger-zone-section" class="mobile-drawer-section">
<span class="mobile-drawer-label" data-i18n="panel.dangerZone">Danger zone</span>
<div class="side-card danger">
<button id="mobile-clear-all" type="button" class="danger-btn" data-i18n="btn.clearCalendar">Clear
diff --git a/modules/hashcalUrlManager.js b/modules/hashcalUrlManager.js
index 377d7f6..117d078 100644
--- a/modules/hashcalUrlManager.js
+++ b/modules/hashcalUrlManager.js
@@ -4,7 +4,7 @@ const HASH_PREFIX = "ENC:";
const DEFAULT_TITLE = "hash-calendar";
const DEFAULT_COLORS = ["#ff6b6b", "#ffd43b", "#4dabf7", "#63e6be", "#9775fa"];
-const DEFAULT_SETTINGS = { d: 0, m: 0, v: "month" };
+const DEFAULT_SETTINGS = { d: 0, m: 0, v: "month", r: 0 };
function arraysEqual(a, b) {
return a.length === b.length && a.every((v, i) => v === b[i]);
@@ -43,13 +43,14 @@ function compactState(state) {
});
}
- if (state.s) {
- const hasView = typeof state.s.v === "string" && state.s.v !== DEFAULT_SETTINGS.v;
- const hasLang = typeof state.s.l === "string" && state.s.l !== "en";
- if (state.s.d !== DEFAULT_SETTINGS.d || state.s.m !== DEFAULT_SETTINGS.m || hasView || hasLang) {
- out.s = state.s;
- }
- }
+ if (state.s) {
+ const hasView = typeof state.s.v === "string" && state.s.v !== DEFAULT_SETTINGS.v;
+ const hasLang = typeof state.s.l === "string" && state.s.l !== "en";
+ const hasReadOnly = Number(state.s.r || 0) !== DEFAULT_SETTINGS.r;
+ if (state.s.d !== DEFAULT_SETTINGS.d || state.s.m !== DEFAULT_SETTINGS.m || hasView || hasLang || hasReadOnly) {
+ out.s = state.s;
+ }
+ }
if (Array.isArray(state.timezones) && state.timezones.length) {
out.z = state.timezones;
diff --git a/modules/worldPlannerModule.js b/modules/worldPlannerModule.js
index 02a2cbd..07c7561 100644
--- a/modules/worldPlannerModule.js
+++ b/modules/worldPlannerModule.js
@@ -1,28 +1,20 @@
-import { getZoneInfo, isValidZone, AVAILABLE_ZONES, getLocalZone, parseOffsetSearchTerm } from "./timezoneManager.js";
-import { t } from "./i18n.js";
import {
- PLANNER_HOURS_PER_DAY,
- PLANNER_BUSINESS_HOUR_START,
- PLANNER_BUSINESS_HOUR_END,
- PLANNER_ACTIVE_HOUR_START,
- PLANNER_ACTIVE_HOUR_END,
- PLANNER_DEFAULT_ZONES,
- PLANNER_MAX_ZONES,
+ CSS_CLASSES,
MAX_TZ_RESULTS,
MIN_SEARCH_LENGTH,
MS_PER_HOUR,
- CSS_CLASSES,
+ PLANNER_ACTIVE_HOUR_END,
+ PLANNER_ACTIVE_HOUR_START,
+ PLANNER_BUSINESS_HOUR_END,
+ PLANNER_BUSINESS_HOUR_START,
+ PLANNER_DEFAULT_ZONES,
+ PLANNER_HOURS_PER_DAY,
+ PLANNER_MAX_ZONES,
} from "./constants.js";
+import { AVAILABLE_ZONES, getLocalZone, getZoneInfo, parseOffsetSearchTerm } from "./timezoneManager.js";
export class WorldPlanner {
- constructor({
- getState,
- updateState,
- ensureEditable,
- scheduleSave,
- showToast,
- closeMobileDrawer
- } = {}) {
+ constructor({ getState, updateState, ensureEditable, scheduleSave, showToast, closeMobileDrawer } = {}) {
// Store dependencies
this.getState = getState;
this.updateState = updateState;
@@ -81,9 +73,7 @@ export class WorldPlanner {
open() {
if (!this.modal) return;
- const canEdit = typeof this.ensureEditable === "function"
- ? this.ensureEditable({ silent: true })
- : true;
+ const canEdit = typeof this.ensureEditable === "function" ? this.ensureEditable({ silent: true }) : true;
const state = this.getState();
@@ -92,10 +82,10 @@ export class WorldPlanner {
const local = getLocalZone();
const newMp = {
h: local,
- z: PLANNER_DEFAULT_ZONES.filter(z => z !== local).slice(0, PLANNER_MAX_ZONES),
+ z: PLANNER_DEFAULT_ZONES.filter((z) => z !== local).slice(0, PLANNER_MAX_ZONES),
s: null,
d: new Date().toISOString().split("T")[0],
- f24: false
+ f24: false,
};
this.updateState("mp", newMp);
}
@@ -119,9 +109,7 @@ export class WorldPlanner {
if (!this.modal) return;
this.modal.classList.add(CSS_CLASSES.HIDDEN);
- if (typeof this.ensureEditable === "function"
- && this.ensureEditable({ silent: true })
- && typeof this.scheduleSave === "function") {
+ if (typeof this.ensureEditable === "function" && this.ensureEditable({ silent: true }) && typeof this.scheduleSave === "function") {
this.scheduleSave();
}
}
@@ -186,7 +174,7 @@ export class WorldPlanner {
return;
}
- results.forEach(zone => {
+ results.forEach((zone) => {
const li = document.createElement("li");
const button = document.createElement("button");
button.type = "button";
@@ -237,13 +225,13 @@ export class WorldPlanner {
const state = this.getState();
if (action === "remove") {
- const newZ = state.mp.z.filter(z => z !== zone);
+ const newZ = state.mp.z.filter((z) => z !== zone);
this.updateState("mp", { ...state.mp, z: newZ });
this.scheduleSave();
this.render();
} else if (action === "promote") {
const oldHome = state.mp.h;
- const newZ = state.mp.z.filter(z => z !== zone);
+ const newZ = state.mp.z.filter((z) => z !== zone);
if (oldHome) newZ.unshift(oldHome);
this.updateState("mp", { ...state.mp, h: zone, z: newZ });
this.scheduleSave();
@@ -272,7 +260,7 @@ export class WorldPlanner {
}
// Zones
- state.mp.z.forEach(zone => {
+ state.mp.z.forEach((zone) => {
cityCol.appendChild(this.createCityHeader(zone, false));
});
@@ -302,7 +290,7 @@ export class WorldPlanner {
if (state.mp.h) {
track.appendChild(this.createRow(state.mp.h, baseDate, true));
}
- state.mp.z.forEach(zone => {
+ state.mp.z.forEach((zone) => {
track.appendChild(this.createRow(zone, baseDate, false));
});
@@ -368,8 +356,8 @@ export class WorldPlanner {
const targetInfo = getZoneInfo(zone);
const parseOff = (s) => {
- const sign = s[0] === '-' ? -1 : 1;
- const [hh, mm] = s.slice(1).split(':').map(Number);
+ const sign = s[0] === "-" ? -1 : 1;
+ const [hh, mm] = s.slice(1).split(":").map(Number);
return sign * (hh * 60 + mm);
};
@@ -382,7 +370,7 @@ export class WorldPlanner {
for (let h = 0; h < PLANNER_HOURS_PER_DAY; h++) {
const cell = document.createElement("div");
- let targetMins = (h * 60) + diffMins;
+ let targetMins = h * 60 + diffMins;
let dayShift = 0;
if (targetMins < 0) {
targetMins += 24 * 60;
@@ -410,15 +398,15 @@ export class WorldPlanner {
if (tHour === 0 && tMin === 0) {
const d = new Date(baseDate);
d.setDate(d.getDate() + dayShift);
- cell.textContent = d.toLocaleDateString('en-US', { day: 'numeric', month: 'short' }).toUpperCase();
+ cell.textContent = d.toLocaleDateString("en-US", { day: "numeric", month: "short" }).toUpperCase();
} else {
if (is24h) {
- cell.textContent = tMin > 0 ? `${tHour}:${String(tMin).padStart(2, '0')}` : `${tHour}`;
+ cell.textContent = tMin > 0 ? `${tHour}:${String(tMin).padStart(2, "0")}` : `${tHour}`;
} else {
const ampm = tHour >= 12 ? "pm" : "am";
const h12 = tHour % 12 || 12;
if (tMin > 0) {
- cell.textContent = `${h12}:${String(tMin).padStart(2, '0')}`;
+ cell.textContent = `${h12}:${String(tMin).padStart(2, "0")}`;
} else {
// Only show am/pm for home zone
cell.textContent = isHome ? `${h12} ${ampm}` : `${h12}`;
@@ -452,7 +440,7 @@ export class WorldPlanner {
const hIndex = Number(cell.dataset.h);
const baseDate = this.getPlannerDate();
- const ts = baseDate.getTime() + (hIndex * MS_PER_HOUR);
+ const ts = baseDate.getTime() + hIndex * MS_PER_HOUR;
const state = this.getState();
this.updateState("mp", { ...state.mp, s: ts });
diff --git a/script.js b/script.js
index b900e0c..fdf945d 100644
--- a/script.js
+++ b/script.js
@@ -1,11 +1,5 @@
-import { readStateFromHash, writeStateToHash, isEncryptedHash, clearHash } from "./modules/hashcalUrlManager.js";
-import { expandEvents } from "./modules/recurrenceEngine.js";
import { renderAgendaView } from "./modules/agendaRender.js";
-import { FocusMode } from "./modules/focusMode.js";
-import { WorldPlanner } from "./modules/worldPlannerModule.js";
-import { initQRCodeManager } from "./modules/qrCodeManager.js";
-import { initCountdownWidget } from "./modules/countdownManager.js";
-import { AVAILABLE_ZONES, getZoneInfo, isValidZone, getLocalZone, parseOffsetSearchTerm } from "./modules/timezoneManager.js";
+import { AppLauncher } from "./modules/app_launcher.js";
import {
formatDateKey,
getMonthGridRange,
@@ -15,49 +9,34 @@ import {
renderWeekdayHeaders,
renderYearView,
} from "./modules/calendarRender.js";
-import { parseIcs } from "./modules/icsImporter.js";
-import { AppLauncher } from "./modules/app_launcher.js";
-import {
- setLanguage,
- t,
- updateDOM,
- getCurrentLanguage,
- getCurrentLocale,
- getTranslatedMonthName,
- getTranslatedWeekday,
- SUPPORTED_LANGUAGES,
-} from "./modules/i18n.js";
import {
+ COLOR_REGEX,
+ CSS_CLASSES,
+ DEBOUNCE_MS,
DEFAULT_COLORS,
- DEFAULT_VIEW,
- VALID_VIEWS,
+ DEFAULT_EVENT_DURATION,
DEFAULT_STATE,
- DEBOUNCE_MS,
- TOAST_TIMEOUT_MS,
- TIMEZONE_UPDATE_INTERVAL_MS,
- MAX_TITLE_LENGTH,
+ DEFAULT_VIEW,
MAX_EVENT_TITLE_LENGTH,
+ MAX_TITLE_LENGTH,
MAX_TZ_RESULTS,
- URL_LENGTH_WARNING_THRESHOLD,
- TZ_EMPTY_MESSAGE,
MIN_SEARCH_LENGTH,
- PLANNER_HOURS_PER_DAY,
- PLANNER_BUSINESS_HOUR_START,
- PLANNER_BUSINESS_HOUR_END,
- PLANNER_ACTIVE_HOUR_START,
- PLANNER_ACTIVE_HOUR_END,
- PLANNER_DEFAULT_ZONES,
- PLANNER_MAX_ZONES,
- MINUTES_PER_HOUR,
MS_PER_MINUTE,
- MS_PER_HOUR,
- DEFAULT_EVENT_DURATION,
- CSS_CLASSES,
- COLOR_REGEX,
- OFFSET_MAX_HOURS,
- OFFSET_MAX_MINUTES,
+ TIMEZONE_UPDATE_INTERVAL_MS,
+ TOAST_TIMEOUT_MS,
+ TZ_EMPTY_MESSAGE,
+ URL_LENGTH_WARNING_THRESHOLD,
+ VALID_VIEWS,
} from "./modules/constants.js";
-
+import { initCountdownWidget } from "./modules/countdownManager.js";
+import { FocusMode } from "./modules/focusMode.js";
+import { clearHash, isEncryptedHash, readStateFromHash, writeStateToHash } from "./modules/hashcalUrlManager.js";
+import { getCurrentLanguage, getCurrentLocale, getTranslatedMonthName, getTranslatedWeekday, setLanguage, SUPPORTED_LANGUAGES, t } from "./modules/i18n.js";
+import { parseIcs } from "./modules/icsImporter.js";
+import { initQRCodeManager } from "./modules/qrCodeManager.js";
+import { expandEvents } from "./modules/recurrenceEngine.js";
+import { AVAILABLE_ZONES, getLocalZone, getZoneInfo, isValidZone, parseOffsetSearchTerm } from "./modules/timezoneManager.js";
+import { WorldPlanner } from "./modules/worldPlannerModule.js";
let state = cloneState(DEFAULT_STATE);
let viewDate = startOfDay(new Date());
@@ -121,7 +100,7 @@ function createRipple(event) {
}
button.appendChild(circle);
-
+
circle.addEventListener("animationend", () => {
circle.remove();
});
@@ -206,9 +185,7 @@ function normalizeState(raw) {
}
}
} else if (Array.isArray(raw.c) && raw.c.length) {
- next.c = raw.c
- .filter((color) => typeof color === "string" && COLOR_REGEX.test(color))
- .map((color) => (color.startsWith("#") ? color : `#${color}`));
+ next.c = raw.c.filter((color) => typeof color === "string" && COLOR_REGEX.test(color)).map((color) => (color.startsWith("#") ? color : `#${color}`));
if (!next.c.length) next.c = DEFAULT_COLORS.slice();
}
@@ -345,7 +322,7 @@ function cacheElements() {
ui.tzSidebar = document.getElementById("timezone-ruler");
ui.sidePanelClose = document.getElementById("side-panel-close");
ui.tzSidebarClose = document.getElementById("tz-sidebar-close");
-
+
// Mobile drawer & quick-action bar
ui.mobileDrawer = document.getElementById("mobile-drawer");
ui.mobileDrawerBackdrop = document.getElementById("mobile-drawer-backdrop");
@@ -365,13 +342,15 @@ function cacheElements() {
ui.mobileUrlWarning = document.getElementById("mobile-url-warning");
ui.mobileViewJson = document.getElementById("mobile-view-json");
ui.mobileExportJson = document.getElementById("mobile-export-json");
- ui.mobileImportIcs = document.getElementById("mobile-import-ics");
- ui.mobileClearAll = document.getElementById("mobile-clear-all");
- ui.mobileTzList = document.getElementById("mobile-tz-list");
- ui.mobileAddTzBtn = document.getElementById("mobile-add-tz-btn");
- ui.mobileDrawerViewButtons = Array.from(
- document.querySelectorAll(".mobile-drawer-view-toggle [data-view]")
- );
+ ui.mobileImportIcs = document.getElementById("mobile-import-ics");
+ ui.mobileClearAll = document.getElementById("mobile-clear-all");
+ ui.mobileTzList = document.getElementById("mobile-tz-list");
+ ui.mobileAddTzBtn = document.getElementById("mobile-add-tz-btn");
+ ui.shareExportSection = document.getElementById("share-export-section");
+ ui.dangerZoneSection = document.getElementById("danger-zone-section");
+ ui.mobileShareExportSection = document.getElementById("mobile-share-export-section");
+ ui.mobileDangerZoneSection = document.getElementById("mobile-danger-zone-section");
+ ui.mobileDrawerViewButtons = Array.from(document.querySelectorAll(".mobile-drawer-view-toggle [data-view]"));
ui.mobileWeekstartToggle = document.getElementById("mobile-weekstart-toggle");
ui.mobileThemeToggle = document.getElementById("mobile-theme-toggle");
ui.mobileReadOnlyBtn = document.getElementById("mobile-readonly-btn");
@@ -395,9 +374,9 @@ function showToast(message, type = "info") {
}, TOAST_TIMEOUT_MS);
}
-function hasStoredData() {
- return (state.e && state.e.length) || (state.timezones && state.timezones.length);
-}
+function hasStoredData() {
+ return !!((state.e && state.e.length) || (state.timezones && state.timezones.length) || isReadOnlyMode());
+}
function createTzCard(zoneId, isLocal) {
const data = getZoneInfo(zoneId);
@@ -699,23 +678,31 @@ function setView(view) {
const grid = ui.calendarGrid;
if (grid) {
grid.classList.add(CSS_CLASSES.VIEW_ANIMATE_OUT);
- grid.addEventListener("animationend", function handleExit() {
- grid.classList.remove(CSS_CLASSES.VIEW_ANIMATE_OUT);
- grid.removeEventListener("animationend", handleExit);
-
- currentView = view;
- if (state && state.s) state.s.v = view;
- updateViewButtons();
- render();
-
- grid.classList.add(CSS_CLASSES.VIEW_ANIMATE_IN);
- grid.addEventListener("animationend", function handleEnter() {
- grid.classList.remove(CSS_CLASSES.VIEW_ANIMATE_IN);
- grid.removeEventListener("animationend", handleEnter);
- }, { once: true });
-
- persistStateToHash();
- }, { once: true });
+ grid.addEventListener(
+ "animationend",
+ function handleExit() {
+ grid.classList.remove(CSS_CLASSES.VIEW_ANIMATE_OUT);
+ grid.removeEventListener("animationend", handleExit);
+
+ currentView = view;
+ if (state && state.s) state.s.v = view;
+ updateViewButtons();
+ render();
+
+ grid.classList.add(CSS_CLASSES.VIEW_ANIMATE_IN);
+ grid.addEventListener(
+ "animationend",
+ function handleEnter() {
+ grid.classList.remove(CSS_CLASSES.VIEW_ANIMATE_IN);
+ grid.removeEventListener("animationend", handleEnter);
+ },
+ { once: true },
+ );
+
+ persistStateToHash();
+ },
+ { once: true },
+ );
} else {
currentView = view;
if (state && state.s) state.s.v = view;
@@ -763,13 +750,39 @@ function updateLockUI() {
ui.titleInput.readOnly = editDisabled;
}
- [ui.addEventBtn, ui.addEventInline, ui.mobileAddEventInline, ui.mobileAddEvent, ui.importIcs, ui.mobileImportIcs, ui.clearAll, ui.mobileClearAll, ui.tzAddBtn, ui.mobileAddTzBtn].forEach((btn) => {
- if (btn) btn.disabled = editDisabled;
- });
-
- [ui.copyLinkBtn, ui.shareQrBtn, ui.mobileCopyLink, ui.mobileShareQr].forEach((btn) => {
- if (btn) btn.disabled = isLocked;
- });
+ [
+ ui.addEventBtn,
+ ui.addEventInline,
+ ui.mobileAddEventInline,
+ ui.mobileAddEvent,
+ ui.importIcs,
+ ui.mobileImportIcs,
+ ui.clearAll,
+ ui.mobileClearAll,
+ ui.tzAddBtn,
+ ui.mobileAddTzBtn,
+ ].forEach((btn) => {
+ if (btn) btn.disabled = editDisabled;
+ });
+
+ [
+ ui.addEventBtn,
+ ui.addEventInline,
+ ui.mobileAddEventInline,
+ ui.mobileAddEvent,
+ ui.tzAddBtn,
+ ui.mobileAddTzBtn,
+ ui.shareExportSection,
+ ui.dangerZoneSection,
+ ui.mobileShareExportSection,
+ ui.mobileDangerZoneSection,
+ ].forEach((item) => {
+ if (item) item.classList.toggle(CSS_CLASSES.HIDDEN, isReadOnly);
+ });
+
+ [ui.copyLinkBtn, ui.shareQrBtn, ui.mobileCopyLink, ui.mobileShareQr].forEach((btn) => {
+ if (btn) btn.disabled = isLocked;
+ });
// Mobile lock/unlock button visibility
if (ui.mobileLockBtn && ui.mobileUnlockBtn) {
@@ -783,7 +796,6 @@ function updateLockUI() {
ui.mobileUnlockBtn.classList.add(CSS_CLASSES.HIDDEN);
}
}
-
}
function handleReadOnlyToggle() {
@@ -807,7 +819,7 @@ function initLanguageDropdown() {
ui.langList.innerHTML = "";
if (ui.mobileLangList) ui.mobileLangList.innerHTML = "";
-
+
SUPPORTED_LANGUAGES.forEach((lang) => {
// Desktop list item
const li = document.createElement("li");
@@ -873,7 +885,7 @@ function toggleLanguageDropdown(dropdown, trigger) {
// Close other dropdowns first
closeLanguageDropdown(ui.langDropdown, ui.langBtn);
closeLanguageDropdown(ui.mobileLangDropdown, ui.mobileLangBtn);
-
+
dropdown.classList.remove(CSS_CLASSES.HIDDEN);
trigger.setAttribute("aria-expanded", "true");
} else {
@@ -891,11 +903,11 @@ function closeLanguageDropdown(dropdown, trigger) {
function updateLanguageUI() {
if (!ui.currentLang || !ui.langList) return;
const langCode = getCurrentLanguage();
-
+
if (ui.currentLang) {
ui.currentLang.textContent = t(`lang.${langCode}`);
}
-
+
if (ui.mobileCurrentLang) {
ui.mobileCurrentLang.textContent = t(`lang.${langCode}`);
}
@@ -1155,13 +1167,7 @@ function openEventModal({ index = null, date = null } = {}) {
const baseDate = date || selectedDate;
const now = new Date();
- let startDate = new Date(
- baseDate.getFullYear(),
- baseDate.getMonth(),
- baseDate.getDate(),
- now.getHours(),
- now.getMinutes(),
- );
+ let startDate = new Date(baseDate.getFullYear(), baseDate.getMonth(), baseDate.getDate(), now.getHours(), now.getMinutes());
let duration = DEFAULT_EVENT_DURATION;
let title = "";
let color = state.c[0] || DEFAULT_COLORS[0];
@@ -1687,7 +1693,10 @@ function openMobileDrawer() {
if (ui.mobileDrawerBackdrop) ui.mobileDrawerBackdrop.classList.add(CSS_CLASSES.IS_ACTIVE);
document.body.style.overflow = "hidden";
const icon = ui.hamburgerBtn && ui.hamburgerBtn.querySelector("i");
- if (icon) { icon.classList.remove("fa-bars"); icon.classList.add("fa-xmark"); }
+ if (icon) {
+ icon.classList.remove("fa-bars");
+ icon.classList.add("fa-xmark");
+ }
}
function closeMobileDrawer() {
@@ -1695,7 +1704,10 @@ function closeMobileDrawer() {
if (ui.mobileDrawerBackdrop) ui.mobileDrawerBackdrop.classList.remove(CSS_CLASSES.IS_ACTIVE);
document.body.style.overflow = "";
const icon = ui.hamburgerBtn && ui.hamburgerBtn.querySelector("i");
- if (icon) { icon.classList.add("fa-bars"); icon.classList.remove("fa-xmark"); }
+ if (icon) {
+ icon.classList.add("fa-bars");
+ icon.classList.remove("fa-xmark");
+ }
}
function initResponsiveFeatures() {
@@ -1880,16 +1892,15 @@ document.addEventListener("click", (e) => {
});
/* --- PWA Service Worker Registration --- */
-if ('serviceWorker' in navigator) {
- window.addEventListener('load', () => {
- navigator.serviceWorker.register('./sw.js')
+if ("serviceWorker" in navigator) {
+ window.addEventListener("load", () => {
+ navigator.serviceWorker
+ .register("./sw.js")
.then((registration) => {
- console.log('ServiceWorker registration successful with scope: ', registration.scope);
+ console.log("ServiceWorker registration successful with scope: ", registration.scope);
})
.catch((err) => {
- console.log('ServiceWorker registration failed: ', err);
+ console.log("ServiceWorker registration failed: ", err);
});
});
}
-
-