AO3: [Wrangling] Empty Bin links to Previous Page

adds a button to the previous page, if there are no more tags on this page

您需要先安裝使用者腳本管理器擴展,如 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] Empty Bin links to Previous Page
// @namespace    https://greasyfork.org/en/users/906106-escctrl
// @version      1.1
// @description  adds a button to the previous page, if there are no more tags on this page
// @author       escctrl
// @license      MIT
// @match        https://archiveofourown.org/tags/*/wrangle?*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js
// @grant        none
// ==/UserScript==

(function($) {
    'use strict';

    // if there are no tags to be wrangled on this page
    if (!$('#main.wrangle-tags form#wrangulator').length) {

        let search = new URLSearchParams(window.location.search);
        let page = parseInt(search.get('page')) || 0;

        // if we're not on the first page, create a button to jump to the previous page
        if (page > 1) {
            search.set('page', page-1);
            $('.notes')
                .text($('.notes').text().replace(/(.*tags) (in.*)/i, "$1 on page "+page+" $2"))
                .after(`<p><a href="${window.location.pathname}?${search.toString()}" class="action">Go to Page ${page-1}</a></p>`);
        }
    }

})(jQuery);