B站视频倍速控制器脚本

调整B站视频播放速度

目前为 2022-03-01 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name B站视频倍速控制器脚本
  3. // @namespace https://github.com/csXLJ/bzplayer/
  4. // @version 2.0
  5. // @description 调整B站视频播放速度
  6. // @author csXLJ
  7. // @icon https://www.bilibili.com/favicon.ico?v=1
  8. // @include https://www.bilibili.com/*
  9. // @match https://www.bilibili.com/video/*
  10. // @grant none
  11. // @license GPL
  12. // ==/UserScript==
  13.  
  14. var controller = (function () {
  15. var timeId;
  16. var speed;
  17. function keyd(e) {
  18. var whichVideo = document.querySelector('bwp-video') != null ? document.querySelector('bwp-video') : document.querySelector('video');
  19. speed = whichVideo.playbackRate;
  20. if (e.key == "+") {
  21. if (speed == 16) {
  22. speed = 16;
  23. } else {
  24. speed = speed + 0.1;
  25. speed = roundFun(speed, 1);
  26. }
  27. } else if (e.key == "-") {
  28. if (speed == 0) {
  29. speed = 0;
  30. } else {
  31. speed = speed - 0.1;
  32. speed = roundFun(speed, 1);
  33. }
  34. }
  35. var str = "播放速度:"+speed + "x";
  36. addAndDelTil(whichVideo, "div", str);
  37. whichVideo.playbackRate = speed;
  38. }
  39.  
  40. document.body.removeEventListener('keydown', keyd);
  41. document.body.addEventListener('keydown', keyd);
  42.  
  43. function roundFun(value, n) {
  44. return Math.round(value * Math.pow(10, n)) / Math.pow(10, n);
  45. }
  46.  
  47. function addAndDelTil(element, tab, str) {
  48. if (timeId != null) {
  49. $(element).prev().remove();
  50. clearTimeout(timeId);
  51. }
  52. var para = document.createElement(tab);
  53. var node = document.createTextNode(str);
  54. para.appendChild(node);
  55. para.style.position = "absolute";
  56. para.style.color = "white";
  57. //para.style.textShadow = "2px 2px 5px #00a1d6";
  58. para.style.fontWeight = "bold";
  59. para.style.borderRadius = "15px";
  60. para.style.border = "2px solid #00a1d6";
  61. para.style.backgroundColor = "#00a1d6";
  62. para.style.padding = "1px";
  63. para.style.opacity = "0.5";
  64. para.style.fontFamily = "-apple-system,BlinkMacSystemFont,Helvetica Neue,Helvetica,Arial,PingFang SC,Hiragino Sans GB,Microsoft YaHei,sans-serif";
  65. para.style.left = "1%";
  66. para.style.top = "1%";
  67. para.style.zIndex = 99999;
  68. element.before(para);
  69. timeId = setTimeout(function () {
  70. para.remove();
  71. clearTimeout(timeId);
  72. }, 2000);
  73.  
  74. }
  75. // Your code here...
  76. })();

QingJ © 2025

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