Danbooru Tag Copier

Automatically copy all general tags from danbooru page to your clipboard

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Danbooru Tag Copier
// @namespace    https://greasyfork.org/en/scripts/453443-danbooru-tag-copier
// @version      0.3
// @description  Automatically copy all general tags from danbooru page to your clipboard
// @author       watzon
// @match        https://danbooru.donmai.us/posts/*
// @match        https://booru.allthefallen.moe/posts/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=donmai.us
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const copyEmoji = '📋';

    const artistsHeader = document.querySelectorAll('h3.artist-tag-list')[0]
    const copyrightHeader = document.querySelectorAll('h3.copyright-tag-list')[0]
    const characterHeader = document.querySelectorAll('h3.character-tag-list')[0]
    const generalHeader = document.querySelectorAll('h3.general-tag-list')[0]
    const metaHeader = document.querySelectorAll('h3.meta-tag-list')[0]

    const artistsList = document.querySelectorAll('ul.artist-tag-list > li')
    const copyrightList = document.querySelectorAll('ul.copyright-tag-list > li')
    const characterList = document.querySelectorAll('ul.character-tag-list > li')
    const generalList = document.querySelectorAll('ul.general-tag-list > li')
    const metaList = document.querySelectorAll('ul.meta-tag-list > li')

    const copyTags = (list) => {
        console.log(list);
        const tags = Array.from(list).map((li) => li.getAttribute('data-tag-name'));
        const taglist = tags.join(', ');
        console.log(taglist);

        if (window.clipboardData && window.clipboardData.setData) {
            // Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
            return window.clipboardData.setData("Text", taglist);

        }

        else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
            var textarea = document.createElement("textarea");
            textarea.textContent = taglist;
            textarea.style.position = "fixed"; // Prevent scrolling to bottom of page in Microsoft Edge.
            document.body.appendChild(textarea);
            textarea.select();
            try {
                return document.execCommand("copy"); // Security exception may be thrown by some browsers.
            }
            catch (ex) {
                console.warn("Copy to clipboard failed.", ex);
                return prompt("Copy to clipboard: Ctrl+C, Enter", taglist);
            }
            finally {
                document.body.removeChild(textarea);
            }
        }
    }

    const lists = [
        [artistsHeader, artistsList],
        [copyrightHeader, copyrightList],
        [characterHeader, characterList],
        [generalHeader, generalList],
        [metaHeader, metaList],
    ];

    for (const [header, list] of lists) {
        if (!header || !list) continue;
        const button = document.createElement('button');
        button.onclick = () => copyTags(list);
        button.innerHTML = copyEmoji;
        button.setAttribute('type', 'button');
        button.setAttribute('title', 'Copy tags to clipboard');
        button.style.backgroundColor = 'transparent';
        button.style.border = 'none';
        button.style.padding = '0 4px';
        header.appendChild(button);
    }
})();