(() => { 'use strict'; const root = document.querySelector('.interfer.quiz'); if (!root) return; const fixed = root.dataset.fixedOrder === 'true'; const scope = root.dataset.quizScope || 'quiz'; // Each participant gets reproducible shuffled answer positions. The order // stays the same on retries, preventing feedback from moving the answers. const participantCode = document.querySelector('[data-participant-code]')?.dataset.participantCode || 'local'; function hash(s) { let h = 2166136261; for (let i=0;i>>0; } function rand(seed) { return () => { seed+=0x6D2B79F5; let t=seed; t=Math.imul(t^(t>>>15),t|1);t^=t+Math.imul(t^(t>>>7),t|61); return ((t^(t>>>14))>>>0)/4294967296; }; } root.querySelectorAll('.question').forEach(card => { const key = card.dataset.question; const choices = card.querySelector('.quiz-options'); const opts = [...choices.children]; if (!fixed) { const next = rand(hash(participantCode+'|'+scope+'|'+(card.dataset.shuffleGroup || key))); for(let i=opts.length-1;i>0;i--) {const j=Math.floor(next()*(i+1)); [opts[i],opts[j]]=[opts[j],opts[i]];} opts.forEach(opt => choices.appendChild(opt)); } const storageKey='interfer:'+participantCode+':'+scope+':'+key; try { const saved = sessionStorage.getItem(storageKey); if (saved) { const option=[...card.querySelectorAll('input[type="radio"]')].find(o=>o.value===saved); if(option) option.checked=true; }} catch(e) {} card.querySelectorAll('input[type="radio"]').forEach(input=>input.addEventListener('change',()=>{ try { sessionStorage.setItem(storageKey,input.value); } catch(e) {} })); }); })(); // Replace oTree's generic error heading with participant-friendly instructions. window.addEventListener('DOMContentLoaded', () => { const candidates = document.querySelectorAll('.otree-form-errors, .alert-danger, .alert.alert-danger'); candidates.forEach(node => { const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT); let child; while ((child = walker.nextNode())) { if (child.textContent.includes('Please fix the errors.')) { child.textContent = child.textContent.replace('Please fix the errors.', 'Some of your answers are not correct yet. Please review the explanations below and try again.'); } } }); });