side-notes/shared/key-builder.js
Fabio Montefuscolo 4365b7687b feat: implement Side Notes Chrome extension
- Manifest V3 with sidePanel, tabs, webNavigation, unlimitedStorage permissions
- Background service worker: sidePanel setup + SPA navigation detection
- Shared modules: URL key derivation (buildNoteKey) and IndexedDB storage
- Side panel: per-tab markdown editor with debounced autosave, in-panel find
- Cross-panel consistency via BroadcastChannel with focus-aware refresh
- Notes-list page: day-grouped entries, click-to-focus/navigate behavior
- Dark theme by default
2026-08-03 19:51:34 +02:00

43 lines
1.1 KiB
JavaScript

// Shared URL-key derivation for note lookups.
// Used by the side panel (load/save), the notes-list click handler
// (tab matching), and background navigation detection.
const DEFAULT_CONFIG = {
// Default: scheme://domain/path?search, hash excluded.
buildKey(url) {
try {
const u = new URL(url);
return `${u.protocol}//${u.host}${u.pathname}${u.search}`;
} catch {
// If URL parsing fails, use the raw string as-is.
return url;
}
},
};
let _config = { ...DEFAULT_CONFIG };
/**
* Derive a storage key from a page URL.
* @param {string} url
* @param {object} [config] — optional override (for testing / future UI changes)
* @returns {string}
*/
export function buildNoteKey(url, config = _config) {
return config.buildKey(url);
}
/**
* Swap the key-derivation rule at runtime.
* @param {object} newConfig — must expose a `buildKey(url)` function
*/
export function setKeyConfig(newConfig) {
_config = { ...newConfig };
}
/**
* Return the current config (read-only copy).
*/
export function getKeyConfig() {
return { ..._config };
}