Copy Prompt

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

当前为 2023-07-26 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Copy Prompt
// @namespace    http://tampermonkey.net/
// @version      1.1.3
// @description  danbooru.donmai.us——gelbooru.com——safebooru.org——yande.re——rule34.xxx——furry.booru.org——nozomi.la——www.zerochan.net(nozomi/zerochan不支持列表页面直接复制)
// @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        GM_setClipboard
// ==/UserScript==


// 获取当前页面的URL
const currentURL = window.location.href;
var tagsValue
var content
var contentImgs
var myEvent="contextmenu"

/*处理多余的Tags和User信息*/
function tagsValueExec(tagsValue) {
    tagsValue=tagsValue.trim().replace("Rule 34 | ","")
    const tagsValueArray = tagsValue.split("Tags:");
    if (tagsValueArray.length > 1) {
        tagsValue = tagsValueArray[1].trim().split("User:")[0]
    }
    if (!tagsValue.includes(",")) {
        tagsValue=tagsValue.replaceAll(" ",",");
    }
    tagsValue= tagsValue.replaceAll(", ",",");
    if (currentURL.includes("gelbooru.com")) {
        tagsValue=tagsValue.replaceAll(" ","_")
    }
    return tagsValue

}
/*复制文本到剪切板并弹出复制成功*/
function copyPrompt(tagsValue){
    console.log(tagsValue)
    // 复制选中内容到剪贴板
    // navigator.clipboard.writeText(tagsValue)
    GM_setClipboard(tagsValue)
    Swal.fire({
        //position: 'top-end',
        icon: 'success',
        title: '复制成功',
        showConfirmButton: false,
        timer: 600
    })
}

(function() {
    'use strict';
    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')
        }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')
            tagsValue = tagsValueExec(tagsValue);
        }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')
        document.body.addEventListener(myEvent, function(event) {
            event.preventDefault();
            tagsValue = tagsValueExec(tagsValue)
            tagsValue=tagsValue.replaceAll(" ","_")
            copyPrompt(tagsValue);
        });
    } else {
        console.log("This is a page with a different URL.");
        // 在这里可以添加针对其他页面的脚本逻辑
    }
    //详情页图片增加监听
    if(content){
        content.addEventListener(myEvent, function(event) {
            event.preventDefault();
            tagsValue=tagsValueExec(tagsValue)
            copyPrompt(tagsValue);
        });
    }
    //列表页图片增加监听
    if(contentImgs){
        contentImgs.forEach((contentImg) => {
            contentImg.addEventListener(myEvent, function(event) {
                event.preventDefault();
                tagsValue=contentImg.getAttribute('alt')
                tagsValue = tagsValueExec(tagsValue);
                copyPrompt(tagsValue);
            });
        });
    }
})();