Danbooru Copy General Tags

复制Danbooru标签,支持角色特征与非角色特征标签的筛选

// ==UserScript==
// @name         Danbooru Copy General Tags
// @namespace    http://tampermonkey.net/
// @version      1.21
// @author       Sarara
// @description  复制Danbooru标签,支持角色特征与非角色特征标签的筛选
// @match        https://danbooru.donmai.us/posts/*
// @match        https://aibooru.online/posts/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const createCopyButton = (buttonText, filterFunction, topOffset) => {
        const button = document.createElement('button');
        button.innerText = buttonText;
        button.style.position = 'absolute';
        button.style.top = `${topOffset}px`;
        button.style.right = '10px';
        button.style.zIndex = '9999';
        button.style.padding = '10px';
        button.style.backgroundColor = '#28a745';
        button.style.color = '#fff';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';
        button.style.marginRight = '5px';

        const imageContainer = document.querySelector('.image-container');
        if (imageContainer) {
            imageContainer.appendChild(button);
        }

        button.addEventListener('click', async () => {
            setTimeout(() => {
                const tagElements = document.querySelectorAll('.general-tag-list a');
                if (tagElements.length === 0) {
                    alert('未找到标签列表。请确保页面加载完成。');
                    return;
                }

                const tags = Array.from(tagElements).map(tag => tag.innerText.replace(/\?/, '').trim());

                const filteredTags = filterFunction ? tags.filter(filterFunction) : tags;
                const tagString = filteredTags.filter(Boolean).join(', ');

                console.log('复制的标签:', tagString);

                navigator.clipboard.writeText(tagString).then(() => {
                    alert('标签已复制到剪切板: ' + tagString);
                }).catch(err => {
                    alert('复制失败,请手动复制。错误信息: ' + err);
                });
            }, 1000); // 等待1秒以确保内容加载完成
        });

        return button;
    };

    const allTagsFilter = () => true; // 复制所有标签

    const characterFeatures = [
        'hair', 'eye', 'skin', 'clothes', 'clothing', 'outfit', 'costume',
        'long hair', 'short hair', 'black hair', 'blonde hair', 'red hair',
        'dress', 'skirt', 'suit', 'jacket', 'shirt', 'pants', 'tie', 'hoodie',
        'anime', 'girl', 'boy', 'female', 'male', 'hat', 'cap', 'coat', 'sleeves',
        'cute', 'kawaii', 'handsome', 'pretty'
    ];

    const characterTagsFilter = (tag) => characterFeatures.some(feature => tag.includes(feature)); // 角色特征标签
    const nonCharacterTagsFilter = (tag) => characterFeatures.every(feature => !tag.includes(feature)); // 非角色特征标签

    createCopyButton('复制所有标签', allTagsFilter, 10);
    createCopyButton('复制非角色特征标签', nonCharacterTagsFilter, 50);
    createCopyButton('复制角色特征标签', characterTagsFilter, 90);
})();