AO3: [Wrangling] Sort Unwrangled Bin Links by Tag Age

change the Unwrangled bin links on the Wrangling Home page to sort by tag creation date

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         AO3: [Wrangling] Sort Unwrangled Bin Links by Tag Age
// @namespace    https://greasyfork.org/en/users/906106-escctrl
// @description  change the Unwrangled bin links on the Wrangling Home page to sort by tag creation date
// @author       escctrl
// @version      1.2
// @match        *://*.archiveofourown.org/tag_wranglers/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js
// @license      MIT
// ==/UserScript==

// CONFIGURATION OPTION
    // The bins will sort tags by age. Which direction should the bins sort, and on which page do you want to start wrangling?
    //   "oldest first" = old -> new, go to the oldest tags on page 1
    //   "oldest last"  = new -> old, go to the oldest tags on the last page
    //   "newest first" = new -> old, go to the newest tags on page 1
    //   "newest last"  = old -> new, go to the newest tags on the last page
    const url_mode = "newest first";

(function($) {
    'use strict';

    // loop through the unwrangled bins
    $('.assigned tbody tr td[title~="unwrangled"] a').each(function() {

        let link = new URL($(this).prop('href'));
        let params = new URLSearchParams(link.search);

        params.set('sort_column', 'created_at');

        if (url_mode == "oldest first" || url_mode == "newest last") params.set('sort_direction', 'ASC');
        else params.set('sort_direction', 'DESC');

        if (url_mode.includes('first')) params.set('page', '1');
        else params.set('page', Math.ceil(parseInt($(this).text(), 10)/20).toString()); // some math to find the last page in a bin

        // status=X has to be the last parameter in the URL for compatibility with other scripts
        params.delete('status');
        params.append('status', 'unwrangled');

        // create the new URL and set it on the <a>
        link.search = "?" + params.toString();
        $(this).prop('href', link.toString());
    });
})(jQuery);