bilibili/B站/mooc/慕课倍速控制优化

'+'、'-'控制倍速;'alt'+'[1-9]' 选择快速选择整数倍速;若无效请单击播放窗口一次再尝试,若仍无效请刷新页面;仍有bug请留言反馈

安装此脚本?
作者推荐脚本

您可能也喜欢超星键盘控制优化

安装此脚本
  1. // ==UserScript==
  2. // @name bilibili/B站/mooc/慕课倍速控制优化
  3. // @namespace https://gf.qytechs.cn/zh-CN/users/782923-asea
  4. // @version 1.0.5
  5. // @description '+'、'-'控制倍速;'alt'+'[1-9]' 选择快速选择整数倍速;若无效请单击播放窗口一次再尝试,若仍无效请刷新页面;仍有bug请留言反馈
  6. // @author Asea Q:569389750
  7. // @match https://www.bilibili.com/video/*
  8. // @match https://www.icourse163.org/learn/*
  9. // @match https://www.icourse163.org/spoc/learn/*
  10. // @icon https://www.bilibili.com/favicon.ico
  11. // @icon https://edu-image.nosdn.127.net/32a8dd2a-b9aa-4ec9-abd5-66cd8751befb.png?imageView&quality=100
  12. // @grant none
  13. // @license GPL-3.0-only
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. var old_url = window.location.href; // 获取当前url,方便后面换课时调用
  18. var errors = 0
  19. mainfn = setInterval(mainKeybind, 500);
  20. function mainKeybind(){
  21. if(document.readyState == 'complete') // 判断网页资源加载完毕
  22. {
  23. urlfn = setInterval(url_listener, 1000) // 监听url变化
  24. var rate = 0.2; // 倍速增长量,倍速最低0.2,最高16
  25. try
  26. {
  27. if(old_url.indexOf("bilibili") != -1)
  28. {
  29. videoElement = document.querySelector('video')
  30. }else{
  31. videoElement = document.querySelector('video')
  32. }
  33.  
  34. // videoElement.click()
  35. document.onkeydown = keybind // 绑定键盘事件
  36. function keybind(event)
  37. {//键盘事件
  38. var e = event || window.event || arguments.callee.caller.arguments[0];
  39. //鼠标上下键控制视频音量
  40. if(e &&(e.key === '=' || e.key === '+'))
  41. {
  42. // 按加号键 倍速增加
  43. rateButton = document.querySelector(old_url.search('bilibili')!== -1 ? '.bilibili-player-video-btn.bilibili-player-video-btn-speed button' : '.controlbar_btn.ratebtn.j-ratebtn')
  44. videoElement.playbackRate <= 16 -rate ? videoElement.playbackRate = parseFloat((videoElement.playbackRate+rate).toFixed(1)) : 1;
  45. rateButton.textContent = parseFloat(videoElement.playbackRate).toFixed(1).toString() + 'x'
  46. return false;
  47. } else if(e && e.key === '-')
  48. {
  49. // 按减号键 倍速减少
  50. rateButton = document.querySelector(old_url.search('bilibili')!== -1 ? '.bilibili-player-video-btn.bilibili-player-video-btn-speed button' : '.controlbar_btn.ratebtn.j-ratebtn')
  51. videoElement.playbackRate > rate ? videoElement.playbackRate = parseFloat((videoElement.playbackRate-rate).toFixed(1)) : 1;
  52. rateButton.textContent = parseFloat(videoElement.playbackRate).toFixed(1).toString() + 'x'
  53. return false;
  54. } else if(e && e.altKey && '123456789'.search(e.key) != -1)
  55. {
  56. // 整数倍速
  57. rateButton = document.querySelector(old_url.search('bilibili')!== -1 ? '.bilibili-player-video-btn.bilibili-player-video-btn-speed button' : '.controlbar_btn.ratebtn.j-ratebtn')
  58. videoElement.playbackRate > 0 && videoElement.playbackRate <= 16 ? videoElement.playbackRate = Number(e.key) : 1;
  59. rateButton.textContent = videoElement.playbackRate.toFixed(1) + 'x';
  60. return false;
  61. }else if(e && e.altKey && e.key === '0')
  62. {
  63. alert('已开启刷课模式,您可以按[shift]+[0]关闭')
  64. not_pause = setInterval(() => {
  65. if (videoElement.paused === true){
  66. videoElement.play()
  67. }
  68. }, 1000);
  69. }else if(e && e.shiftKey && e.key === '0')
  70. {
  71. try{
  72. clearInterval(not_pause)
  73. alert('已关闭刷课模式')}
  74. catch{
  75. alert('您未开启刷课模式,可以按[alt]+[0]开启')
  76. }
  77. }
  78. };
  79. console.log('Done') // 总事件绑定完毕
  80. clearInterval(mainfn); // 关闭加载元素的定时监听
  81. }
  82. catch
  83. {
  84. errors += 1
  85. if(errors < 20){
  86. console.log('Loading') // 元素未加载出来时
  87. }
  88. else if (errors > 20){
  89. console.log('未发现video元素,已关闭监听')
  90. clearInterval(mainfn)
  91. }
  92. }
  93. }
  94. }
  95.  
  96. function url_listener()
  97. {
  98. var now_url = window.location.href; // 当前url
  99. if (now_url !== old_url) // 判断是否换节课
  100. {
  101. errors = 0
  102. clearInterval(mainfn)
  103. console.log('发现url切换')
  104. old_url = now_url;
  105. mainfn = setInterval(mainKeybind, 500); // 开启主定时任务
  106. clearInterval(urlfn); // 关闭url监听定时任务
  107. }
  108. }
  109. })();

QingJ © 2025

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