Update JS file name and path and HTML template file name

This commit is contained in:
2026-01-05 21:48:12 +00:00
parent ab12e4b5a5
commit 95bcf56cd4
3 changed files with 3 additions and 3 deletions

41
assets/category_submit.js Normal file
View File

@@ -0,0 +1,41 @@
document.addEventListener('DOMContentLoaded', function() {
if (window.location.pathname !== '/challenges') return;
fetch('/category_submit/config')
.then(r => r.json())
.then(config => {
if (!config.categories) return;
function inject() {
document.querySelectorAll('.category-header').forEach(header => {
const catName = header.textContent.trim();
if (config.categories.includes(catName) && !header.querySelector('.custom-box')) {
const div = document.createElement('div');
div.className = "custom-box input-group mt-2 mb-4 p-2 bg-light border rounded";
div.innerHTML = `
<input type="text" class="form-control" placeholder="Found a flag for ${catName}?" id="in-${catName}">
<div class="input-group-append"><button class="btn btn-success btn-sub" data-cat="${catName}">Submit</button></div>
`;
header.after(div);
div.querySelector('button').onclick = function() {
const btn = this;
const val = document.getElementById(`in-${catName}`).value;
btn.disabled = true;
const body = new URLSearchParams({ submission: val, category: catName, nonce: init.csrfNonce });
fetch('/category_submit', { method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: body })
.then(r => r.json())
.then(data => {
alert(data.message);
if(data.success) location.reload();
btn.disabled = false;
});
};
}
});
}
// Watch for CTFd's dynamic challenge loading
new MutationObserver(inject).observe(document.body, { childList: true, subtree: true });
});
});