From 03d5da76d0a3226bc24f483c52a8aba2d4ae2c76 Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Mon, 5 Jan 2026 22:14:44 +0000 Subject: [PATCH] Update theming --- assets/category_submit.js | 48 ++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/assets/category_submit.js b/assets/category_submit.js index ea699ff..9ecdb2b 100644 --- a/assets/category_submit.js +++ b/assets/category_submit.js @@ -3,32 +3,38 @@ function injectSubmissionBoxes(config) { const enabledCategories = config.categories || []; - // Find all category headers const headers = document.querySelectorAll('.category-header'); headers.forEach(header => { const catName = header.textContent.trim(); - - // 1. Check if category is enabled - // 2. Check if we already injected a box (to prevent infinite loops) const alreadyInjected = header.nextElementSibling && - header.nextElementSibling.classList.contains('custom-cat-sub-box'); + header.nextElementSibling.classList.contains('cat-sub-row'); if (enabledCategories.includes(catName) && !alreadyInjected) { - const div = document.createElement('div'); - div.className = "custom-cat-sub-box input-group mt-2 mb-4 p-3 bg-light border rounded"; - div.style.maxWidth = "500px"; // Keep it tidy - div.innerHTML = ` - -
- + // Create a row container to match CTFd's grid layout + const row = document.createElement('div'); + row.className = "cat-sub-row row mb-4 justify-content-center"; + + // Use col-md-8 or 10 to keep the box from being too wide + row.innerHTML = ` +
+
+ +
+ +
+
`; - header.after(div); + header.after(row); - // Submission logic - div.querySelector('button').onclick = function() { + row.querySelector('button').onclick = function() { const btn = this; const input = document.getElementById(`in-${catName.replace(/\s+/g, '-')}`); const val = input.value.trim(); @@ -50,9 +56,7 @@ .then(r => r.json()) .then(data => { alert(data.message); - if (data.success) { - location.reload(); // Refresh to show the checkmark on the challenge - } + if (data.success) location.reload(); btn.disabled = false; }) .catch(() => { @@ -64,27 +68,19 @@ }); } - // Initialize the plugin fetch('/category_submit/config') .then(r => r.json()) .then(config => { - // Run once on load injectSubmissionBoxes(config); - - // Observe the challenge board for changes (e.g. category filtering/loading) - // We use a debounce timer to avoid the "Loading Forever" infinite loop let timeout; const observer = new MutationObserver(() => { clearTimeout(timeout); timeout = setTimeout(() => { - // Temporarily disconnect to avoid observing our own changes observer.disconnect(); injectSubmissionBoxes(config); - // Re-observe after injection observer.observe(document.body, { childList: true, subtree: true }); }, 200); }); - observer.observe(document.body, { childList: true, subtree: true }); }) .catch(err => console.error("Could not load category submission config", err));