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: Add direct-link event creation from human-readable URL paths and implement import logic for events from URL

Supun Lakmalc012e17f532e
diff --git a/README.md b/README.md
index bbf08cd..a536a1c 100644
--- a/README.md
+++ b/README.md
@@ -18,13 +18,14 @@ GitHub: https://github.com/supunlakmal/hash-calendar
- App launcher menu in the top bar
- PWA support (manifest + service worker cache)
- JSON bridge page (`json.html`) for raw JSON -> hash URL redirect
+- Direct-link event creation from human-readable URL paths
## Features
### Calendar and planning
- Day, week, month, year, and agenda views
-- Create, edit, delete, recurring, and all-day events
+- Create, edit, delete, recurring, all-day, and cross-day timed events
- Color palette support and editable calendar title
- Focus mode overlay with timer and upcoming list
- "Up Next" countdown widget
@@ -46,6 +47,7 @@ GitHub: https://github.com/supunlakmal/hash-calendar
- View/copy JSON and raw hash from modal
- Export JSON
- Import `.ics` (supports daily/weekly/monthly/yearly RRULE frequency mapping)
+- One-time import from readable URL path or hash-path, then auto-save to compressed hash
### Timezone tools
@@ -123,6 +125,28 @@ Default ports are `80` and `443` (override with `HOST_PORT_HTTP` / `HOST_PORT_HT
Use `json.html` to pass JSON payloads via query params (`json`, `data`, `state`, `payload`) and auto-redirect to a compressed hash URL.
+## Direct-link event creation (readable URL paths)
+
+You can create events directly from the URL path. The app parses readable paths from either:
+
+- `window.location.pathname` (e.g. `/2025/12/25/10/30/Open-Presents`)
+- A hash-path beginning with `/` (e.g. `#/2025/12/25/10/30/Open-Presents`)
+
+Supported patterns:
+
+| Pattern | Scenario | Example |
+| :-- | :-- | :-- |
+| `YYYY/MM/DD/HH/mm/Title` | Full precision | `/2025/12/25/10/30/Open-Presents` |
+| `YYYY/MM/DD/Title` | All-day | `/2025/12/25/Christmas-Day` |
+| `YYYY/MM/DD/HH/mm+Minutes/Title` | Timed with explicit duration | `/2025/12/25/10/00+90/Family-Brunch` |
+| `Event1,Event2` | Multi-event in one link | `/2025/01/01/Gym,2025/01/01/10/00/Clean` |
+
+Behavior notes:
+
+- URL segments are decoded (`decodeURIComponent`), and dashes in titles become spaces.
+- If title is missing, it falls back to `New Event (URL)`.
+- Parsed events are appended once, then the readable path is cleaned and state is persisted as the normal compressed URL hash.
+
## How it works
1. State is serialized to JSON.
@@ -146,12 +170,12 @@ Example (before compression):
[28930800, 90, "Design review"]
],
"s": { "d": 1, "m": 1, "v": "week", "l": "en", "r": 1 },
- "z": ["America/New_York", "Europe/London"],
"mp": {
"h": "America/Los_Angeles",
- "z": ["UTC", "Asia/Tokyo"],
+ "z": ["UTC", "Asia/Tokyo", "Europe/London"],
"s": 1769721600000,
- "d": "2026-01-30"
+ "d": "2026-01-30",
+ "f24": 1
}
}
```
@@ -162,11 +186,12 @@ Key fields:
- `c`: color overrides by palette index (hex without `#`)
- `e`: events as `[startMin, duration, title, colorIndex?, recurrence?]`
- `s`: settings (`d` theme, `m` week start, `v` last view, `l` language, `r` read-only mode)
-- `z`: saved world-clock zones
-- `mp`: optional world planner snapshot (`h` home zone, `z` planner zones, `s` scrubber timestamp, `d` planner date)
+- `mp`: optional world-time snapshot (`h` home zone, `z` saved zones, `s` scrubber timestamp, `d` planner date, `f24` 24-hour mode)
Recurrence values: `d` (daily), `w` (weekly), `m` (monthly), `y` (yearly)
+Legacy compatibility: older payloads with top-level `z` / `timezones` / `tz` are still read and migrated into `mp.z`.
+
## Project structure
- `index.html` - main app UI
@@ -190,6 +215,7 @@ Recurrence values: `d` (daily), `w` (weekly), `m` (monthly), `y` (yearly)
- `cryptoManager.js` - encryption/decryption helpers
- `i18n.js` - localization engine
- `app_launcher.js` - app launcher menu
+ - `urlPathEventParser.js` - readable URL path parser for event creation
- `lz-string.min.js` - compression library
- `demo/` - screenshot assets
- `Dockerfile`, `docker-compose.yaml`, `Caddyfile` - containerized deployment
diff --git a/modules/urlPathEventParser.js b/modules/urlPathEventParser.js
new file mode 100644
index 0000000..9e53ebe
--- /dev/null
+++ b/modules/urlPathEventParser.js
@@ -0,0 +1,108 @@
+import { DEFAULT_EVENT_DURATION, MS_PER_MINUTE } from "./constants.js";
+
+const DEFAULT_URL_EVENT_TITLE = "New Event (URL)";
+
+function safeDecodePath(path) {
+ try {
+ return decodeURIComponent(String(path || ""));
+ } catch (error) {
+ return String(path || "");
+ }
+}
+
+function toInteger(value) {
+ if (typeof value !== "string" || !/^\d+$/.test(value)) return null;
+ const parsed = Number.parseInt(value, 10);
+ return Number.isFinite(parsed) ? parsed : null;
+}
+
+function isValidDate(year, month, day) {
+ if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day)) return false;
+ if (month < 1 || month > 12 || day < 1 || day > 31) return false;
+ const date = new Date(year, month - 1, day);
+ return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
+}
+
+function normalizeTitle(parts) {
+ const title = parts.join(" ").replace(/-/g, " ").trim();
+ return title || DEFAULT_URL_EVENT_TITLE;
+}
+
+function parseTimeParts(hourText, minuteText) {
+ const hour = toInteger(hourText);
+ if (hour === null || hour > 23) return null;
+ if (typeof minuteText !== "string" || minuteText.length === 0) return null;
+
+ let minuteRaw = minuteText;
+ let duration = DEFAULT_EVENT_DURATION;
+
+ if (minuteText.includes("+")) {
+ const pieces = minuteText.split("+");
+ if (pieces.length !== 2) return null;
+ minuteRaw = pieces[0];
+ const parsedDuration = toInteger(pieces[1]);
+ if (parsedDuration === null) return null;
+ duration = Math.max(1, parsedDuration);
+ }
+
+ const minute = toInteger(minuteRaw);
+ if (minute === null || minute > 59) return null;
+
+ return { hour, minute, duration };
+}
+
+function findDateStart(parts) {
+ for (let i = 0; i <= parts.length - 3; i += 1) {
+ const year = toInteger(parts[i]);
+ const month = toInteger(parts[i + 1]);
+ const day = toInteger(parts[i + 2]);
+ if (isValidDate(year, month, day)) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+function parseEventBlock(block) {
+ const rawParts = block.split("/").filter((part) => part.length > 0);
+ if (rawParts.length < 3) return null;
+
+ const dateStart = findDateStart(rawParts);
+ if (dateStart === -1) return null;
+
+ const parts = rawParts.slice(dateStart);
+ const year = toInteger(parts[0]);
+ const month = toInteger(parts[1]);
+ const day = toInteger(parts[2]);
+ if (!isValidDate(year, month, day)) return null;
+
+ let startDate = new Date(year, month - 1, day);
+ let duration = 0;
+ let titleParts = parts.slice(3);
+
+ if (parts.length >= 5) {
+ const time = parseTimeParts(parts[3], parts[4]);
+ if (time) {
+ startDate = new Date(year, month - 1, day, time.hour, time.minute);
+ duration = time.duration;
+ titleParts = parts.slice(5);
+ }
+ }
+
+ const title = normalizeTitle(titleParts);
+ const startMin = Math.floor(startDate.getTime() / MS_PER_MINUTE);
+ return [startMin, duration, title, 0];
+}
+
+export function parsePathToEventEntries(path) {
+ const decodedPath = safeDecodePath(path);
+ const cleanPath = decodedPath.replace(/^\/+|\/+$/g, "").trim();
+ if (!cleanPath) return [];
+
+ return cleanPath
+ .split(",")
+ .map((block) => block.trim())
+ .filter(Boolean)
+ .map(parseEventBlock)
+ .filter((entry) => Array.isArray(entry));
+}
diff --git a/script.js b/script.js
index 4c655b1..20aa763 100644
--- a/script.js
+++ b/script.js
@@ -36,6 +36,7 @@ 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 { parsePathToEventEntries } from "./modules/urlPathEventParser.js";
import { WorldPlanner } from "./modules/worldPlannerModule.js";
let state = cloneState(DEFAULT_STATE);
@@ -1448,6 +1449,7 @@ async function attemptUnlock() {
state = normalizeState(loaded);
if (state.s.l) setLanguage(state.s.l);
applyStoredView();
+ await importEventsFromPath();
render();
showToast(t("toast.calendarUnlocked"), "success");
} catch (error) {
@@ -1458,7 +1460,7 @@ async function attemptUnlock() {
}
async function loadStateFromHash() {
- if (!window.location.hash) {
+ if (!window.location.hash || getCreationHashPath()) {
state = cloneState(DEFAULT_STATE);
// Initialize language from local storage if no hash
state.s.l = getCurrentLanguage();
@@ -1483,8 +1485,69 @@ async function loadStateFromHash() {
applyStoredView();
}
+function getCreationHashPath() {
+ const rawHash = window.location.hash.startsWith("#") ? window.location.hash.slice(1) : window.location.hash;
+ if (!rawHash || rawHash === "/") return "";
+ return rawHash.startsWith("/") ? rawHash : "";
+}
+
+function cleanUrlAfterImport(creationSource) {
+ const search = window.location.search || "";
+ if (creationSource === "hash") {
+ // Remove the human-readable hash
+ window.history.replaceState({}, "", `${window.location.pathname}${search}`);
+ } else if (creationSource === "pathname") {
+ // Remove the human-readable pathname and redirect to root
+ const hash = window.location.hash || "";
+ window.history.pushState({}, "", `/${search}${hash}`);
+ }
+}
+
+async function importEventsFromPath() {
+ if (isCalendarLocked() || isReadOnlyMode()) return 0;
+
+ // Check pathname first
+ let entries = parsePathToEventEntries(window.location.pathname);
+ let creationSource = entries.length ? "pathname" : null;
+
+ // Check hash second (only if pathname didn't have readable data)
+ if (!entries.length) {
+ const hashPath = getCreationHashPath();
+ if (hashPath) {
+ entries = parsePathToEventEntries(hashPath);
+ creationSource = entries.length ? "hash" : null;
+ }
+ }
+
+ if (!entries.length) return 0;
+
+ // USER DEFINITION: any readable pattern import is source === "path"
+ const source = "path";
+ state.e.push(...entries);
+
+ const firstStartMin = Number(entries[0][0]);
+ if (Number.isFinite(firstStartMin)) {
+ const firstDate = startOfDay(new Date(firstStartMin * MS_PER_MINUTE));
+ selectedDate = firstDate;
+ viewDate = firstDate;
+ }
+
+ // Always clean the URL and persist to compressed hash for "path" source
+ cleanUrlAfterImport(creationSource);
+ if (saveTimer) {
+ window.clearTimeout(saveTimer);
+ saveTimer = null;
+ }
+ await persistStateToHash();
+ return entries.length;
+}
+
function handleHashChange() {
- loadStateFromHash().then(render);
+ loadStateFromHash().then(() => {
+ importEventsFromPath().then(() => {
+ render();
+ });
+ });
}
function handleTitleInput() {
@@ -1970,6 +2033,7 @@ async function init() {
bindEvents();
initResponsiveFeatures();
await loadStateFromHash();
+ await importEventsFromPath();
if (!isEncryptedHash() && !hasStoredData() && window.location.hash) {
clearHash();
}