Greasy Fork is available in English.

AO3: [Wrangling] Sort Fandoms by Number of Unwrangled Tags

sort the fandoms on your Wrangling Home by their number of unwrangled tags

// ==UserScript==
// @name         AO3: [Wrangling] Sort Fandoms by Number of Unwrangled Tags
// @namespace    https://greasyfork.org/en/users/906106-escctrl
// @version      3.0
// @description  sort the fandoms on your Wrangling Home by their number of unwrangled tags
// @author       escctrl
// @match        https://*.archiveofourown.org/tag_wranglers/*
// @grant        none
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js
// @license      MIT
// ==/UserScript==

(function($) {
    'use strict';

    // set this to true if you want the page to automatically sort fandoms by the total number of unwrangled tags
    const AUTO_SORT_BY_TOTAL = false;

    // for each (visible) line sum up the total unwrangleds
    $('.assigned table tbody tr').each( function() {
        let uws = 0;
        $(this).find('td[title*="unwrangled"] a').each( function() {
            uws += parseInt(this.innerText.match(/\d+/)[0]);
        });
        $(this).find('th').append(`<span class="uwtotal" style="display: none;">${uws}</span>`);
    });

    // keep a copy of the original order so we don't have to worry about which letter the fandom actually sorts by (e.g. ignoring "The")
    let fandoms_orig = $('.assigned table tbody tr');

    // build a button for sorting (by total unwrangleds, by fandom name)
    // filters are complicated to ensure that we'll only turn the heading text into a link, no matter what stuff other scripts add to the headings
    let href = 'href="javascript:void(0)"';
    let headings0 = $('.assigned table thead tr:nth-child(1) th');
    let headings1 = $('.assigned table thead tr:nth-child(2) th');
    $(headings0).eq(0).contents().filter(function() { return this.nodeType === 3 && this.textContent == "Fandom"; }).wrap(`<a id="sortname" title="Sort fandoms alphabetically" ${href}></a>`);
    $(headings0).eq(2).contents().filter(function() { return this.nodeType === 3 && this.textContent == "Unwrangled"; }).wrap(`<a id="sortunwrangled" title="Sort by total number of unwrangled tags" ${href}></a>`);
    $(headings1).eq(3).contents().filter(function() { return this.nodeType === 3 && this.textContent == "Characters"; }).wrap(`<a id="sortchars" title="Sort by number of unwrangled character tags" ${href}></a>`);
    $(headings1).eq(4).contents().filter(function() { return this.nodeType === 3 && this.textContent == "Relationships"; }).wrap(`<a id="sortrels" title="Sort by number of unwrangled relationship tags" ${href}></a>`);
    $(headings1).eq(5).contents().filter(function() { return this.nodeType === 3 && this.textContent == "Freeforms"; }).wrap(`<a id="sortff" title="Sort by number of unwrangled freeform tags" ${href}></a>`);

    // add event triggers
    $('#sortname').on("click", resortByName);
    $('#sortunwrangled, #sortchars, #sortrels, #sortff').on("click", resortByColumn);

    if (AUTO_SORT_BY_TOTAL) $('#sortunwrangled').trigger('click');

    function resortByColumn(e) {
        // define the column to sort by => the selector of where we retrieve the sort number from
        let column = e.target.id == "sortunwrangled" ? ':nth-child(1) .uwtotal' : // total UW
                     e.target.id == "sortchars" ? ':nth-child(5) a' : // UW chars
                     e.target.id == "sortrels" ? ':nth-child(6) a' : // UW rels
                     ':nth-child(7) a'; // UW freeforms

        let fandoms = $('.assigned table tbody tr').toArray();

        // sort them by order (most UWs to least)
        fandoms.sort(function(a, b) {
            let uw_a = $(a).find(column).text() || "0";
                uw_a = parseInt(uw_a.match(/\d+/)[0]);
            let uw_b = $(b).find(column).text() || "0";
                uw_b = parseInt(uw_b.match(/\d+/)[0]);
            return uw_b-uw_a;
        });

        // remove current content/order and insert the new sorted order instead
        $('.assigned table tbody tr').remove();
        $('.assigned table tbody').append(fandoms);
    }

    function resortByName(e) {
        // remove the current content/order and insert the original order instead
        $('.assigned table tbody tr').remove();
        $('.assigned table tbody').append(fandoms_orig);
    }

})(jQuery);