Files
surtic86andClaude Opus 5.5 901ed1c098 fix: e2e size helper keeps the user's other appearance choices
It sent the size alone, which replaced the admin's saved mode, contrast
and color.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 10:18:45 +02:00

17 lines
1.1 KiB
JavaScript

// 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 <head>: 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})`);
}