Tech, Coding & AI

✕
🎁

₦
' + '

' + escHtml(titleTxt) + '

' + (accTxt ? '
Score: ' + escHtml(accTxt) + '
' : '') + cardsHtml + ''; var iframe = document.createElement('iframe'); iframe.style.position = 'fixed'; iframe.style.width = '0'; iframe.style.height = '0'; iframe.style.border = '0'; document.body.appendChild(iframe); var win = iframe.contentWindow; var doc = win.document; doc.open(); doc.write(docHtml); doc.close(); setTimeout(function() { win.focus(); win.print(); setTimeout(function() { if (iframe.parentNode) iframe.parentNode.removeChild(iframe); }, 1500); }, 180); } // Safely intercept fetch() responses from Newsfeed_Feed_Quiz_Addon if (window.fetch && !window.__nqzfdFetchPatched) { window.__nqzfdFetchPatched = true; var origFetch = window.fetch; window.fetch = function(input, init) { var actionName = ''; if (init && init.body && typeof init.body.get === 'function') { actionName = init.body.get('action') || ''; } var promise = origFetch.apply(this, arguments); if ( actionName === 'nqzf_submit_answer' || actionName === 'nqzf_submit_contest' || actionName === 'nqzf_spectate_reveal' ) { promise.then(function(res) { return res.clone().json(); }).then(function(payload) { if (!payload || !payload.success || !payload.data || !payload.data.post_id) return; var d = payload.data; var quizBox = document.getElementById('nqzf-quiz-' + d.post_id); if (!quizBox) return; setTimeout(function() { var qCount = parseInt(quizBox.getAttribute('data-q-count') || '1', 10); if (d.reveal_correct) { var items = buildItemsFromAjaxPayload(quizBox, d); upsertDropdownIntoQuizBox(quizBox, true, qCount, items); } else { fetchServerDetails(quizBox); } }, 60); }).catch(function() {}); } return promise; }; } document.addEventListener('click', function(e) { // 1. Toggle Outer Details Dropdown var trigger = e.target.closest('.nqzfd-details-trigger'); if (trigger) { e.stopPropagation(); var box = trigger.closest('.nqzfd-details-dropdown'); var body = box ? box.querySelector('.nqzfd-details-body') : null; if (!box || !body) return; var isOpen = box.classList.toggle('open'); body.style.display = isOpen ? 'block' : 'none'; trigger.setAttribute('aria-expanded', isOpen ? 'true' : 'false'); return; } // 2. All / Missed Only / Source Insights Filter Pill var filterPill = e.target.closest('.nqzfd-filter-pill'); if (filterPill) { e.stopPropagation(); var box = filterPill.closest('.nqzfd-details-dropdown'); var filterType = filterPill.getAttribute('data-filter') || 'all'; if (!box) return; box.querySelectorAll('.nqzfd-filter-pill').forEach(function(p) { p.classList.toggle('active', p === filterPill); }); var visibleCards = 0; box.querySelectorAll('.nqzfd-item-card').forEach(function(card) { var show = true; if (filterType === 'missed') { show = (card.getAttribute('data-missed') === '1'); } else if (filterType === 'insights') { show = (card.getAttribute('data-insight') === '1'); } card.style.display = show ? 'flex' : 'none'; if (show) visibleCards++; }); var emptyEl = box.querySelector('.nqzfd-filter-empty'); if (emptyEl) { if (visibleCards === 0 && filterType === 'missed') { emptyEl.innerText = '🎉 Great job — zero missed questions to review!'; emptyEl.style.display = 'block'; } else if (visibleCards === 0 && filterType === 'insights') { emptyEl.innerText = 'No source quote insights were included in this quiz.'; emptyEl.style.display = 'block'; } else { emptyEl.style.display = 'none'; } } return; } // 3. Collapse / Expand All Question Cards Button var toggleAllBtn = e.target.closest('.nqzfd-toggle-all-btn'); if (toggleAllBtn) { e.stopPropagation(); var box = toggleAllBtn.closest('.nqzfd-details-dropdown'); if (!box) return; var currentlyExpanded = toggleAllBtn.getAttribute('data-state') !== 'collapsed'; var nextState = currentlyExpanded ? 'collapsed' : 'expanded'; toggleAllBtn.setAttribute('data-state', nextState); var lbl = toggleAllBtn.querySelector('.nqzfd-toggle-all-lbl'); if (lbl) { lbl.innerText = (nextState === 'collapsed') ? 'Expand All' : 'Collapse All'; } box.querySelectorAll('.nqzfd-item-card').forEach(function(card) { card.classList.toggle('is-card-collapsed', nextState === 'collapsed'); }); return; } // 4. Individual Question Card Header Toggle var itemHead = e.target.closest('.nqzfd-item-head'); if (itemHead) { e.stopPropagation(); var card = itemHead.closest('.nqzfd-item-card'); if (card) card.classList.toggle('is-card-collapsed'); return; } // 5. Copy Study Notes var copyBtn = e.target.closest('.nqzfd-copy-btn'); if (copyBtn) { e.stopPropagation(); var box = copyBtn.closest('.nqzfd-details-dropdown'); if (!box) return; var notes = buildPlainTextStudyNotes(box); copyTextToClipboard(notes).then(function() { var lbl = copyBtn.querySelector('.nqzfd-copy-label'); copyBtn.classList.add('is-copied'); if (lbl) lbl.innerText = 'Copied ✓'; setTimeout(function() { copyBtn.classList.remove('is-copied'); if (lbl) lbl.innerText = 'Copy Notes'; }, 2000); }); return; } // 6. Download Study Sheet (.txt) var dlBtn = e.target.closest('.nqzfd-download-btn'); if (dlBtn) { e.stopPropagation(); var box = dlBtn.closest('.nqzfd-details-dropdown'); if (box) downloadStudyNotesTxt(box); return; } // 7. Print Study Sheet var prBtn = e.target.closest('.nqzfd-print-btn'); if (prBtn) { e.stopPropagation(); var box = prBtn.closest('.nqzfd-details-dropdown'); if (box) printStudySheet(box); return; } }); document.addEventListener('keydown', function(e) { if (e.key !== 'Enter' && e.key !== ' ') return; var t = e.target.closest('.nqzfd-details-trigger, .nqzfd-filter-pill, .nqzfd-toggle-all-btn, .nqzfd-item-head, .nqzfd-copy-btn, .nqzfd-download-btn, .nqzfd-print-btn'); if (!t) return; e.preventDefault(); e.stopPropagation(); t.click(); }); function initDetailsObserver() { scanAllFeedQuizBoxes(); var stream = document.getElementById('nfp-feed-stream') || document.body; if (stream && window.MutationObserver) { var obs = new MutationObserver(function(mutations) { var hasNew = mutations.some(function(m) { return m.addedNodes && m.addedNodes.length > 0; }); if (hasNew) { scanAllFeedQuizBoxes(); } }); obs.observe(stream, { childList: true, subtree: true }); } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initDetailsObserver); } else { initDetailsObserver(); } })();