mirror of
https://github.com/owncast/owncast.git
synced 2025-11-03 04:27:18 +08:00
Support changing your own name and handling name change events
This commit is contained in:
47
web/utils/localStorage.ts
Normal file
47
web/utils/localStorage.ts
Normal file
@ -0,0 +1,47 @@
|
||||
export const LOCAL_STORAGE_KEYS = {
|
||||
username: 'username',
|
||||
};
|
||||
|
||||
export function getLocalStorage(key) {
|
||||
try {
|
||||
return localStorage.getItem(key);
|
||||
} catch (e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function setLocalStorage(key, value) {
|
||||
try {
|
||||
if (value !== '' && value !== null) {
|
||||
localStorage.setItem(key, value);
|
||||
} else {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
return true;
|
||||
} catch (e) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function clearLocalStorage(key) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
// jump down to the max height of a div, with a slight delay
|
||||
export function jumpToBottom(element, behavior) {
|
||||
if (!element) return;
|
||||
|
||||
if (!behavior) {
|
||||
behavior = document.visibilityState === 'visible' ? 'smooth' : 'instant';
|
||||
}
|
||||
|
||||
setTimeout(
|
||||
() => {
|
||||
element.scrollTo({
|
||||
top: element.scrollHeight,
|
||||
left: 0,
|
||||
behavior,
|
||||
});
|
||||
},
|
||||
50,
|
||||
element,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user