Random Prompt from Related Tags.

Press Ctrl+Y to create a random prompt from the results of Danbooru's RelatedTags and copy it to the clipboard. If you press Alt, it will be 20, if you press Shift, it will be 30, and if you press both Alt and Shift, it will be 50.

当前为 2024-01-13 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Random Prompt from Related Tags.
// @namespace    https://www6.notion.site/dc99953d5f04405c893fba95dace0722
// @version      1
// @description  Press Ctrl+Y to create a random prompt from the results of Danbooru's RelatedTags and copy it to the clipboard. If you press Alt, it will be 20, if you press Shift, it will be 30, and if you press both Alt and Shift, it will be 50.
// @author       SenY
// @match        https://danbooru.donmai.us/related_tag*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=donmai.us
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const generateTags = (tagsLimit) => {
        let tags = document.getElementById("search_query").value.split(" ").map(x => x.trim().replace(/_/g, " "));
        let order = document.getElementById("search_order")
        if(order && order.value){
            order = order.value.toLowerCase();
            while (tags.length < tagsLimit){
                document.querySelectorAll('[href^="/posts?tags="]').forEach(a => {
                    let tr = a.closest("tr");
                    let tag = a.textContent.trim().replace(/_/g, " ");
                    let num = tr.querySelector("."+order+"-column span").textContent.replace("%", "") - 0;
                    let randomNum = Math.floor(Math.random() * 101);
                    if (num > randomNum && tags.length < tagsLimit && !tags.includes(tag) ) {
                        tags.push(tag);
                    }
                })
            }
            console.log(tags.join(", "));
            navigator.clipboard.writeText(tags.join(", "));
        }else{
            alert("Please select any value on Order property.");
        }
    }
    document.addEventListener("keyup", (e) => {
        if (e.ctrlKey && e.code === 'KeyY') {
            if (!e.altKey && !e.shiftKey) {
                generateTags(10);
            } else if (e.altKey && !e.shiftKey) {
                generateTags(20);
            } else if (!e.altKey && e.shiftKey) {
                generateTags(30);
            } else if (e.altKey && e.shiftKey) {
                generateTags(50);
            }
        }
    });
})();