// Saves a size mode on the logged-in user's account (needs the redmine_tonalmine plugin). The user's // other choices (mode, contrast, color) are kept. No size removes the size choice again. // The page must be loaded after the last change, since the saved choice is read from it. export async function setSize(page, size) { const status = await page.evaluate(async (size) => { // The plugin hands the saved choice to theme.js in : Tonalmine.configure({..., user: {...}}) const script = [...document.scripts].find((s) => s.text.includes('Tonalmine.configure(')); const prefs = JSON.parse(script.text.match(/Tonalmine\.configure\((.*)\);/s)[1]).user; if (size) prefs.size = size; else delete prefs.size; const headers = { 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest', 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content }; return (await fetch('/tonalmine/appearance', { method: 'PUT', headers, body: JSON.stringify(prefs) })).status; }, size); if (status !== 204) throw new Error(`could not save size ${size ?? 'default'} (HTTP ${status})`); }