Greasy Fork

来自缓存

Greasy Fork is available in English.

视频截图

使用Shift+S快捷键截取视频截图

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         视频截图
// @namespace    http://your-namespace.example.com
// @version      1.1
// @description  使用Shift+S快捷键截取视频截图
// @author       Your Name
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    document.addEventListener('keydown', function (e) {
        if (e.shiftKey && e.key === 'S') {
            e.preventDefault();
            captureVideoScreenshot();
        }
    });

    function captureVideoScreenshot() {
        const videoElements = document.querySelectorAll('video');
        if (videoElements.length === 0) {
            console.log('没有找到视频元素。');
            return;
        }

        const video = videoElements[0]; // 获取第一个视频元素
        const canvas = document.createElement('canvas');
        const context = canvas.getContext('2d');

        canvas.width = video.videoWidth;
        canvas.height = video.videoHeight;

        context.drawImage(video, 0, 0, canvas.width, canvas.height);

        const currentDate = new Date();
        const dateStr = currentDate.toISOString().slice(0, 10);
        const timeStr = currentDate.toTimeString().split(' ')[0].replace(/:/g, '-');

        let filename = 'screenshot';

        // 获取视频标题
        const videoTitleElement = document.querySelector('title');
        if (videoTitleElement) {
            filename = videoTitleElement.textContent.trim();
        }

        filename += '_' + dateStr + '_' + timeStr + '.png';

        const screenshotDataUrl = canvas.toDataURL('image/png');

        // 创建一个下载链接
        const a = document.createElement('a');
        a.href = screenshotDataUrl;
        a.download = filename;
        a.click();

        console.log('截图已保存。');
    }
})();