owncast/webroot/js/utils.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-06-14 10:24:26 +03:00
function getLocalStorage(key) {
try {
return localStorage.getItem(key);
} catch (e) {
}
return null;
}
function setLocalStorage(key, value) {
try {
2020-06-14 11:10:26 +03:00
if (value !== "" && value !== null) {
localStorage.setItem(key, value);
} else {
localStorage.removeItem(key);
}
2020-06-14 10:24:26 +03:00
return true;
} catch (e) {}
return false;
}
2020-06-14 11:10:26 +03:00
function clearLocalStorage(key) {
localStorage.removeItem(key);
}
2020-06-14 10:24:26 +03:00
function jumpToBottom(id) {
const div = document.querySelector(id);
div.scrollTo({
2020-06-14 11:10:26 +03:00
top: div.scrollHeight,// - div.clientHeight,
2020-06-14 10:24:26 +03:00
left: 0,
behavior: 'smooth'
});
}
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
2020-06-15 07:14:42 +03:00
}
function setVHvar() {
let vh = window.innerHeight * 0.01;
// Then we set the value in the --vh custom property to the root of the document
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
function mobileVHhack() {
setVHvar();
window.addEventListener("orientationchange", setVHvar);
2020-06-14 10:24:26 +03:00
}