获取并复制指定百度网盘当前页面资源名字

获取所有具有特定类名的a标签的title属性内容并复制到剪贴板

目前為 2025-01-03 提交的版本,檢視 最新版本

// ==UserScript==
// @name         获取并复制指定百度网盘当前页面资源名字
// @namespace    http://tampermonkey.net/
// @version      1.1
// @match        *.pan.baidu.com/*
// @description  获取所有具有特定类名的a标签的title属性内容并复制到剪贴板
// @author       你的名字
// @grant        none
// ==/UserScript==

(function () {
    'use strict';
    // 创建按钮
    const button = document.createElement('button');
    button.textContent = '复制文件名并跳转';
    button.style.position = 'absolute';
    button.style.top = '10px';
    button.style.right = '10px';
    button.style.zIndex = 9999;
    button.style.padding = '10px';
    button.style.backgroundColor = '#00a1d6';
    button.style.color = 'white';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';

    // 按钮点击事件
    button.addEventListener('click', () => {
        // 获取所有 class="mivggPoZ" 的 <a> 标签
        const elements = document.querySelectorAll('a.mivggPoZ');
        const titles = [];
        const links = new Set(); // 使用 Set 去重

        // 正则表达式匹配数字 ID
        const idRegex = /(\d{6,})/;

        // 提取每个 <a> 标签的 title 属性
        elements.forEach(element => {
            if (element.title) {
                const match = element.title.match(idRegex);
                const result = match ? `https://booth.pm/en/items/${match[1]}` : '无';
                titles.push(`${element.title} -> ${result}`);
                if (match) links.add(result); // 添加到 Set 以去重
            }
        });

        // 如果没有找到内容,提示用户
        if (titles.length === 0) {
            alert('未找到任何匹配的title内容!');
            return;
        }

        // 复制结果到剪贴板
        const tempInput = document.createElement('textarea');
        tempInput.value = titles.join('\n'); // 用换行符分隔
        document.body.appendChild(tempInput);
        tempInput.select();
        document.execCommand('copy');
        document.body.removeChild(tempInput);

        // 提示用户
        alert('已复制以下内容到剪贴板:\n' + titles.join('\n'));

        // 逐个打开去重后的链接
        links.forEach(link => {
            window.open(link, '_blank');
        });
    });

    // 添加按钮到页面
    document.body.appendChild(button);
})();



QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址