Copy Prompt

danbooru.donmai.us/gelbooru.com/safebooru.org/yande.re/rule34.xxx/furry.booru.org nozomi.la/www.zerochan.net(不支持列表页复制)

Versione datata 26/07/2023. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Copy Prompt
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  danbooru.donmai.us/gelbooru.com/safebooru.org/yande.re/rule34.xxx/furry.booru.org   nozomi.la/www.zerochan.net(不支持列表页复制)
// @author       zuogangju
// @match        *://danbooru.donmai.us/*
// @match        *://gelbooru.com/*
// @match        *://safebooru.org/*
// @match        *://yande.re/*
// @match        *://rule34.xxx/*
// @match        *://furry.booru.org/*
// @match        *://nozomi.la/*
// @match        *://www.zerochan.net/*
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.all.min.js
// @resource     customCSS https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.min.css
// @grant        none
// ==/UserScript==



(function() {
    'use strict';

    // 获取当前页面的URL
    const currentURL = window.location.href;
    var tagsValue
    var content
    var contentImgs
    var myEvent="contextmenu"
    if (currentURL.includes("danbooru.donmai.us")||currentURL.includes("gelbooru.com")) {
        // 获取需要复制的 data-tags 值
        const tag = document.querySelector('[data-tags]');
        if(tag){
            content=document.querySelector('#content,[data-tags]');
            tagsValue=tag.getAttribute('data-tags').replace(/ /g,",")
        }else{
            //列表页处理
            contentImgs=document.querySelectorAll("#content img,.thumbnail-container img")


        }
    } else if (currentURL.includes("safebooru.org")|| currentURL.includes("yande.re")||currentURL.includes("rule34.xxx")||currentURL.includes("furry.booru.org") ) {
        const tag=document.querySelector("#image");
        if(tag){
            content = document.querySelector('.content');
            tagsValue=tag.getAttribute('alt').replace(/ /g,",")
        }else{
            //列表页处理
            contentImgs=document.querySelectorAll(".content img")

        }
    } else if (currentURL.includes("nozomi.la")||currentURL.includes("www.zerochan.net")) { //不支持列表页复制
        const tag=document.querySelector("img.png, img.jpg,#fullsize img,.container img");
        tagsValue=tag.getAttribute('alt')
    } else {
        console.log("This is a page with a different URL.");
        // 在这里可以添加针对其他页面的脚本逻辑
    }
    //详情页复制
    if(content){
        content.addEventListener(myEvent, function(event) {
            event.preventDefault();
            copyPrompt(tagsValue);
        });
    }
    if(contentImgs){
        contentImgs.forEach((contentImg, index) => {
            contentImg.addEventListener(myEvent, function(event) {
                event.preventDefault();
                const tagsValue=contentImg.getAttribute('alt').trim().replace(/ /g,",")
                copyPrompt(tagsValue);
            });
        });
    }




    function copyPrompt(tagsValue){
        // 创建一个用于存储复制内容的临时元素
        const tempDiv = document.createElement('input');
        tempDiv.id = "prompt_999";
        document.body.appendChild(tempDiv);

        // 将 data-tags 值复制到临时元素中
        tempDiv.value = tagsValue;
        console.log(tagsValue)

        // 选中临时元素的内容
        //tempDiv.focus();
        tempDiv.select();
        // 复制选中内容到剪贴板
        document.execCommand('copy');
        // 移除临时元素
        var prompt_999=document.querySelector("#prompt_999")
        if(prompt_999){
            prompt_999.remove();
        }
        Swal.fire({
            //position: 'top-end',
            icon: 'success',
            title: '复制成功',
            showConfirmButton: false,
            timer: 1000
        })

    }

})();