AO3: [Wrangling] Random Bin Button!!

because what wrangler doesn't need a lil fun in their lives ;)

目前为 2022-06-04 提交的版本。查看 最新版本

// ==UserScript==
// @name         AO3: [Wrangling] Random Bin Button!!
// @description  because what wrangler doesn't need a lil fun in their lives ;)
// @version      1.0.0

// @author       owlwinter
// @namespace    N/A
// @license      MIT license

// @match        *://*.archiveofourown.org/tag_wranglers/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const array = f => Array.prototype.slice.call(f, 0)

    const unwrangled_label = document.querySelector("#user-page > div.assigned.module > table > thead > tr > th:nth-child(3)");
    const btn = document.createElement("button")
    btn.innerText = "Random bin"
    btn.style.fontSize = "0.627rem"
    btn.style.float = "right"
    unwrangled_label.appendChild(btn)
    let t = 10
    let last = null
    let interval = null;
    let choosing = false;

    btn.addEventListener("click", function(e) {
        if (choosing) {
            return;
        }
        choosing = true;
        t = 10;
        if (interval != null) {
            clearInterval(interval)
        }
        if (last != null) {
            last.style.backgroundColor = ""
        }
        e.preventDefault()
        const l = array(document.getElementsByTagName("td")).filter(o => o.title.indexOf("unwrangled") != -1 && o.children.length > 0)
        const fun = function fun() {
            t = t * 1.4
            if (last != null) {
                last.style.backgroundColor = ""
            }
            last = l[Math.round(Math.random() * (l.length - 1))]
            last.style.backgroundColor = "yellow"
            if (t > 500) {
                //last.style.transition = "all 0.3s linear"
                interval = setInterval(() => {
                    last.style.backgroundColor = last.style.backgroundColor == "lime" ? "yellow" : "lime";
                }, 500);
                choosing = false;
            } else {
                setTimeout(fun, t)
            }
        }
        setTimeout(fun, t);
    });

    // Your code here...
})();