Sort Faction List by FF Score

Sort faction members by FF Score

  1. // ==UserScript==
  2. // @name Sort Faction List by FF Score
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Sort faction members by FF Score
  6. // @author You
  7. // @match https://www.torn.com/factions.php?step=profile*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function sortMembersByFF() {
  16. const list = document.querySelector('.table-body.tt-modified-ff-scouter');
  17. if (!list) return;
  18.  
  19. let rows = Array.from(list.querySelectorAll('.table-row'));
  20.  
  21. rows.sort((a, b) => {
  22. let ffA = parseFloat(a.getAttribute('data-ff-scout')) || 0;
  23. let ffB = parseFloat(b.getAttribute('data-ff-scout')) || 0;
  24. return ffB - ffA; // Sort descending
  25. });
  26.  
  27. rows.forEach(row => list.appendChild(row));
  28. }
  29.  
  30. function addSortButton() {
  31. const header = document.querySelector('.tt-ff-scouter-faction-list-header');
  32. if (!header) return;
  33.  
  34. const sortButton = document.createElement('div');
  35. sortButton.innerText = '⇅';
  36. sortButton.style.cursor = 'pointer';
  37. sortButton.style.marginLeft = '5px';
  38. sortButton.style.display = 'inline-block';
  39. sortButton.style.fontWeight = 'bold';
  40. sortButton.addEventListener('click', sortMembersByFF);
  41.  
  42. header.appendChild(sortButton);
  43. }
  44.  
  45. function init() {
  46. const observer = new MutationObserver(() => {
  47. if (document.querySelector('.table-body.tt-modified-ff-scouter')) {
  48. addSortButton();
  49. observer.disconnect();
  50. }
  51. });
  52.  
  53. observer.observe(document.body, { childList: true, subtree: true });
  54. }
  55.  
  56. init();
  57. })();