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: Introduce PWA capabilities by adding a manifest, service worker, and registration logic.

Supun Lakmal82b17067e750
diff --git a/index.html b/index.html
index 9c19c3e..ba41cda 100644
--- a/index.html
+++ b/index.html
@@ -38,6 +38,8 @@
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.png" type="image/png" sizes="32x32">
<link rel="apple-touch-icon" href="apple-touch-icon.png" sizes="180x180">
+ <link rel="manifest" href="manifest.json">
+ <meta name="theme-color" content="#ffffff">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
diff --git a/manifest.json b/manifest.json
new file mode 100644
index 0000000..5d0403a
--- /dev/null
+++ b/manifest.json
@@ -0,0 +1,32 @@
+{
+ "name": "hash-calendar",
+ "short_name": "hash-calendar",
+ "description": "Privacy-first calendar that lives in your URL. Create events, share instantly, and keep data in your browser - no accounts or backend.",
+ "start_url": "./index.html",
+ "display": "standalone",
+ "background_color": "#ffffff",
+ "theme_color": "#ffffff",
+ "orientation": "any",
+ "icons": [
+ {
+ "src": "favicon.ico",
+ "sizes": "64x64 32x32 24x24 16x16",
+ "type": "image/x-icon"
+ },
+ {
+ "src": "favicon.png",
+ "sizes": "32x32",
+ "type": "image/png"
+ },
+ {
+ "src": "apple-touch-icon.png",
+ "sizes": "180x180",
+ "type": "image/png"
+ },
+ {
+ "src": "logo.png",
+ "sizes": "512x512",
+ "type": "image/png"
+ }
+ ]
+}
diff --git a/script.js b/script.js
index 1d0f133..09966fd 100644
--- a/script.js
+++ b/script.js
@@ -1508,6 +1508,19 @@ if (document.readyState === "loading") {
init();
}
+/* --- PWA Service Worker Registration --- */
+if ('serviceWorker' in navigator) {
+ window.addEventListener('load', () => {
+ navigator.serviceWorker.register('./sw.js')
+ .then((registration) => {
+ console.log('ServiceWorker registration successful with scope: ', registration.scope);
+ })
+ .catch((err) => {
+ console.log('ServiceWorker registration failed: ', err);
+ });
+ });
+}
+
/* --- World Planner Logic --- */
function initWorldPlanner() {
diff --git a/sw.js b/sw.js
new file mode 100644
index 0000000..d4cff97
--- /dev/null
+++ b/sw.js
@@ -0,0 +1,81 @@
+const CACHE_NAME = 'hash-calendar-v1';
+const ASSETS_TO_CACHE = [
+ './',
+ './index.html',
+ './styles.css',
+ './script.js',
+ './manifest.json',
+ './favicon.ico',
+ './favicon.png',
+ './apple-touch-icon.png',
+ './logo.png',
+ './modules/lz-string.min.js',
+ './modules/app_launcher.js',
+ // Modules
+ './modules/agendaRender.js',
+ './modules/calendarRender.js',
+ './modules/countdownManager.js',
+ './modules/focusMode.js',
+ './modules/hashcalUrlManager.js',
+ './modules/icsImporter.js',
+ './modules/qrCodeManager.js',
+ './modules/recurrenceEngine.js',
+ './modules/timezoneManager.js',
+ // External resources (Font Awesome, Fonts)
+ 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css',
+ 'https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js',
+ 'https://fonts.googleapis.com/css2?family=Fraunces:wght@400;600;700&family=Space+Grotesk:wght@400;500;600&display=swap'
+];
+
+self.addEventListener('install', (event) => {
+ event.waitUntil(
+ caches.open(CACHE_NAME).then((cache) => {
+ return cache.addAll(ASSETS_TO_CACHE);
+ })
+ );
+});
+
+self.addEventListener('activate', (event) => {
+ event.waitUntil(
+ caches.keys().then((cacheNames) => {
+ return Promise.all(
+ cacheNames.map((cacheName) => {
+ if (cacheName !== CACHE_NAME) {
+ return caches.delete(cacheName);
+ }
+ })
+ );
+ })
+ );
+});
+
+self.addEventListener('fetch', (event) => {
+ event.respondWith(
+ caches.match(event.request).then((response) => {
+ // Return cached response if found
+ if (response) {
+ return response;
+ }
+
+ // Clone request for fetch
+ const fetchRequest = event.request.clone();
+
+ return fetch(fetchRequest).then((response) => {
+ // Check if valid response
+ if (!response || response.status !== 200 || response.type !== 'basic') {
+ return response;
+ }
+
+ // Cache the new resource (if it's local)
+ if (event.request.url.startsWith(self.location.origin)) {
+ const responseToCache = response.clone();
+ caches.open(CACHE_NAME).then((cache) => {
+ cache.put(event.request, responseToCache);
+ });
+ }
+
+ return response;
+ });
+ })
+ );
+});