Greasy Fork is available in English.
按下数字0键时,将页面上的所有视频重置到开头
当前为
// ==UserScript==
// @name 按下0键重置视频
// @license MIT
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 按下数字0键时,将页面上的所有视频重置到开头
// @author onionycs
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 监听键盘按下事件
document.addEventListener('keydown', function(event) {
// 检查按下的键是否是数字0(注意:这里不区分大小写,但数字键通常没有大小写)
if (event.key === '0') {
// 获取页面上所有的video标签
const videos = document.querySelectorAll('video');
// 遍历每个video标签,并将其currentTime设置为0
videos.forEach(video => {
if (!video.paused) {
video.currentTime = 0;
video.pause(); // 如果需要,也可以在这里暂停视频
video.play(); // 如果希望视频重置后立即播放,可以调用play()
}
});
}
});
})();