update_links.js 1.1 KB

1234567891011121314151617181920212223242526
  1. {#- Override sort order to prefer looking at the most recent past first, workaround for https://github.com/Parallels/rq-dashboard/issues/123 -#}
  2. function updateLinks() {
  3. document.querySelectorAll('td.failed a, td.narrow a').forEach(link => {
  4. const href = link.getAttribute('href');
  5. if (href.includes('/canceled/') || href.includes('/failed/') || href.includes('/finished/')) {
  6. const newHref = href.replace('/asc/', '/dsc/');
  7. link.setAttribute('href', newHref);
  8. }
  9. });
  10. }
  11. // Function to check if the table is done loading
  12. function checkTableAndUpdate(mutationsList, observer) {
  13. const loadingRow = document.querySelector('tbody tr');
  14. if (loadingRow && loadingRow.textContent.trim() !== 'Loading...') {
  15. updateLinks();
  16. observer.disconnect(); // Stop observing once the table is updated
  17. }
  18. }
  19. // Monitor the tbody for changes
  20. const observer = new MutationObserver(checkTableAndUpdate);
  21. // Start observing the tbody element for child list changes
  22. const tbody = document.querySelector('tbody');
  23. observer.observe(tbody, { childList: true, subtree: true });