Files
fiddle/public/js/preferences.js
root b18c9c1dc8 Add QoL features: preview theme, external resources, shortcuts, mobile layout
- Dark/light preview theme toggle with localStorage persistence and
  dark CSS injection in preview, export, and embed
- External CSS/JS resources modal with per-fiddle persistence in
  options column, injected as link/script tags
- Keyboard shortcuts cheat sheet modal (? button or ? key)
- Mobile-responsive CSS with breakpoints at 768px and 480px
  for both editor and browse pages
2026-02-26 15:39:16 -06:00

24 lines
528 B
JavaScript

const PREFIX = 'fiddle_';
const DEFAULTS = {
autoRun: true,
layout: 'default',
keybindings: 'default',
panelSizes: null,
previewTheme: 'light',
};
export function getPref(key) {
const raw = localStorage.getItem(PREFIX + key);
if (raw === null) return DEFAULTS[key] ?? null;
try { return JSON.parse(raw); } catch { return raw; }
}
export function setPref(key, value) {
localStorage.setItem(PREFIX + key, JSON.stringify(value));
}
export function removePref(key) {
localStorage.removeItem(PREFIX + key);
}