HTML5 Video Playback Speed Control Keyboard Shortcut

Add keyboard shortcuts to decrease (CTRL+,), increase (CTRL+.), and reset (CTRL+;) HTML5 video playback rate. Available playback speeds are between 0.25 to 2.0 inclusive in 0.25 increments. Speed of 1.0 is used when resetting playback speed. Note: the video playback speed menu selection on YouTube will not be affected.

当前为 2017-09-12 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        HTML5 Video Playback Speed Control Keyboard Shortcut
// @namespace   HTML5VideoPlaybackSpeedControlKeyboardShortcut
// @description Add keyboard shortcuts to decrease (CTRL+,), increase (CTRL+.), and reset (CTRL+;) HTML5 video playback rate. Available playback speeds are between 0.25 to 2.0 inclusive in 0.25 increments. Speed of 1.0 is used when resetting playback speed. Note: the video playback speed menu selection on YouTube will not be affected.
// @version     1.0.2
// @author      jcunews
// @include     http://*/*
// @include     https://*/*
// @grant       none
// ==/UserScript==

addEventListener("keydown", function(ev) {
  var ele = document.querySelector("VIDEO"), rate;
  if (ele && ev.ctrlKey) {
    rate = rate = ele.playbackRate;
    if ((ev.key === ",") || (ev.keyIdentifier === "U+00BC")) {
      rate -= 0.25;
      if (rate < 0.25) rate = 0.25;
    } else if ((ev.key === ".") || (ev.keyIdentifier === "U+00BE")) {
      rate += 0.25;
      if (rate > 2) rate = 2;
    } else if ((ev.key === ";") || (ev.keyIdentifier === "U+00BA")) {
      rate = 1;
    }
    rate = Math.trunc(rate * 4) / 4;
    ele.playbackRate = rate;
  }
});