Sort Faction List by FF Score

Sort faction members by FF Score

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Sort Faction List by FF Score
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Sort faction members by FF Score
// @author       You
// @match        https://www.torn.com/factions.php?step=profile*
// @grant        none
// @license      MIT 
// ==/UserScript==

(function() {
    'use strict';

    function sortMembersByFF() {
        const list = document.querySelector('.table-body.tt-modified-ff-scouter');
        if (!list) return;

        let rows = Array.from(list.querySelectorAll('.table-row'));

        rows.sort((a, b) => {
            let ffA = parseFloat(a.getAttribute('data-ff-scout')) || 0;
            let ffB = parseFloat(b.getAttribute('data-ff-scout')) || 0;
            return ffB - ffA; // Sort descending
        });

        rows.forEach(row => list.appendChild(row));
    }

    function addSortButton() {
        const header = document.querySelector('.tt-ff-scouter-faction-list-header');
        if (!header) return;

        const sortButton = document.createElement('div');
        sortButton.innerText = '⇅';
        sortButton.style.cursor = 'pointer';
        sortButton.style.marginLeft = '5px';
        sortButton.style.display = 'inline-block';
        sortButton.style.fontWeight = 'bold';
        sortButton.addEventListener('click', sortMembersByFF);

        header.appendChild(sortButton);
    }

    function init() {
        const observer = new MutationObserver(() => {
            if (document.querySelector('.table-body.tt-modified-ff-scouter')) {
                addSortButton();
                observer.disconnect();
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    }

    init();
})();