// SPDX-FileCopyrightText: 2026 Dennis Fink // // SPDX-License-Identifier: BSD-3-Clause document.addEventListener("DOMContentLoaded", () => { const checkboxes = Array.from(document.querySelectorAll(".received-select")); const selectAll = document.getElementById("received-select-all"); const bulkButtons = document.querySelectorAll("[data-received-bulk-action]"); const count = document.getElementById("received-selected-count"); const modal = document.getElementById("confirmation-modal"); const selected = () => checkboxes.filter((checkbox) => checkbox.checked); const updateSelection = () => { const selectedCount = selected().length; if (count !== null) { count.textContent = `${selectedCount} selected`; } bulkButtons.forEach((button) => { button.disabled = selectedCount === 0; }); if (selectAll !== null) { selectAll.checked = selectedCount === checkboxes.length; selectAll.indeterminate = selectedCount > 0 && selectedCount < checkboxes.length; } }; selectAll?.addEventListener("change", () => { checkboxes.forEach((checkbox) => { checkbox.checked = selectAll.checked; }); updateSelection(); }); checkboxes.forEach((checkbox) => { checkbox.addEventListener("change", updateSelection); }); modal?.addEventListener("show.bs.modal", (event) => { const form = modal.querySelector("#confirmation-modal-form"); // Never carry a previous bulk selection into an unrelated confirmation. form.querySelectorAll('input[name="webmention_uuids"]').forEach((input) => { input.remove(); }); if (!event.relatedTarget?.dataset.receivedBulkAction) { return; } const selection = selected(); const message = modal.querySelector("#confirmation-modal-message"); const action = event.relatedTarget.dataset.receivedBulkAction; if (action === "delete") { message.textContent = `This permanently deletes ${selection.length} selected webmentions and cannot be undone.`; } else if (action === "block-sources") { message.textContent = `Source domains from ${selection.length} selected webmentions (and their subdomains) will be blocked. Existing webmentions will be kept.`; } else { message.textContent = `${selection.length} selected webmentions will be fetched and verified again.`; } selection.forEach((checkbox) => { const input = document.createElement("input"); input.type = "hidden"; input.name = "webmention_uuids"; input.value = checkbox.value; form.appendChild(input); }); }); updateSelection(); });