Greasy Fork is available in English.

Bilibili“稍后再看”UID提取

从Bilibili的“稍后再看”列表中提取UID

// ==UserScript==
// @name         Bilibili“稍后再看”UID提取
// @namespace    https://github.com/ayyayyayy2002/BilibiliWatchlaterUIDExtract
// @version      1.0
// @description  从Bilibili的“稍后再看”列表中提取UID
// @author       You
// @match        www.bilibili.com/watchlater/*
// @grant        GM_setClipboard
// @icon         https://i2.hdslb.com/bfs/app/8920e6741fc2808cce5b81bc27abdbda291655d3.png@240w_240h_1c_1s_!web-avatar-space-header.avif
// ==/UserScript==

(function() {
    'use strict';

    // 添加一个按钮来触发操作
    function addButton() {
        var button = document.createElement('button');
        button.innerHTML = '提取并复制UID';
        button.style.position = 'fixed';
        button.style.top = '10px';
        button.style.right = '10px';
        button.style.zIndex = '9999';
        button.addEventListener('click', extractAndCopyUIDs);
        document.body.appendChild(button);
    }

    // 创建一个用于显示消息的通知框
    function showNotification(message) {
        var notification = document.createElement('div');
        notification.innerHTML = message;
        notification.style.position = 'fixed';
        notification.style.top = '50px';
        notification.style.right = '10px';
        notification.style.backgroundColor = '#333';
        notification.style.color = '#fff';
        notification.style.padding = '10px';
        notification.style.borderRadius = '5px';
        notification.style.zIndex = '9999';
        notification.style.opacity = '0.9';
        notification.style.transition = 'opacity 0.5s';

        document.body.appendChild(notification);

        // 设置定时器使通知在几秒后消失
        setTimeout(function() {
            notification.style.opacity = '0';
            setTimeout(function() {
                document.body.removeChild(notification);
            }, 500);
        }, 3000); // 3秒后消失
    }

    // 提取并复制 UID 到剪贴板
    function extractAndCopyUIDs() {
        var regex = /<a href="\/\/space\.bilibili\.com\/(\d+)" class="user">.*?<\/a>/g;
        var matches = document.body.innerHTML.matchAll(regex);

        var uids = [];
        for (const match of matches) {
            if (match && match.length > 1) {
                uids.push(match[1]);
            }
        }

        if (uids.length > 0) {
            var uidString = uids.join("\n");
            GM_setClipboard(uidString);
            showNotification("已复制以下 UID 到剪贴板:\n" + uidString);
        } else {
            showNotification("页面中未找到符合条件的链接");
        }
    }

    addButton(); // 添加按钮到页面

})();