bilibili 工具箱

长按 S 键倍速播放

  1. // ==UserScript==
  2. // @name bilibili 工具箱
  3. // @version 1.5.0
  4. // @description 长按 S 键倍速播放
  5. // @author sakura-flutter
  6. // @namespace https://github.com/sakura-flutter/tampermonkey-scripts
  7. // @license GPL-3.0
  8. // @compatible chrome Latest
  9. // @compatible firefox Latest
  10. // @compatible edge Latest
  11. // @noframes
  12. // @match https://www.bilibili.com/video/*
  13. // @match https://www.bilibili.com/bangumi/play/*
  14. // ==/UserScript==
  15.  
  16. /******/ (() => { // webpackBootstrap
  17. /******/ "use strict";
  18. var __webpack_exports__ = {};
  19.  
  20. ;// CONCATENATED MODULE: ./src/utils/selector.ts
  21. const $ = document.querySelector.bind(document);
  22. const $$ = document.querySelectorAll.bind(document);
  23. ;// CONCATENATED MODULE: ./src/scripts/bilibili/speed.js
  24.  
  25. function speed() {
  26. longPress('KeyS', () => {
  27. const video = $('#bilibili-player video') || $('#bilibili-player bwp-video');
  28. const oldPlaybackRate = video.playbackRate;
  29. video.playbackRate = 6;
  30. window.addEventListener('keyup', () => {
  31. video.playbackRate = oldPlaybackRate;
  32. }, {
  33. once: true
  34. });
  35. });
  36. }
  37. /**
  38. * 长按键盘
  39. * @param {string} code keyCode
  40. * @param {function} callback
  41. * @param {number} duration 长按时间
  42. */
  43.  
  44. function longPress(code, callback, duration = 350) {
  45. let timeoutID = null;
  46. window.addEventListener('keypress', event => {
  47. if (event.code === code && timeoutID) return;
  48.  
  49. if (event.code !== code) {
  50. if (timeoutID) {
  51. clearTimeout(timeoutID);
  52. timeoutID = null;
  53. }
  54.  
  55. return;
  56. }
  57.  
  58. timeoutID = setTimeout(() => {
  59. callback();
  60. }, duration);
  61. window.addEventListener('keyup', () => {
  62. clearTimeout(timeoutID);
  63. timeoutID = null;
  64. }, {
  65. once: true
  66. });
  67. });
  68. }
  69. ;// CONCATENATED MODULE: ./src/scripts/bilibili/index.js
  70.  
  71. speed();
  72. /******/ })()
  73. ;

QingJ © 2025

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