function sortPostCells() { // Get all the postCell elements const postCells = Array.from(document.querySelectorAll('.postCell')); // Sort the postCells array based on the content of the nested span with class labelId postCells.sort((a, b) => { // Use querySelector to find the labelId spans const aLabelId = a.querySelector('.labelId').textContent.trim(); const bLabelId = b.querySelector('.labelId').textContent.trim(); // Compare for sorting return aLabelId.localeCompare(bLabelId); }); // Append the sorted elements back to the parent container const parentContainer = postCells[0].parentElement; postCells.forEach(postCell => parentContainer.appendChild(postCell)); } // Function to add a button next to the refresh button function addSortButton() { const refreshButton = document.getElementById('refreshButton'); // Create a new button const sortButton = document.createElement('input'); sortButton.type = 'button'; sortButton.value = 'JUDGE'; sortButton.id = 'sortButton'; // Add an event listener to call sortPostCells on click sortButton.addEventListener('click', sortPostCells); // Insert the new button after the refresh button refreshButton.insertAdjacentElement('afterend', sortButton); } // Add event listener for DOMContentLoaded document.addEventListener('DOMContentLoaded', (event) => { addSortButton(); });