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

Add JSON bridge for hash import and refresh SW cache

Supun Lakmal3a8bc2a82145
diff --git a/LLM.md b/LLM.md
new file mode 100644
index 0000000..5ba6557
--- /dev/null
+++ b/LLM.md
@@ -0,0 +1,71 @@
+# System Role: Hash Calendar Generator
+
+You are an intelligent URL generator for Hash Calendar.
+Base URL: `https://hash-calendar.netlify.app/`
+
+Your job: accept a natural-language schedule request and return a URL that loads the schedule.
+
+Output rules (must follow exactly):
+
+1. If you can run code to compress JSON: output ONLY two lines:
+ Title: <calendar title>
+ URL: <base_url>#<compressed_payload>
+2. If you cannot run code: output ONLY the JSON payload, then one short sentence:
+ "Use LZ-String compressToEncodedURIComponent on this JSON to build the URL."
+
+Do not include any other text.
+
+---
+
+How to generate the data
+
+1. Parse the request into events, durations, and recurrence.
+2. Pick dates and times:
+ - If the user gives dates/times, use them.
+ - Interpret times in the user's requested timezone; otherwise use UTC.
+ - If only a date is provided (no time), create an all-day event (duration = 0).
+ - If no date is provided, start on the next logical Monday at 09:00.
+3. Convert each event start to minutes since Unix epoch:
+ startMin = floor(timestamp_ms / 60000)
+4. Build the JSON payload using the compact schema below.
+5. Compress the JSON with LZ-String (URI safe) using compressToEncodedURIComponent.
+6. Final URL format: <base_url>#<compressed_payload>
+
+JSON schema (compact form before compression):
+
+```json
+{
+ "t": "Calendar Title",
+ "c": { "0": "2ecc71", "1": "e74c3c" },
+ "e": [
+ [startMin, duration, "Title", colorIndex, "recurrence"]
+ ],
+ "s": { "d": 1, "m": 1, "v": "week" },
+ "z": ["UTC"],
+ "mp": { "h": "UTC", "z": ["UTC"], "s": timestamp_ms, "d": "YYYY-MM-DD", "f24": 1 }
+}
+```
+
+Field notes
+
+- `c`: palette overrides by index. Values are hex WITHOUT `#`.
+- `e`: each event is `[startMin, duration, title]` with optional `colorIndex` and `recurrence`.
+- `duration`: minutes; `0` means all-day.
+- `recurrence`: `d` (daily), `w` (weekly), `m` (monthly), `y` (yearly).
+- `s`: settings (theme, week start, last view). Use `{ "d": 1, "m": 1, "v": "week" }` unless asked otherwise.
+- `z`: list of saved timezones (IANA strings). Use `"UTC"` if none is requested.
+- `mp`: planner state; set `mp.s` and `mp.d` to the schedule start date.
+
+Compression rule
+
+- Use LZ-String compressToEncodedURIComponent (URI safe). Do NOT guess the hash.
+
+Optional internal reference (use only if you can run code):
+
+```python
+import json
+# NOTE: Use a real LZ-String implementation. If you do not have it, output JSON only.
+# Example call: LZString().compressToEncodedURIComponent(json.dumps(payload, separators=(',', ':')))
+```
+
+Status: Ready. Ask for a schedule.
diff --git a/README.md b/README.md
index 102feca..15128ea 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,14 @@ GitHub: https://github.com/supunlakmal/hash-calendar
</tr>
<tr>
<td><img src="demo/demo-7.png" alt="hash-calendar demo 7" width="420"></td>
+ <td><img src="demo/demo-8.png" alt="hash-calendar demo 8" width="420"></td>
+ </tr>
+ <tr>
+ <td><img src="demo/demo-9.png" alt="hash-calendar demo 9" width="420"></td>
+ <td><img src="demo/demo-10.png" alt="hash-calendar demo 10" width="420"></td>
+ </tr>
+ <tr>
+ <td><img src="demo/demo-11.png" alt="hash-calendar demo 11" width="420"></td>
<td></td>
</tr>
</table>
@@ -58,6 +66,56 @@ GitHub: https://github.com/supunlakmal/hash-calendar
Encrypted links start with `#ENC:`. Clearing the hash resets the calendar.
+## URL hash payload (full schema + example)
+
+The URL hash stores a compressed JSON payload (LZ-String). The JSON below is the compact form **before** compression. (This section intentionally excludes encrypted payloads.)
+
+```json
+{
+ "t": "Acme Schedule",
+ "c": { "1": "2ecc71", "3": "e74c3c" },
+ "e": [
+ [28930080, 30, "Daily standup", 1, "d"],
+ [28930200, 0, "Launch day", 3],
+ [28930800, 90, "Design review"]
+ ],
+ "s": { "d": 1, "m": 1, "v": "week" },
+ "z": ["America/New_York", "Europe/London"],
+ "mp": {
+ "h": "America/Los_Angeles",
+ "z": ["UTC", "Asia/Tokyo"],
+ "s": 1769721600000,
+ "d": "2026-01-30",
+ "f24": 1
+ }
+}
+```
+
+Key meanings:
+
+- `t`: Calendar title (string).
+- `c`: Colors.
+ - **Compact form (most common):** an object of palette overrides by index (keys `"0"`, `"1"`, ...), values are hex colors **without** the `#`.
+ - **Expanded form (also accepted):** an array of hex colors (with or without `#`).
+- `e`: Events array. Each event entry is a compact array:
+ - `[startMin, duration, title]` is the minimum shape.
+ - Optional `colorIndex` and `rule` follow: `[startMin, duration, title, colorIndex, rule]`.
+ - `startMin` is minutes since Unix epoch (`Math.floor(date.getTime() / 60000)`).
+ - `duration` is minutes; `0` means an all-day event.
+ - `colorIndex` points into the palette (defaults to `0`).
+ - `rule` is recurrence: `d` (daily), `w` (weekly), `m` (monthly), `y` (yearly).
+- `s`: Settings object:
+ - `d`: Theme (`1` = dark, `0` = light).
+ - `m`: Week start (`1` = Monday, `0` = Sunday).
+ - `v`: Last view (`day`, `week`, `month`, `year`, `agenda`).
+- `z`: Saved world-clock timezones (IANA strings).
+- `mp`: World planner state (optional):
+ - `h`: Home timezone (IANA string).
+ - `z`: Extra timezones to compare (IANA strings).
+ - `s`: Selected scrubber timestamp (milliseconds since Unix epoch).
+ - `d`: Planner date (YYYY-MM-DD string).
+ - `f24`: Time format (`1` = 24h, `0` = 12h).
+
## Getting started
Open `index.html` in your browser.
diff --git a/demo/demo-10.png b/demo/demo-10.png
new file mode 100644
index 0000000..93dee2a
Binary files /dev/null and b/demo/demo-10.png differ
diff --git a/demo/demo-11.png b/demo/demo-11.png
new file mode 100644
index 0000000..232f2bf
Binary files /dev/null and b/demo/demo-11.png differ
diff --git a/demo/demo-9.png b/demo/demo-9.png
new file mode 100644
index 0000000..a2b0f68
Binary files /dev/null and b/demo/demo-9.png differ
diff --git a/json.html b/json.html
new file mode 100644
index 0000000..c785b1f
--- /dev/null
+++ b/json.html
@@ -0,0 +1,173 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>hash-calendar JSON bridge</title>
+ <meta name="robots" content="noindex">
+ <style>
+ :root {
+ color-scheme: light;
+ }
+
+ body {
+ margin: 0;
+ font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
+ background: #f6f6f4;
+ color: #1f1f1f;
+ }
+
+ main {
+ max-width: 720px;
+ margin: 12vh auto 0;
+ padding: 24px;
+ background: #ffffff;
+ border-radius: 14px;
+ box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
+ }
+
+ h1 {
+ font-size: 1.5rem;
+ margin: 0 0 12px;
+ }
+
+ p {
+ margin: 0 0 12px;
+ line-height: 1.6;
+ }
+
+ pre {
+ margin: 12px 0 0;
+ padding: 12px;
+ background: #0d0d0d;
+ color: #f6f6f4;
+ border-radius: 10px;
+ overflow: auto;
+ font-size: 0.875rem;
+ }
+
+ .hidden {
+ display: none;
+ }
+ </style>
+</head>
+
+<body>
+ <main>
+ <h1>hash-calendar JSON bridge</h1>
+ <p id="status">Processing JSON payload...</p>
+ <p id="hint" class="hidden">Pass a URL-encoded JSON string as <code>?json=</code> or raw JSON as the only query param.</p>
+ <pre id="details" class="hidden"></pre>
+ </main>
+
+ <script src="modules/lz-string.min.js"></script>
+ <script>
+ (function () {
+ const status = document.getElementById("status");
+ const details = document.getElementById("details");
+ const hint = document.getElementById("hint");
+
+ function showError(message, error) {
+ status.textContent = message;
+ hint.classList.remove("hidden");
+ if (error) {
+ details.textContent = String(error);
+ details.classList.remove("hidden");
+ }
+ }
+
+ function extractRawParam(search, key) {
+ if (!search) return null;
+ const raw = search.startsWith("?") ? search.slice(1) : search;
+ const token = `${key}=`;
+ const idx = raw.indexOf(token);
+ if (idx === -1) return null;
+ let value = raw.slice(idx + token.length);
+ let cursor = 0;
+ while (true) {
+ const amp = value.indexOf("&", cursor);
+ if (amp === -1) break;
+ const next = value.slice(amp + 1);
+ if (/^[A-Za-z0-9_.-]+=/.test(next)) {
+ value = value.slice(0, amp);
+ break;
+ }
+ cursor = amp + 1;
+ }
+ return value || null;
+ }
+
+ function maybeDecode(value) {
+ if (typeof value !== "string") return value;
+ if (!/%[0-9A-Fa-f]{2}/.test(value) && value.indexOf("+") === -1) {
+ return value;
+ }
+ try {
+ return decodeURIComponent(value.replace(/\+/g, " "));
+ } catch (error) {
+ return value;
+ }
+ }
+
+ function readPayloadCandidates() {
+ const keys = ["json", "data", "state", "payload"];
+ const candidates = [];
+ const params = new URLSearchParams(window.location.search);
+ keys.forEach((key) => {
+ const value = params.get(key);
+ if (value) candidates.push(value);
+ });
+ const search = window.location.search;
+ keys.forEach((key) => {
+ const rawValue = extractRawParam(search, key);
+ if (rawValue) candidates.push(maybeDecode(rawValue));
+ });
+ if (window.location.hash && window.location.hash.length > 1) {
+ const raw = window.location.hash.slice(1);
+ try {
+ candidates.push(decodeURIComponent(raw));
+ } catch (error) {
+ candidates.push(raw);
+ }
+ }
+ return candidates.filter((value, index, arr) => value && arr.indexOf(value) === index);
+ }
+
+ if (!window.LZString || !window.LZString.compressToEncodedURIComponent) {
+ showError("Compression library failed to load.");
+ return;
+ }
+
+ const candidates = readPayloadCandidates();
+ if (!candidates.length) {
+ showError("Missing JSON payload.");
+ return;
+ }
+
+ let parsed;
+ let lastError;
+ for (const candidate of candidates) {
+ try {
+ parsed = JSON.parse(candidate);
+ break;
+ } catch (error) {
+ lastError = error;
+ }
+ }
+ if (!parsed) {
+ showError("Invalid JSON payload. URL-encode it or send raw JSON as the only query param.", lastError);
+ return;
+ }
+
+ const json = JSON.stringify(parsed);
+ const compressed = window.LZString.compressToEncodedURIComponent(json);
+ const basePath = window.location.pathname.replace(/json\.html$/, "");
+ const target = `${window.location.origin}${basePath}#${compressed}`;
+ status.textContent = "Redirecting to calendar...";
+ window.location.replace(target);
+ })();
+ </script>
+</body>
+
+</html>
diff --git a/sw.js b/sw.js
index d4cff97..023fd77 100644
--- a/sw.js
+++ b/sw.js
@@ -1,7 +1,8 @@
-const CACHE_NAME = 'hash-calendar-v1';
+const CACHE_NAME = 'hash-calendar-v3';
const ASSETS_TO_CACHE = [
'./',
'./index.html',
+ './json.html',
'./styles.css',
'./script.js',
'./manifest.json',