Netflix长按倍速脚本

Netflix长按右箭头倍速播放

  1. // ==UserScript==
  2. // @license AGPL License
  3. // @name Netflix长按倍速脚本
  4. // @name:en Netflix long press to speed up
  5. // @namespace Violentmonkey Scripts
  6. // @match https://www.netflix.com/*
  7. // @run-at document-start
  8. // @grant none
  9. // @version 1.0
  10. // @author n1nja88888
  11. // @description Netflix长按右箭头倍速播放
  12. // @description:en Netflix long press Arrow Right to speed up
  13. // ==/UserScript==
  14. 'use strict'
  15. const speed = 2
  16. const forward = 5
  17. console.log('n1nja88888 creates this world!')
  18.  
  19. !function () {
  20. //改变keydown事件监听器函数 忽略指定key
  21. function keydownOmit(listener, omits) {
  22. return (...args) => {
  23. if (!omits.has(args[0].key))
  24. listener(...args)
  25. }
  26. }
  27. // netflix 是keydown下的div#appaMountpoint控制
  28. Element.prototype._addEventListener = Element.prototype.addEventListener
  29. Element.prototype.addEventListener = function (type, listener, useCapture = false) {
  30. if (type === 'keydown')
  31. listener = keydownOmit(listener, new Set(['ArrowLeft', 'ArrowRight']))
  32. this._addEventListener(type, listener, useCapture)
  33. }
  34. }()
  35.  
  36. main()
  37.  
  38. function main() {
  39. // 倍速定时器
  40. let timer = null
  41. //初始速度,松开按键后是恢复到初始速度
  42. let initSpeed = -1
  43. // 获取nefliex内嵌的player
  44. let videoPlayer = null
  45. let player = null
  46. // 判断是否加速
  47. let isSpeeding = false
  48. // 复写keydown的事件监听器
  49. document.addEventListener('keydown', (e) => {
  50. if (isCombKey(e) || isActive('input', 'textarea') || !netflix)
  51. return
  52. videoPlayer = netflix.appContext.state.playerApp.getAPI().videoPlayer
  53. const sessions = videoPlayer.getAllPlayerSessionIds()
  54. player = videoPlayer.getVideoPlayerBySessionId(sessions[sessions.length - 1])
  55. if (!player)
  56. return
  57. switch (e.key) {
  58. case 'ArrowLeft':
  59. player.seek(player.getCurrentTime() - forward * 1e3)
  60. break
  61. case 'ArrowRight':
  62. if (!timer) {
  63. timer = setTimeout(() => {
  64. isSpeeding = true
  65. player.play()
  66. initSpeed = player.getPlaybackRate()
  67. player.setPlaybackRate(speed)
  68. }, 0.15e3)
  69. }
  70. break
  71. }
  72. })
  73.  
  74. document.addEventListener('keyup', (e) => {
  75. if (e.key === 'ArrowRight') {
  76. clearTimeout(timer)
  77. timer = null
  78. if (isSpeeding) {
  79. isSpeeding = false
  80. player.setPlaybackRate(initSpeed)
  81. }
  82. else
  83. player.seek(player.getCurrentTime() + forward * 1e3)
  84. }
  85. })
  86. }
  87.  
  88. // 判断是否是组合键
  89. function isCombKey(e) {
  90. return e.ctrlKey || e.shiftkey || e.altKey || e.metaKey
  91. }
  92. // 判断当前页面活动元素
  93. function isActive(...eleSet) {
  94. for (const ele of eleSet) {
  95. if (ele instanceof HTMLElement) {
  96. if (document.activeElement === ele)
  97. return true
  98. }
  99. else {
  100. switch (ele.charAt(0)) {
  101. case '.':
  102. if (document.activeElement.classList.contains(ele.substring(1)))
  103. return true
  104. break
  105. case '#':
  106. if (document.activeElement.id.toLowerCase() === ele.substring(1).toLowerCase())
  107. return true
  108. break
  109. default:
  110. if (document.activeElement.tagName.toLowerCase() === ele.toLowerCase())
  111. return true
  112. }
  113. }
  114. }
  115. return false
  116. }
  117.  

QingJ © 2025

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