抖音收藏夹内容复制

用来将抖音收藏夹中视频的id name复制到剪切板中

// ==UserScript==
// @name         抖音收藏夹内容复制
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  用来将抖音收藏夹中视频的id name复制到剪切板中
// @author       Cyrus
// @match        https://www.douyin.com/*
// @icon         https://www.google.com/s2/favicons?domain=douyin.com
// @grant        none
// @license     MIT
// ==/UserScript==

(function () {
    'use strict';

    document.body.addEventListener('keydown', function (e) {
        if (e.shiftKey && e.code == 'KeyS') {
            e.preventDefault();

            let output = '';
            document.querySelectorAll('.h0CXDpkg').forEach(x => {
                const href = x.href;
                const alt = x.querySelector('img') ? x.querySelector('img').alt : '';
                output += `${href} ${alt}\n`;
            });

            // 使用现代的 navigator.clipboard API
            navigator.clipboard.writeText(output).then(() => {
                alert('内容已复制到剪切板');
            }).catch(err => {
                alert('复制到剪切板失败:', err);
            });
        }
    });
})();