Guest User

Untitled

a guest
Apr 16th, 2025
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. function sortPostCells() {
  2. // Get all the postCell elements
  3. const postCells = Array.from(document.querySelectorAll('.postCell'));
  4.  
  5. // Sort the postCells array based on the content of the nested span with class labelId
  6. postCells.sort((a, b) => {
  7. // Use querySelector to find the labelId spans
  8. const aLabelId = a.querySelector('.labelId').textContent.trim();
  9. const bLabelId = b.querySelector('.labelId').textContent.trim();
  10.  
  11. // Compare for sorting
  12. return aLabelId.localeCompare(bLabelId);
  13. });
  14.  
  15. // Append the sorted elements back to the parent container
  16. const parentContainer = postCells[0].parentElement;
  17. postCells.forEach(postCell => parentContainer.appendChild(postCell));
  18. }
  19.  
  20. // Function to add a button next to the refresh button
  21. function addSortButton() {
  22. const refreshButton = document.getElementById('refreshButton');
  23. // Create a new button
  24. const sortButton = document.createElement('input');
  25. sortButton.type = 'button';
  26. sortButton.value = 'JUDGE';
  27. sortButton.id = 'sortButton';
  28.  
  29. // Add an event listener to call sortPostCells on click
  30. sortButton.addEventListener('click', sortPostCells);
  31.  
  32. // Insert the new button after the refresh button
  33. refreshButton.insertAdjacentElement('afterend', sortButton);
  34. }
  35.  
  36. // Add event listener for DOMContentLoaded
  37. document.addEventListener('DOMContentLoaded', (event) => {
  38. addSortButton();
  39. });
Advertisement
Add Comment
Please, Sign In to add comment