Files
lpra/internal/server/web/static/prefs.js
T

30 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The look of the panel, as each user set it (Аккаунт › Вид): applied at
// once on load from what the page came with, and again on every change.
(function () {
'use strict';
let p = Object.assign({}, (window.APP && window.APP.prefs) || {});
function apply() {
const b = document.body;
// Parts that follow a setting of their own (the chat's model menu).
document.dispatchEvent(new CustomEvent('lpra:prefs'));
b.dataset.tabicons = p.tabIcons || 'left';
b.classList.toggle('compact', !!p.compact);
b.classList.toggle('no-ftime', p.fileTime === 'hide');
b.classList.toggle('no-motion', p.motion === 'off');
// Open terminals take the new size at once.
if (window.Workspace) Workspace.panes().forEach(t => {
if (t.term && t.term.options.fontSize !== termFont()) { t.term.options.fontSize = termFont(); t.fit(); }
});
}
const termFont = () => p.termFont || (matchMedia('(pointer: coarse)').matches ? 13 : 14);
async function set(k, v) {
p[k] = v;
apply();
const r = await fetch('/api/panel/account/prefs', {method: 'POST', headers: {'Content-Type': 'application/json'},
credentials: 'same-origin', body: JSON.stringify(p)}).then(x => x.json()).catch(() => ({ok: false}));
return r.ok;
}
apply();
window.Prefs = {get: () => Object.assign({}, p), set, apply, termFont};
})();