0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-01-24 15:16:32 +01:00
gitea/web_src/js/modules/storage.ts
2025-12-17 21:36:56 +01:00

21 lines
695 B
TypeScript

/** Get a setting from localStorage */
export function getLocalStorageSetting(key: string) {
return localStorage?.getItem(key);
}
/** Set a setting in localStorage */
export function setLocalStorageSetting(key: string, value: string) {
return localStorage?.setItem(key, value);
}
/** Add a listener to the 'storage' event for given setting key. This event only fires in non-current tabs. */
export function addLocalStorageChangeListener(key: string, listener: (e: StorageEvent) => void) {
const fn = (e: StorageEvent) => {
if (e.storageArea === localStorage && e.key === key) {
listener(e);
}
};
window.addEventListener('storage', fn);
return fn; // for unregister
}