Danbooru Tag Extractor

Extract tags from Danbooru image pages and copy them to the clipboard when a button is clicked.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Danbooru Tag Extractor
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Extract tags from Danbooru image pages and copy them to the clipboard when a button is clicked.
// @author       Shinnpuru
// @match        https://danbooru.donmai.us/posts/*
// @grant        GM_setClipboard
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function extractTags() {
        // Select all tag links within the tag list section
        let tagElements = document.querySelectorAll('#tag-list a.search-tag');

        // Extract the text content of each tag
        let tags = [];
        tagElements.forEach(function(tagElement) {
            tags.push(tagElement.textContent.trim());
        });

        // Join the tags into a string separated by spaces
        return tags.join(',');
    }

    function createCopyButton() {
        // Create the button element
        let button = document.createElement('button');
        button.innerText = 'Copy Tags';
        button.style.position = 'fixed';
        button.style.bottom = '10px';
        button.style.right = '10px';
        button.style.padding = '10px';
        button.style.backgroundColor = '#008CBA';
        button.style.color = 'white';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';
        button.style.zIndex = '9999';

        // Add click event listener to the button
        button.addEventListener('click', function() {
            let tags = extractTags();
            GM_setClipboard(tags);
            alert('Tags copied to clipboard!');
        });

        // Append the button to the body
        document.body.appendChild(button);
    }

    // Run the script when the page is fully loaded
    window.addEventListener('load', createCopyButton);

})();