Greasy Fork

Greasy Fork is available in English.

抖音视频提取器(简洁版)

提取抖音用户喜欢、收藏、作品、所有视频链接,并添加复制所有链接的悬浮按钮

当前为 2024-11-30 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         抖音视频提取器(简洁版)
// @namespace    http://tampermonkey.net/
// @version      1.0.5
// @description  提取抖音用户喜欢、收藏、作品、所有视频链接,并添加复制所有链接的悬浮按钮
// @author       qqlcx5
// @match        https://www.douyin.com/user/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=douyin.com
// @grant        GM_setClipboard
// @run-at       document-end
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    /**
     * 存储提取到的视频链接
     * Stores the extracted video links
     */
    let videoLinks = [];

    /**
     * 提取用户主页中的所有视频链接
     * Extracts all video links from the user's profile page
     */
    function extractVideoLinks() {
        // 定义需要提取链接的节点选择器
        const selectors = [
            'div[data-e2e="user-post-list"]',
            'div[data-e2e="user-like-list"]'
        ];
        const videoListContainer = document.querySelector(selectors);
        
        if (!videoListContainer) {
            console.warn('未找到视频列表元素 (Video list container not found)');
            return;
        }

        // 选择所有以 "/video/" 开头的链接
        // Select all links starting with "/video/"
        const videoAnchorElements = videoListContainer.querySelectorAll('a[href^="/video/"]');
        videoLinks = Array.from(videoAnchorElements).map(anchor => anchor.href);

        console.info(`提取到 ${videoLinks.length} 个视频链接。`);
    }

    /**
     * 复制所有视频链接到剪贴板
     * Copies all video links to the clipboard
     */
    function copyAllVideoLinks() {
        extractVideoLinks();

        if (videoLinks.length === 0) {
            alert('未提取到视频链接,请确保页面已完全加载后重试。');
            return;
        }

        GM_setClipboard(videoLinks.join('\n'));
        notifyUser(`已复制 ${videoLinks.length} 个视频链接到剪贴板。`);
    }

    /**
     * 创建并添加悬浮复制按钮到页面
     * Creates and adds a floating copy button to the page
     */
    function createFloatingCopyButton() {
        const button = document.createElement('button');
        button.id = 'copy-video-links-btn';
        button.textContent = '复制所有视频链接';
        
        // 样式设计 (Styling)
        Object.assign(button.style, {
            position: 'fixed',
            right: '20px',
            bottom: '50px',
            padding: '12px 20px',
            backgroundColor: '#FF4D4F',
            color: '#fff',
            border: 'none',
            borderRadius: '8px',
            boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)',
            cursor: 'pointer',
            fontSize: '14px',
            zIndex: '10000',
            transition: 'background-color 0.3s, transform 0.3s',
        });

        // 鼠标悬停效果 (Hover Effects)
        button.addEventListener('mouseenter', () => {
            button.style.backgroundColor = '#FF7875';
            button.style.transform = 'scale(1.05)';
        });

        button.addEventListener('mouseleave', () => {
            button.style.backgroundColor = '#FF4D4F';
            button.style.transform = 'scale(1)';
        });

        // 点击事件 (Click Event)
        button.addEventListener('click', copyAllVideoLinks);

        // 添加按钮到页面主体 (Append button to the body)
        document.body.appendChild(button);
    }

    /**
     * 显示提示通知给用户
     * Displays a notification to the user
     * @param {string} message - 要显示的消息 (Message to display)
     */
    function notifyUser(message) {
        // 创建通知元素
        const notification = document.createElement('div');
        notification.textContent = message;

        // 样式设计 (Styling)
        Object.assign(notification.style, {
            position: 'fixed',
            bottom: '80px',
            right: '20px',
            backgroundColor: '#333',
            color: '#fff',
            padding: '10px 15px',
            borderRadius: '5px',
            opacity: '0',
            transition: 'opacity 0.5s',
            zIndex: '10000',
            fontSize: '13px',
        });

        document.body.appendChild(notification);

        // 触发动画
        setTimeout(() => {
            notification.style.opacity = '1';
        }, 100); // Slight delay to allow transition

        // 自动淡出和移除
        setTimeout(() => {
            notification.style.opacity = '0';
            setTimeout(() => {
                document.body.removeChild(notification);
            }, 500); // 等待淡出完成
        }, 3000); // 显示3秒
    }

    /**
     * 初始化脚本
     * Initializes the userscript
     */
    function initializeScript() {
        createFloatingCopyButton();
        console.info('抖音视频链接提取器已启用。');
    }

    // 等待页面内容加载完毕后初始化脚本
    // Wait for the DOM to be fully loaded before initializing
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        initializeScript();
    } else {
        document.addEventListener('DOMContentLoaded', initializeScript);
    }

})();