您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
按 S 键一键截图,并保存成 PNG 格式
当前为
// ==UserScript== // @name Bilibili 一键截图 // @description 按 S 键一键截图,并保存成 PNG 格式 // @version 0.1.3 // @author Kazurin // @match https://www.bilibili.com/video/* // @match https://www.bilibili.com/bangumi/play/* // @grant none // @namespace https://gf.qytechs.cn/users/699115 // ==/UserScript== 'use strict'; var video, videoTitle, bgmTitle, canvas, ctx, link; function lazyInitialize() { if(!canvas) { video = document.querySelector('.bilibili-player-video video'); videoTitle = document.querySelector('.bilibili-player-video-top-title'); bgmTitle = document.querySelector('.media-title'); canvas = document.createElement('canvas'); ctx = canvas.getContext('2d'); link = document.createElement('a'); link.style.display = 'none'; document.body.appendChild(link); } } function getVideoCurrentTime(video) { var time = Math.round(video.currentTime); var seconds = time % 60; var minutes = (time - seconds) / 60; return minutes + '-' + (seconds < 10 ? '0' : '') + seconds; } function startDownload(uri) { link.href = uri; if(window.location.href.indexOf('/bangumi/') >= 0) { var bgmEpisode = document.querySelector('#eplist_module .ep-item.cursor .ep-title') || document.querySelector('.ep-section-module .ep-item.cursor .ep-title'); if(bgmEpisode) { link.download = bgmTitle.textContent + ' ' + bgmEpisode.textContent + ' ' + getVideoCurrentTime(video) + '.png'; } else { link.download = bgmTitle.textContent + ' ' + getVideoCurrentTime(video) + '.png'; } } else { link.download = videoTitle.textContent + ' ' + getVideoCurrentTime(video) + '.png'; } link.click(); } function downloadScreenshot() { lazyInitialize(); canvas.width = video.videoWidth; canvas.height = video.videoHeight; ctx.drawImage(video, 0, 0, canvas.width, canvas.height); if(typeof(canvas.toBlob) !== 'undefined') { // 如果浏览器支持 canvas.toBlob(),则用 blob URL 下载 canvas.toBlob(function(blob) { startDownload(URL.createObjectURL(blob)); }); } else { // 否则用 data URL 下载 startDownload(canvas.toDataURL()); } } document.addEventListener('keydown', function(e) { if(e.keyCode == 83) { e.preventDefault = true; try { downloadScreenshot(); } catch(e) { console.error('截图失败'); console.error(e); window.alert('截图失败,请重试。如果此问题反复出现,请在 F12 控制台查看错误消息,并向开发者反馈。'); } } });
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址