video, faster

make video faster

目前為 2023-09-17 提交的版本,檢視 最新版本

// ==UserScript==
// @name        video, faster
// @namespace   Violentmonkey Scripts
// @include     *://*/*
// @grant       none
// @version     1.1
// @author      KraXen72
// @description make video faster
// @grant       GM_registerMenuCommand
// @grant       GM_unregisterMenuCommand
// @license     MIT
// ==/UserScript==

// TODO
// auto look for video elements on location change
// add a floating menu above video to change speed & remember speed across videos (reapply)
// possibly support remembering speed + subtitles on a per-site basis implementation

// NOTE: to get compact video speed buttons, add this css in violentMonkey custom css in settings
/*
 [data-message="video, faster"] + .submenu-buttons + .submenu-commands {
 display: flex;
 justify-content: center;
}
[data-message="video, faster"] + .submenu-buttons + .submenu-commands .menu-item {
 padding: 0.5rem;
 margin: 0px;
 width: auto;
}
[data-message="video, faster"] + .submenu-buttons + .submenu-commands .menu-item .icon {
 display: none;
}
*/

let videoElem = null

const commands = {
  "1x": () => playbackRate(1),
  "1.5x": () => playbackRate(1.5),
  "2x": () => playbackRate(2),
  "2.5x": () => playbackRate(2.5),
  "2.75x": () => playbackRate(2.75),
  "3x": () => playbackRate(3),
  "3.5x": () => playbackRate(3.5),
  "4x": () => playbackRate(4)
}

function findVideoElement(debug = false) {
  if (document.body.contains(videoElem)) return;

  let qs = "video"
  // switch(window.location.hostname) {
  //   default:
  //     qs = "video"
  //     break;
  // }
  videoElem = document.querySelector(qs)

 if (videoElem !== null) {
   if (debug) console.log("found video elem", videoElem, qs)
 } else {
   if (debug) console.log("failed to find videoElem", qs)
 }
}

function playbackRate(rate) {
  findVideoElement()

  let wasplaying = !videoElem.paused
  if (wasplaying) videoElem.pause()
  videoElem.playbackRate = rate
  if (wasplaying) videoElem.play()
}

function registerCommands() {
  Object.keys(commands).forEach(command => {
    try {
      GM_unregisterMenuCommand(command)
    } catch (e) { console.error(e) }
  })
  Object.entries(commands).forEach(command => {
    GM_registerMenuCommand(command[0], command[1])
  })
}

findVideoElement()
registerCommands()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址