Danbooru Tags Extractor

Generate comma-separated tags from danbooru tags. Useful for image generations.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Danbooru Tags Extractor
// @namespace    https://ns.imgg.dev/userscripts/danbooru-tags-extractor
// @version      0.1
// @description  Generate comma-separated tags from danbooru tags. Useful for image generations.
// @author       You
// @match        https://danbooru.donmai.us/posts/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=donmai.us
// @grant        none
// @license MIT
// ==/UserScript==

function extract() {
    const tags = [
        { category: "general", tags: Array.from(document.querySelector('ul.general-tag-list').querySelectorAll('a.search-tag')).map(el => el.innerText) },
        { category: "copyright", tags: document.querySelector('ul.copyright-tag-list') ? Array.from(document.querySelector('ul.copyright-tag-list').querySelectorAll('a.search-tag')).map(el => el.innerText) : [] },
        { category: "character", tags: document.querySelector('ul.character-tag-list') ? Array.from(document.querySelector('ul.character-tag-list').querySelectorAll('a.search-tag')).map(el => el.innerText) : [] },
        { category: "ip", tags: Array.from(document.querySelector('ul.copyright-tag-list').querySelectorAll('a.search-tag')).map(el => el.innerText) },
        { category: "meta", tags: Array.from(document.querySelector('ul.meta-tag-list').querySelectorAll('a.search-tag')).map(el => el.innerText) }
    ]

    return tags
}

(function() {
    'use strict';

    const text = extract().flatMap(el => el.tags).map(el => el.replace("(", "\\(").replace(")", "\\)")).join(', ')

    const content = document.querySelector('#content')

    const notice = document.createElement('div')
    notice.className = "notice notice-small post-notice post-notice-resized"
    notice.style.background = "var(--note-highlight-color)";
    notice.style.display = "flex";
    notice.style.flexDirection = "column";

    notice.innerHTML = `<div style="display:flex;gap:0.5rem;align-items:center"><h6>Extracted Prompt</h6><button onclick="navigator.clipboard.writeText('${text}');this.innerText='Copied';this.style.background='var(--green-3)'">Copy</button></div><textarea readonly rows="4">${text}</textarea>`

    content.prepend(notice)
})();