Greasy Fork

Greasy Fork is available in English.

按下0键重置视频

按下数字0键时,将页面上的所有视频重置到开头

当前为 2024-08-03 提交的版本,查看 最新版本

// ==UserScript==  
// @name         按下0键重置视频  
// @namespace    http://tampermonkey.net/  
// @version      0.1.1
// @description  按下数字0键时,将页面上的所有视频重置到开头  
// @author       onionycs 
// @match        *://*/*  
// @grant        none  
// @license MIT
// ==/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(); // 如果需要,也可以在这里暂停视频   
                }  
            });  
        }  
    });  
})();