B站时间戳复制markdown

通过快捷键Alt+⬇️快捷获取B站时间戳并转换为markdown格式复制到剪贴板

// ==UserScript==
// @name        B站时间戳复制markdown
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  通过快捷键Alt+⬇️快捷获取B站时间戳并转换为markdown格式复制到剪贴板
// @author       瀚海阑干
// @match        *://www.bilibili.com/video/*
// @grant        GM_setClipboard
// @grant        GM_notification
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('keydown', function(event) {
        // 检查是否按下 Alt + 下键
        if (event.altKey && event.key === 'ArrowDown') {
            const video = document.querySelector('video');
            if (video) {
                const currentTime = video.currentTime; // 获取当前时间戳
                const formattedTime = formatTime(currentTime); // 格式化时间
                const videoUrl = window.location.href.split('?')[0]; // 获取当前视频的链接并去掉查询参数
                const markdownText = `[${formattedTime}](${videoUrl}?t=${currentTime.toFixed(1)}#t=${formattedTime})`; // 创建Markdown格式文本

                // 复制到剪贴板
                GM_setClipboard(markdownText);

                // 提示复制成功
                GM_notification({
                    title: '复制成功',
                    text: '时间戳已复制到剪贴板!',
                    timeout: 2000
                });
            }
        }
    });

    // 格式化时间为 hh:mm:ss
    function formatTime(seconds) {
        const hrs = Math.floor(seconds / 3600);
        const mins = Math.floor((seconds % 3600) / 60);
        const secs = Math.floor(seconds % 60);
        return `${hrs < 10 ? '0' : ''}${hrs}:${mins < 10 ? '0' : ''}${mins}:${secs < 10 ? '0' : ''}${secs}`;
    }
})();
长期地址
遇到问题?请前往 GitHub 提 Issues,或加Q群1031348184

赞助商

Fishcpy

广告

Rainyun

注册一下就行

Rainyun

一年攒够 12 元