(function() { if (window.location.pathname !== '/challenges') return; function injectBoxes(config) { const enabledCategories = config.categories || []; document.querySelectorAll('.category-header').forEach(header => { const catName = header.textContent.trim(); if (enabledCategories.includes(catName) && !header.nextElementSibling.classList.contains('cat-sub-row')) { const row = document.createElement('div'); row.className = "cat-sub-row row mb-4 justify-content-center"; row.innerHTML = `
`; header.after(row); row.querySelector('button').onclick = function() { const btn = this; const container = row.querySelector('.col-md-10'); const input = container.querySelector('input'); const msg = container.querySelector('.status-msg'); const val = input.value.trim(); if (!val) return; btn.disabled = true; msg.innerHTML = 'Checking...'; const params = new URLSearchParams({ submission: val, category: catName, nonce: init.csrfNonce }); fetch('/category_submit', { method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: params }) .then(r => r.json()) .then(data => { if (data.success) { msg.innerHTML = `✔ ${data.message}`; input.value = ''; // Delay reload slightly so the user sees the success message setTimeout(() => { window.location.reload(); }, 1200); } else { msg.innerHTML = `✘ ${data.message}`; btn.disabled = false; } }); }; } }); } fetch('/category_submit/config').then(r => r.json()).then(config => { injectBoxes(config); const observer = new MutationObserver(() => { observer.disconnect(); injectBoxes(config); observer.observe(document.body, { childList: true, subtree: true }); }); observer.observe(document.body, { childList: true, subtree: true }); }); })();