Greasy Fork

Greasy Fork is available in English.

按下0键重置视频

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         按下0键重置视频
// @namespace    http://tampermonkey.net/
// @version      2024年8月29日23点12分
// @description  按下数字0键时,将页面上的所有视频重置到开头
// @author       onionycs
// @match        https://www.bilibili.com/*
// @match        https://www.mashibing.com/*
// @match        https://live.shixiseng.com/review/*
// @match        https://video.51job.com/watch/*
// @match        https://www.acwing.com/video/*
// @require      http://code.jquery.com/jquery-3.x-git.min.js
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    // 推荐安装,http://greasyfork.icu/zh-CN/scripts/390792-b站封面替换右侧广告-bilibili-哔哩哔哩


    /* globals jQuery, $, waitForKeyElements */
    // 监听键盘按下事件
    document.addEventListener('keydown', function(event) {
        // 检查按下的键是否是数字0(注意:这里不区分大小写,但数字键通常没有大小写)
        if (event.key === '0') {
            // 显示确认对话框
            if (confirm('确定要将所有视频重置到开头吗?')) {
                // 获取页面上所有的video标签
                const videos = document.querySelectorAll('video');

                // 遍历每个video标签,并将其currentTime设置为0
                videos.forEach(video => {
                    video.currentTime = 0;
                    video.pause();
                    // 如果需要,可以在这里添加额外的逻辑,比如暂停或播放视频
                });
                alert("已退回开头,空格键播放")
            }

        }

         if (event.key === 'k'||event.key === 'K') {
             const videos = document.querySelectorAll('video');
             videos.forEach(video => {
                 // 如果视频当前是暂停的,则播放;如果是播放的,则暂停
                 if (video.paused) {
                     video.play();
                 } else {
                     video.pause();
                 }
             });
         }

        if (event.key === 'j'||event.key === 'J') {
            const videos = document.querySelectorAll('video');
            videos.forEach(video => {
                video.currentTime -= 10;
            });
        }

        if (event.key === 'l'||event.key === 'L') {
            const videos = document.querySelectorAll('video');
            videos.forEach(video => {
                video.currentTime += 10;
            });
        }

        if (event.key === 't'||event.key === 'T') {
            const buttons = $('.bpx-player-ctrl-wide').toArray();
            buttons.forEach(button => {
                button.click();
            });
        }
    });
})();