Sort Faction List by FF Score

Sort faction members by FF Score

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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();
})();