(function () { const quizId = parseInt(new URLSearchParams(location.search).get('id'), 10); const state = { quiz: null, assets: [], questions: [] }; let dirty = false; let saving = false; let dragState = null; const FREE_KINDS = ['line', 'text', 'number', 'date']; const OPTION_KINDS = ['single', 'multiple', 'select']; function isFree(kind) { return FREE_KINDS.includes(kind); } function isOptionKind(kind) { return OPTION_KINDS.includes(kind); } function normalizeKind(kind) { return isFree(kind) || isOptionKind(kind) ? kind : 'single'; } function at(s) { return esc(String(s == null ? '' : s)).replace(/"/g, '"'); } function assetName(a) { return String(a.path || '').split('/').pop(); } function mediaSrc(a) { const name = assetName(a); const play = a.kind === 'audio' || a.kind === 'video' ? '&play=1' : ''; return API + '/api/quizzes/files/' + encodeURIComponent(name) + '?token=' + encodeURIComponent(token || '') + play; } function allAssets() { const out = state.assets.slice(); for (const q of state.questions) { out.push(...q.assets); for (const o of q.options) out.push(...o.assets); } return out; } function findAsset(id) { return allAssets().find(a => Number(a.id) === Number(id)) || null; } function markDirty() { dirty = true; document.getElementById('qeDirty').hidden = false; } function clearDirty() { dirty = false; document.getElementById('qeDirty').hidden = true; } function fromServer(data) { const quiz = data.quiz || {}; state.quiz = { id: quiz.id, title: quiz.title || '', description: quiz.description || '', kind: quiz.kind === 'survey' ? 'survey' : 'test', is_published: quiz.is_published === true, shuffle_questions: quiz.shuffle_questions === true, shuffle_options: quiz.shuffle_options === true, show_results: quiz.show_results !== false, allow_anonymous: quiz.allow_anonymous === true, max_attempts: quiz.max_attempts == null ? '' : quiz.max_attempts, time_limit_min: quiz.time_limit_min || 0, pass_percent: quiz.pass_percent == null ? 60 : quiz.pass_percent, cover_path: quiz.cover_path || null, }; state.assets = Array.isArray(data.quiz_assets) ? data.quiz_assets.slice() : []; state.questions = (data.questions || []).map(q => ({ id: q.id, kind: normalizeKind(q.kind), text: q.text || '', description: q.description || '', weight: q.weight == null ? 1 : Number(q.weight), partial_credit: q.partial_credit === true, required: q.required !== false, min_length: Number(q.min_length) || 0, options_inline: q.options_inline === true, text_match: q.text_match === 'contains' ? 'contains' : 'exact', accepted_answers: Array.isArray(q.accepted_answers) ? q.accepted_answers.slice() : [], assets: Array.isArray(q.assets) ? q.assets.slice() : [], options: (q.options || []).map(o => ({ id: o.id, text: o.text || '', description: o.description || '', is_correct: o.is_correct === true, weight: o.weight == null ? 1 : Number(o.weight), assets: Array.isArray(o.assets) ? o.assets.slice() : [], })), })); } function payload() { const q = state.quiz; return { title: q.title, description: q.description, kind: q.kind, is_published: q.is_published, shuffle_questions: q.shuffle_questions, shuffle_options: q.shuffle_options, show_results: q.show_results, allow_anonymous: q.allow_anonymous, max_attempts: q.max_attempts === '' ? null : q.max_attempts, time_limit_min: q.time_limit_min === '' ? 0 : q.time_limit_min, pass_percent: q.pass_percent === '' ? 60 : q.pass_percent, cover_path: q.cover_path, asset_ids: state.assets.map(a => a.id), questions: state.questions.map(qq => ({ id: qq.id || null, kind: qq.kind, text: qq.text, description: qq.description, weight: qq.weight, partial_credit: qq.partial_credit, required: qq.required, min_length: qq.min_length, options_inline: qq.options_inline, text_match: qq.text_match, accepted_answers: qq.accepted_answers, asset_ids: qq.assets.map(a => a.id), options: qq.options.map(o => ({ id: o.id || null, text: o.text, description: o.description, is_correct: o.is_correct, weight: o.weight, asset_ids: o.assets.map(a => a.id), })), })), }; } function assetsHtml(assets, owner) { if (!assets.length) return ''; const cards = assets.map(a => { const kind = a.kind || 'file'; let inner; if (kind === 'image') { inner = `${at(a.original_name || '')}`; } else if (kind === 'audio') { inner = ``; } else if (kind === 'video') { inner = ``; } else { inner = ` ${esc(a.original_name || assetName(a))}`; } const caption = ``; return `
${inner}${caption}
`; }); return cards.join(''); } function optionHtml(o, qi, oi, isTest) { const owner = `o:${qi}:${oi}`; return `
⠿ ${isTest ? ` ` : ''}
${assetsHtml(o.assets, owner)}
`; } function acceptedHtml(q, qi, isTest) { if (!isFree(q.kind) || !isTest) return ''; const hints = { line: 'Ответ вводится одной строкой. Регистр, «ё» и лишние пробелы не важны.', text: 'Ответ вводится многострочным текстом. Регистр, «ё» и лишние пробелы не важны.', number: 'Ответ сравнивается как число: «4», «4,0» и « 4 » совпадут.', date: 'Ответ сравнивается как дата: ГГГГ-ММ-ДД или ДД.ММ.ГГГГ.', }; const placeholder = q.kind === 'number' ? '4 4.0' : q.kind === 'date' ? '2026-12-31 31.12.2026' : '4 четыре'; const matchSelect = q.kind === 'line' || q.kind === 'text' ? `` : ''; return `
${matchSelect} ${hints[q.kind] || ''} Балл за вопрос: вес вопроса.
`; } function questionHtml(q, qi) { const isTest = state.quiz.kind === 'test'; const owner = `q:${qi}`; const kindOptions = [ ['single', 'Один ответ (радиокнопки)'], ['multiple', 'Несколько ответов (флажки)'], ['select', 'Выпадающий список'], ['line', 'Строка'], ['text', 'Многострочный текст'], ['number', 'Число'], ['date', 'Дата'], ].map(([value, label]) => ``).join(''); const options = isOptionKind(q.kind) ? `
${q.options.map((o, oi) => optionHtml(o, qi, oi, isTest)).join('')}
` : ''; return `
⠿ ${qi + 1} ${isTest ? `` : ''}
${isTest && q.kind === 'multiple' ? `` : ''} ${isOptionKind(q.kind) && q.kind !== 'select' ? `` : ''} ${q.required && (q.kind === 'line' || q.kind === 'text') ? `` : ''}
${assetsHtml(q.assets, owner)}
${acceptedHtml(q, qi, isTest)} ${options}
`; } function renderCover() { const el = document.getElementById('qeCover'); const p = state.quiz.cover_path; el.innerHTML = (p ? `Обложка` : '
Без обложки
') + (p ? '' : ''); renderIcons(); } function renderQuestions() { const wrap = document.getElementById('qeQuestions'); if (!state.questions.length) { wrap.innerHTML = '

Вопросов пока нет. Добавьте первый вопрос.

'; return; } wrap.innerHTML = state.questions.map(questionHtml).join(''); renderIcons(); } function renderQuizAssets() { const el = document.querySelector('[data-assets="quiz"]'); if (el) { el.innerHTML = assetsHtml(state.assets, 'quiz'); renderIcons(); } } function renderPreview() { const box = document.getElementById('qeDescPreview'); const btn = document.getElementById('qeDescPreviewBtn'); if (!box) return; if (box.hidden) { btn.textContent = 'Предпросмотр Markdown'; return; } const text = document.getElementById('qeDesc').value; box.innerHTML = text.trim() ? WhatIDoMD.render(text) : 'Пусто'; btn.textContent = 'Скрыть предпросмотр'; } function renderAnon() { const wrap = document.getElementById('qeAnonWrap'); if (!wrap) return; const isSurvey = state.quiz.kind === 'survey'; wrap.hidden = !isSurvey; if (!isSurvey) return; document.getElementById('qeAnonymous').checked = state.quiz.allow_anonymous; const link = document.getElementById('qeAnonLink'); const hint = document.getElementById('qeAnonPublishHint'); const ready = state.quiz.allow_anonymous && state.quiz.is_published; const visible = ready && !dirty; link.hidden = !visible; let text = ''; if (state.quiz.allow_anonymous && !state.quiz.is_published) text = 'Опубликуйте опрос, чтобы ссылка заработала.'; else if (ready && dirty) text = 'Сохраните опрос, чтобы ссылка заработала.'; hint.hidden = !text; hint.textContent = text; if (visible) { const url = location.origin + '/quiz-public.html?id=' + state.quiz.id; document.getElementById('qeAnonUrl').value = url; document.getElementById('qeAnonOpen').href = url; } } function renderSide() { const q = state.quiz; document.getElementById('qeName').value = q.title; document.getElementById('qeDesc').value = q.description; document.getElementById('qePass').value = q.pass_percent; document.getElementById('qeAttempts').value = q.max_attempts; document.getElementById('qeTime').value = q.time_limit_min; document.getElementById('qePublished').checked = q.is_published; document.getElementById('qeShuffleQ').checked = q.shuffle_questions; document.getElementById('qeShuffleO').checked = q.shuffle_options; document.getElementById('qeShowResults').checked = q.show_results; document.querySelectorAll('#qeKindSeg .qe-seg-btn').forEach(b => { b.classList.toggle('on', b.dataset.kind === q.kind); }); document.getElementById('qePassWrap').hidden = q.kind !== 'test'; document.getElementById('qeBarTitle').textContent = q.title || 'Без названия'; document.getElementById('qePreviewBtn').href = 'quiz.html?id=' + q.id; renderCover(); renderQuizAssets(); renderAnon(); } function renderAll() { renderSide(); renderQuestions(); renderPreview(); } async function load() { try { const res = await fetch(API + '/api/quizzes/' + quizId, { headers: hdr() }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.error || 'Не удалось загрузить тест'); if (!data.can_edit) throw new Error('Изменять тест может только автор или администратор'); fromServer(data); clearDirty(); renderAll(); } catch (e) { showToast(e.message, true); document.getElementById('qeQuestions').innerHTML = `

${esc(e.message)}

`; } } async function save() { if (saving) return; const q = state.quiz; if (!q.title.trim()) { showToast('Укажите название теста', true); return; } for (let i = 0; i < state.questions.length; i++) { const item = state.questions[i]; if (!String(item.text || '').trim()) { showToast('Вопрос ' + (i + 1) + ': заполните текст', true); return; } if (isFree(item.kind)) continue; if (item.options.length < 2) { showToast('Вопрос ' + (i + 1) + ': нужно минимум два варианта', true); return; } if (item.options.some(o => !String(o.text || '').trim())) { showToast('Вопрос ' + (i + 1) + ': заполните все варианты', true); return; } if (q.kind === 'test') { const correct = item.options.filter(o => o.is_correct).length; if ((item.kind === 'single' || item.kind === 'select') && correct !== 1) { showToast('Вопрос ' + (i + 1) + ': отметьте ровно один верный ответ', true); return; } if (item.kind === 'multiple' && correct < 1) { showToast('Вопрос ' + (i + 1) + ': отметьте хотя бы один верный ответ', true); return; } } } saving = true; const btn = document.getElementById('qeSaveBtn'); btn.disabled = true; try { const res = await fetch(API + '/api/quizzes/' + quizId, { method: 'PUT', headers: hdrJson(), body: JSON.stringify(payload()), }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.error || 'Не удалось сохранить тест'); fromServer(data); clearDirty(); renderAll(); showToast('Сохранено'); } catch (e) { showToast(e.message, true); } finally { saving = false; btn.disabled = false; } } function pickFile(cb) { const input = document.createElement('input'); input.type = 'file'; input.addEventListener('change', () => { const file = input.files && input.files[0]; if (file) cb(file); }); input.click(); } async function uploadAsset(owner, file) { try { const fd = new FormData(); fd.append('file', file); const res = await fetch(API + '/api/quizzes/assets', { method: 'POST', headers: hdr(), body: fd }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.error || 'Не удалось загрузить файл'); const asset = data.item; if (owner === 'quiz') state.assets.push(asset); else if (owner.startsWith('q:')) state.questions[Number(owner.split(':')[1])].assets.push(asset); else { const parts = owner.split(':'); state.questions[Number(parts[1])].options[Number(parts[2])].assets.push(asset); } markDirty(); renderAll(); showToast('Файл загружен'); } catch (e) { showToast(e.message, true); } } async function deleteAsset(owner, id) { if (!confirm('Удалить файл?')) return; try { const res = await fetch(API + '/api/quizzes/assets/' + id, { method: 'DELETE', headers: hdr() }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.error || 'Не удалось удалить файл'); const strip = list => list.filter(a => Number(a.id) !== Number(id)); if (owner === 'quiz') state.assets = strip(state.assets); else if (owner.startsWith('q:')) { const qi = Number(owner.split(':')[1]); state.questions[qi].assets = strip(state.questions[qi].assets); } else { const parts = owner.split(':'); const qq = state.questions[Number(parts[1])]; qq.options[Number(parts[2])].assets = strip(qq.options[Number(parts[2])].assets); } markDirty(); renderAll(); showToast('Файл удалён'); } catch (e) { showToast(e.message, true); } } async function saveCaption(input) { const id = Number(input.dataset.capAsset); const asset = findAsset(id); if (!asset) return; const caption = input.value.trim(); try { const res = await fetch(API + '/api/quizzes/assets/' + id, { method: 'PUT', headers: hdrJson(), body: JSON.stringify({ caption }), }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.error || 'Не удалось сохранить подпись'); asset.caption = data.item ? data.item.caption : caption; input.value = asset.caption || ''; } catch (e) { input.value = asset.caption || ''; showToast(e.message, true); } } async function uploadCover(file) { try { const fd = new FormData(); fd.append('photo', file); const res = await fetch(API + '/api/quizzes/' + quizId + '/cover', { method: 'POST', headers: hdr(), body: fd }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.error || 'Не удалось загрузить обложку'); state.quiz.cover_path = data.item.path; markDirty(); renderCover(); showToast('Обложка загружена'); } catch (e) { showToast(e.message, true); } } async function deleteCover() { try { const res = await fetch(API + '/api/quizzes/' + quizId + '/cover', { method: 'DELETE', headers: hdr() }); const data = await res.json().catch(() => ({})); if (!res.ok) throw new Error(data.error || 'Не удалось удалить обложку'); state.quiz.cover_path = null; markDirty(); renderCover(); } catch (e) { showToast(e.message, true); } } function onField(e) { const el = e.target; const isChoice = el.tagName === 'SELECT' || el.type === 'checkbox' || el.type === 'radio'; if (isChoice && e.type !== 'change') return; if (!isChoice && e.type !== 'input') return; const role = el.dataset.role; if (role === 'qkind') { const qi = Number(el.dataset.qi); const q = state.questions[qi]; q.kind = normalizeKind(el.value); if (isFree(q.kind)) { q.options = []; } else if (q.options.length < 2) { q.options = [ { id: null, text: '', description: '', is_correct: q.kind !== 'multiple', weight: 1, assets: [] }, { id: null, text: '', description: '', is_correct: false, weight: 1, assets: [] }, ]; } markDirty(); renderQuestions(); renderPreview(); return; } const field = el.dataset.field; if (!field) return; if (el.dataset.oi !== undefined) { const qi = Number(el.closest('[data-qi]').dataset.qi); const oi = Number(el.dataset.oi); const opt = state.questions[qi].options[oi]; if (field === 'is_correct') { opt.is_correct = el.checked; if (opt.is_correct && state.questions[qi].kind === 'single') { state.questions[qi].options.forEach((o, idx) => { if (idx !== oi) o.is_correct = false; }); renderQuestions(); renderPreview(); } } else if (field === 'weight') { opt.weight = el.value === '' ? 0 : Number(el.value); } else { opt[field] = el.value; } markDirty(); return; } if (el.dataset.qi !== undefined) { const qi = Number(el.dataset.qi); const q = state.questions[qi]; if (field === 'weight') q.weight = el.value === '' ? 0 : Number(el.value); else if (field === 'min_length') q.min_length = el.value === '' ? 0 : Math.max(0, Math.min(2000, Math.round(Number(el.value) || 0))); else if (field === 'partial_credit' || field === 'required' || field === 'options_inline') { q[field] = el.checked; if (field === 'required' && (q.kind === 'line' || q.kind === 'text')) { markDirty(); renderQuestions(); return; } } else if (field === 'accepted_raw') { q.accepted_answers = el.value.split('\n').map(s => s.trim()).filter(Boolean).slice(0, 50); } else if (field === 'text_match') { q.text_match = el.value === 'contains' ? 'contains' : 'exact'; } else q[field] = el.value; markDirty(); } } function moveItem(list, from, to) { const [item] = list.splice(from, 1); list.splice(to, 0, item); } function clearDragMarks() { document.querySelectorAll('.qe-dragging').forEach(el => el.classList.remove('qe-dragging')); document.querySelectorAll('.qe-drag-over').forEach(el => el.classList.remove('qe-drag-over')); } function onDragStart(e) { const qHandle = e.target.closest('.qe-drag'); const oHandle = e.target.closest('.qe-opt-drag'); if (qHandle) { const card = qHandle.closest('.qe-q'); dragState = { type: 'question', qi: Number(card.dataset.qi) }; card.classList.add('qe-dragging'); e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/plain', 'question'); return; } if (oHandle) { const opt = oHandle.closest('.qe-opt'); const card = oHandle.closest('[data-qi]'); dragState = { type: 'option', qi: Number(card.dataset.qi), oi: Number(opt.dataset.oi) }; opt.classList.add('qe-dragging'); e.dataTransfer.effectAllowed = 'move'; e.dataTransfer.setData('text/plain', 'option'); } } function onDragOver(e) { if (!dragState) return; const card = e.target.closest('.qe-q'); if (!card) return; if (dragState.type === 'question') { e.preventDefault(); e.dataTransfer.dropEffect = 'move'; document.querySelectorAll('.qe-q.qe-drag-over').forEach(el => el.classList.remove('qe-drag-over')); if (Number(card.dataset.qi) !== dragState.qi) card.classList.add('qe-drag-over'); return; } const opt = e.target.closest('.qe-opt'); if (!opt || Number(card.dataset.qi) !== dragState.qi) return; e.preventDefault(); e.dataTransfer.dropEffect = 'move'; const scope = card.querySelectorAll('.qe-opt.qe-drag-over'); scope.forEach(el => el.classList.remove('qe-drag-over')); if (Number(opt.dataset.oi) !== dragState.oi) opt.classList.add('qe-drag-over'); } function onDrop(e) { if (!dragState) return; const card = e.target.closest('.qe-q'); if (!card) return; e.preventDefault(); if (dragState.type === 'question') { const target = Number(card.dataset.qi); if (target !== dragState.qi) moveItem(state.questions, dragState.qi, target); } else { const opt = e.target.closest('.qe-opt'); if (!opt || Number(card.dataset.qi) !== dragState.qi) { clearDragMarks(); dragState = null; return; } const target = Number(opt.dataset.oi); const opts = state.questions[dragState.qi].options; if (target !== dragState.oi) moveItem(opts, dragState.oi, target); } dragState = null; clearDragMarks(); markDirty(); renderQuestions(); } function onClick(e) { const btn = e.target.closest('[data-act]'); if (!btn) return; const act = btn.dataset.act; if (act === 'add-option') { const qi = Number(btn.dataset.qi); state.questions[qi].options.push({ id: null, text: '', description: '', is_correct: false, weight: 1, assets: [] }); markDirty(); renderAll(); return; } if (act === 'del-option') { const qi = Number(btn.closest('[data-qi]').dataset.qi); const oi = Number(btn.dataset.oi); state.questions[qi].options.splice(oi, 1); markDirty(); renderAll(); return; } if (act === 'del-question') { const qi = Number(btn.dataset.qi); if (!confirm('Удалить вопрос?')) return; state.questions.splice(qi, 1); markDirty(); renderAll(); return; } if (act === 'up' || act === 'down') { const qi = Number(btn.dataset.qi); const target = act === 'up' ? qi - 1 : qi + 1; if (target < 0 || target >= state.questions.length) return; moveItem(state.questions, qi, target); markDirty(); renderAll(); return; } if (act === 'upload') { const owner = btn.dataset.owner; pickFile(file => uploadAsset(owner, file)); return; } if (act === 'del-asset') { deleteAsset(btn.dataset.owner, btn.dataset.asset); return; } if (act === 'del-cover') { deleteCover(); return; } if (act === 'copy-anon') { const input = document.getElementById('qeAnonUrl'); input.select(); const done = () => showToast('Ссылка скопирована'); if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(input.value).then(done, () => { document.execCommand('copy'); done(); }); } else { document.execCommand('copy'); done(); } } } function bind() { document.getElementById('qeName').addEventListener('input', e => { state.quiz.title = e.target.value; document.getElementById('qeBarTitle').textContent = e.target.value || 'Без названия'; markDirty(); }); document.getElementById('qeDesc').addEventListener('input', e => { state.quiz.description = e.target.value; markDirty(); if (!document.getElementById('qeDescPreview').hidden) renderPreview(); }); document.getElementById('qeDescPreviewBtn').addEventListener('click', () => { const box = document.getElementById('qeDescPreview'); box.hidden = !box.hidden; renderPreview(); }); document.getElementById('qePass').addEventListener('input', e => { state.quiz.pass_percent = e.target.value === '' ? '' : Number(e.target.value); markDirty(); }); document.getElementById('qeAttempts').addEventListener('input', e => { state.quiz.max_attempts = e.target.value === '' ? '' : Number(e.target.value); markDirty(); }); document.getElementById('qeTime').addEventListener('input', e => { state.quiz.time_limit_min = e.target.value === '' ? 0 : Number(e.target.value); markDirty(); }); ['qePublished', 'qeShuffleQ', 'qeShuffleO', 'qeShowResults', 'qeAnonymous'].forEach(id => { document.getElementById(id).addEventListener('change', e => { const map = { qePublished: 'is_published', qeShuffleQ: 'shuffle_questions', qeShuffleO: 'shuffle_options', qeShowResults: 'show_results', qeAnonymous: 'allow_anonymous', }; state.quiz[map[id]] = e.target.checked; markDirty(); if (id === 'qePublished' || id === 'qeAnonymous') renderAnon(); }); }); document.getElementById('qeKindSeg').addEventListener('click', e => { const btn = e.target.closest('[data-kind]'); if (!btn) return; if (state.quiz.kind === btn.dataset.kind) return; state.quiz.kind = btn.dataset.kind; if (state.quiz.kind !== 'survey') state.quiz.allow_anonymous = false; markDirty(); renderSide(); renderQuestions(); }); document.getElementById('qeAddQuestion').addEventListener('click', () => { state.questions.push({ id: null, kind: 'single', text: '', description: '', weight: 1, partial_credit: false, required: true, min_length: 0, options_inline: false, text_match: 'exact', accepted_answers: [], assets: [], options: [ { id: null, text: '', description: '', is_correct: true, weight: 1, assets: [] }, { id: null, text: '', description: '', is_correct: false, weight: 1, assets: [] }, ], }); markDirty(); renderAll(); }); document.getElementById('qeSaveBtn').addEventListener('click', save); document.getElementById('qeCoverFile').addEventListener('change', e => { const file = e.target.files && e.target.files[0]; if (file) uploadCover(file); e.target.value = ''; }); document.getElementById('qeAssetFile').addEventListener('change', e => { const file = e.target.files && e.target.files[0]; if (file) uploadAsset('quiz', file); e.target.value = ''; }); const wrap = document.getElementById('qeQuestions'); wrap.addEventListener('dragstart', onDragStart); wrap.addEventListener('dragover', onDragOver); wrap.addEventListener('drop', onDrop); wrap.addEventListener('dragend', () => { dragState = null; clearDragMarks(); }); wrap.addEventListener('change', e => { const cap = e.target.closest('[data-cap-asset]'); if (cap) saveCaption(cap); }); document.addEventListener('input', onField); document.addEventListener('change', onField); document.addEventListener('click', onClick); document.addEventListener('keydown', e => { if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 's') { e.preventDefault(); save(); } }); window.addEventListener('beforeunload', e => { if (!dirty) return; e.preventDefault(); e.returnValue = ''; }); } async function init() { if (!Number.isInteger(quizId) || quizId < 1) { showToast('Неверный адрес теста', true); return; } if (!(await checkAuth())) return; buildSidebar(document.body.dataset.page); bind(); await load(); } init(); })();