Danbooru Tag 提取

Get General tags from Danbooru posts and copy them to clipboard

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Danbooru Tag 提取
// @name:en      Danbooru Tag Crawler
// @namespace    https://danbooru.donmai.us/
// @version      1.01
// @description:zh-cn 一键提取当前图片的General tags并复制到剪贴板
// @description:en Get General tags from Danbooru posts and copy them to clipboard
// @author       LigHT
// @Copyright    2023 LigHT
// @license      MIT
// @match        https://danbooru.donmai.us/*
// @icon         https://www.google.com/s2/favicons?domain=donmai.us
// @grant        GM_setClipboard
// @description Get General tags from Danbooru posts and copy them to clipboard
// ==/UserScript==

(function() {
    'use strict';
    var button = document.createElement("button");
    button.innerHTML = "get tag";
    button.style.position = "fixed";
    button.style.bottom = "1%";
    button.style.right = "1%";
    button.style.zIndex = "9999";
    button.style.opacity = "0.5";
    button.addEventListener("mouseover", function() {
        button.style.opacity = "1";
    });
    button.addEventListener("mouseout", function() {
        button.style.opacity = "0.5";
    });
    document.body.appendChild(button);
    button.addEventListener("click", function() {
        var ul = document.querySelector("ul.general-tag-list");
        if (ul) {
            var lis = ul.querySelectorAll("li[data-tag-name]");
            var tags = [];
            for (var i = 0; i < lis.length; i++) {
                var tag = lis[i].getAttribute("data-tag-name");
                tag = tag.replace(/_/g, ' ');
                tags.push(tag);
            }
            var result = tags.join(",");
            GM_setClipboard(result);
            button.innerHTML = "success";
            setTimeout(function() {
                button.innerHTML = "get tag";
            }, 3000);
        }
    });
})();