AO3: [Wrangling] Check Unique Tag Users

Adds a button to count unique users in your unfilterable wrangling bins. Based on Check Tag Status script: https://github.com/kaerstyne/ao3-wrangling-scripts

נכון ליום 26-11-2020. ראה הגרסה האחרונה.

// ==UserScript==
// @name         AO3: [Wrangling] Check Unique Tag Users
// @description  Adds a button to count unique users in your unfilterable wrangling bins. Based on Check Tag Status script: https://github.com/kaerstyne/ao3-wrangling-scripts
// @version      0.1

// @author       endofthyme
// @namespace    http://tampermonkey.net/
// @license      GPL-3.0 <https://www.gnu.org/licenses/gpl.html>

// @match        *://*.archiveofourown.org/tags/*/wrangle?*&status=unfilterable
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
// @grant        none
// ==/UserScript==

(function($) {
    // add the button
    var count_users_button = $('<ul class="actions" role="menu"><li><a id="count_users">Count Users</a></li></ul>');
    $("thead").find("th:contains('Taggings')").append(count_users_button);

    // when button is pressed
    $("a[id='count_users']").on("click", function() {

        // check each tag on page
        $("tbody tr").each(function(i, row) {
            var tag_link = $(this).find("a[href$='/works']").attr("href").slice(0, -6);
            var taggings_cell = $(this).find("td[title='taggings']");

            // check the tag's landing page
            $.get(tag_link, function(response) {
                var authors = new Set();
                $(response).find("div.work div.header").each(function(j, row2) {
                    var parsed_author = $(this).find("a[rel$='author']").first().text();
                    var check_pseud = parsed_author.match(/[^(]*\(([^)]*)\)/)
                    if (check_pseud) {
                        parsed_author = check_pseud[1]
                    }
                    if (parsed_author && parsed_author != "orphan_account") {
                        authors.add(parsed_author);
                    }
                });
                if (authors.size > 1) {
                    taggings_cell.append(" (" + authors.size + ")");
                }
            });
        });

        // remove the button when finished
        $("ul").remove(":has(li a[id='count_users'])");
    });
})(jQuery);