Customize Website

x
Color Swatches
Theme
Font Size
100%

YouTube AI Quiz Generator

100% FREE

Turn any YouTube video into a captivating quiz in seconds! Customize the format and difficulty, then share, embed, or download as images.

`; const blob = new Blob([html], { type: 'application/vnd.ms-excel;charset=utf-8' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = fileSafe(quizData.quiz_title) + '-qa.xls'; document.body.appendChild(a); a.click(); setTimeout(function () { URL.revokeObjectURL(a.href); a.remove(); }, 1000); } function wrapCanvasText(ctx, text, x, y, maxWidth, lineHeight, maxLines) { const words = String(text || '').split(/\s+/); let line = ''; let lines = []; words.forEach(function (word) { const test = line ? line + ' ' + word : word; if (ctx.measureText(test).width > maxWidth && line) { lines.push(line); line = word; } else { line = test; } }); if (line) lines.push(line); if (maxLines && lines.length > maxLines) { lines = lines.slice(0, maxLines); lines[lines.length - 1] = lines[lines.length - 1].replace(/\s+\S*$/, '') + '...'; } lines.forEach(function (ln, idx) { ctx.fillText(ln, x, y + idx * lineHeight); }); return y + lines.length * lineHeight; } function downloadImagePack() { if (!quizData || !quizData.questions) return; const title = quizData.quiz_title || 'YouTube Quiz'; quizData.questions.forEach(function (q, i) { setTimeout(function () { const canvas = document.createElement('canvas'); canvas.width = 1080; canvas.height = 1080; const ctx = canvas.getContext('2d'); ctx.fillStyle = '#f8fafc'; ctx.fillRect(0, 0, 1080, 1080); ctx.fillStyle = '#4c1d95'; ctx.fillRect(0, 0, 1080, 138); ctx.fillStyle = '#ffffff'; ctx.font = '800 34px Arial, sans-serif'; wrapCanvasText(ctx, title, 70, 60, 940, 42, 2); ctx.fillStyle = '#7c3aed'; ctx.font = '800 26px Arial, sans-serif'; ctx.fillText('Question ' + (i + 1) + ' of ' + quizData.questions.length, 70, 210); ctx.fillStyle = '#0f172a'; ctx.font = '800 48px Arial, sans-serif'; let y = wrapCanvasText(ctx, stripHtml(escapeHtml(q.question).replace(/___/g, '_____')), 70, 285, 940, 62, 7) + 34; ctx.font = '600 32px Arial, sans-serif'; ctx.fillStyle = '#334155'; if (q.type === 'multiple_choice') { (q.options || []).forEach(function (opt, idx) { y = wrapCanvasText(ctx, String.fromCharCode(65 + idx) + '. ' + opt, 92, y, 870, 44, 2) + 18; }); } else if (q.type === 'true_false') { ctx.fillText('True Or False', 92, y); y += 52; } ctx.fillStyle = '#10b981'; ctx.fillRect(70, 845, 940, 4); ctx.font = '800 30px Arial, sans-serif'; ctx.fillText('Answer', 70, 910); ctx.font = '700 38px Arial, sans-serif'; wrapCanvasText(ctx, getCorrectAnswer(q), 70, 965, 940, 48, 2); const a = document.createElement('a'); a.href = canvas.toDataURL('image/png'); a.download = fileSafe(title) + '-question-' + String(i + 1).padStart(2, '0') + '.png'; document.body.appendChild(a); a.click(); a.remove(); }, i * 250); }); } function recordSharedSubmission() { if (!activeShareToken || sharedSubmissionRecorded) return; sharedSubmissionRecorded = true; $.ajax({ type: 'POST', url: ajaxUrl(), data: { action: 'yt_quiz_share_submit', token: activeShareToken } }); } $(document).off('click.ytqshare').on('click.ytqshare', '.ytq-share-btn', function () { createShareLink($(this)); }); $(document).off('click.ytqexcel').on('click.ytqexcel', '.ytq-excel-btn', downloadExcel); $(document).off('click.ytqimages').on('click.ytqimages', '.ytq-images-btn', downloadImagePack); $(document).off('click.ytqedit').on('click.ytqedit', '.ytq-edit-btn', renderQuizEditor); $(document).off('click.ytqdeletequestion').on('click.ytqdeletequestion', '.ytq-delete-question', function () { const index = Number($(this).data('index')); if (!quizData || quizData.questions.length <= 1) { alert('A quiz needs at least one question. Regenerate this question instead.'); return; } quizData.questions.splice(index, 1); resetQuizProgress(); renderQuizEditor(); }); $(document).off('click.ytqregeneratequestion').on('click.ytqregeneratequestion', '.ytq-regenerate-question', function () { regenerateQuestion(Number($(this).data('index')), $(this)); }); $(document).off('click.ytqfinishediting').on('click.ytqfinishediting', '#ytq-finish-editing', function () { resetQuizProgress(); renderQuestion(0); }); function createResultMount() { $('.result-container').remove(); newResultContainer = $('
'); newResultDiv = $('
'); newResultContainer.append(newResultDiv); if ($('.tool-box').length) $('.tool-box').after(newResultContainer); else $('#ytq_html_anchors').after(newResultContainer); } function loadSharedQuiz(token) { activeShareToken = token; generationConfig = null; sharedSubmissionRecorded = false; createResultMount(); $('.tool-box').hide(); newResultDiv.html(createProgressBlock()); startProgress(); $.ajax({ type: 'POST', url: ajaxUrl(), data: { action: 'yt_quiz_share_get', token: token }, success: function (raw) { clearInterval(progressInt); let d; try { d = typeof raw === 'string' ? JSON.parse(raw) : raw; } catch (ex) { showError('Could not load this shared quiz.'); return; } if (!d.success || !d.data || !d.data.quiz) { showError(d.error || 'Share link not found or expired.'); return; } quizData = d.data.quiz; currentQ = 0; score = 0; answers = []; renderQuizShell({ video_id: d.data.video_id, video_title: d.data.video_title, difficulty: d.data.difficulty, source_mode: d.data.source_mode }, true); renderQuestion(0); $('html,body').animate({ scrollTop: newResultDiv.offset().top - 80 }, 300); }, error: function () { clearInterval(progressInt); showError('Could not load this shared quiz. Please try again later.'); } }); } // ── URL preview overlay (retrieve video name + X to clear) ── const ytqUrlInput = $('#form-field-video_url'); function ytqExtractVideoId(url) { const m = url.match(/(?:v=|youtu\.be\/|\/shorts\/|\/embed\/)([a-zA-Z0-9_-]{11})/); return m ? m[1] : (/^[a-zA-Z0-9_-]{11}$/.test(url) ? url : null); } function ytqShowOverlay(label, vid) { $('#youtube-overlay').remove(); const ov = $('
').attr('data-vid', vid); ov.append($('').text(label)).append($('

Tool Comments