AO3: [Wrangling] Edit Tag page cleanup

Removes descriptions and some fields from Edit Tag pages to avoid wrangling accidents

Versione datata 23/06/2022. Vedi la nuova versione l'ultima versione.

// ==UserScript==
// @name         AO3: [Wrangling] Edit Tag page cleanup
// @namespace    https://greatest.deepsurf.us/en/users/906106-escctrl
// @description  Removes descriptions and some fields from Edit Tag pages to avoid wrangling accidents
// @author       escctrl
// @version      3.0
// @match        *://*.archiveofourown.org/tags/*/edit
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @license      MIT
// ==/UserScript==

(function($) {
    'use strict';

    // remove all descriptions to save space. experienced wranglers know them by heart
    $('form#edit_tag dl dd p').not('.actions').hide();

    // what's the status of my tag?
    const canonical = ($('input#tag_canonical').attr("checked") == "checked") ? true : false;
    const unwrangleable = ($('input#tag_unwrangleable').attr("checked") == "checked") ? true : false;
    const synonym = ($('input#tag_syn_string_autocomplete').parent().prev("li.added").length == 1) ? true : false;

    // if the tag is two things at once, something was already incorrect, and we'd rather display all fields again to allow fixing it
    if (canonical && unwrangleable || canonical && synonym || synonym && unwrangleable) { return false; }

    // if the tag is not canonical, remove the metatag field
    if (!canonical) {
        $('dd[title="MetaTags"]').hide();
        $('dd[title="MetaTags"]').prev().hide();
    }

    // if the tag is a canonical or synonym, remove the unwrangleable button
    if (canonical || synonym) {
        $('input#tag_unwrangleable').parent().hide();
        $('input#tag_unwrangleable').parent().prev().hide();

        // and also push up the Edit Canonical button so it uses less space
        $('input#tag_syn_string').siblings('p.actions').css('margin-top', '-3em');
    }

    // if the tag is a synonym or unwrangleable, remove the canonical button
    if (synonym || unwrangleable) {
        $('input#tag_canonical').parent().hide();
        $('input#tag_canonical').parent().prev().hide();
    }

    // if the tag is unwrangleable, also remove the synonym field
    if (unwrangleable) {
        $('input#tag_syn_string').parent().hide();
        $('input#tag_syn_string').parent().prev().hide();
    }

    // remove the Add Subtags and Add Synonyms fields (only shown on canonicals)
    if (canonical) {
        var add_sub = $('dt').filter(function() {
            return $(this).text() == "SubTags";
        });
        if (add_sub.next().children('#child_SubTag_associations_to_remove_checkboxes').length == 0) {
            add_sub.hide();
            add_sub.next().hide();
        }
        else {
            add_sub.next().children('div[title="add tags"],h5.heading').hide();
        }

        var add_syn = $('dt').filter(function() {
            return $(this).text() == "Synonyms";
        });
        if (add_syn.next().children('#child_Merger_associations_to_remove_checkboxes').length == 0) {
            add_syn.hide();
            add_syn.next().hide();
        }
        else {
            add_syn.next().children('div[title="add tags"],h5.heading').hide();
        }

        // also disable the canonical checkbox if there is a metatag (to avoid the filter bug)
        if ($('#parent_MetaTag_associations_to_remove_checkboxes').length == 1) {
            $('input#tag_canonical').attr("disabled", "disabled");
            $('input[name="tag[canonical]"]').attr("disabled", "disabled");
        }
    }

})(jQuery);