Sort Faction List by FF Score

Sort faction members by FF Score

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 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();
})();