HTML5播放器自定义配置

HTML5播放器自定义配置,按需定制自己的功能

  1. // ==UserScript==
  2. // @name HTML5播放器自定义配置
  3. // @name:en HTML5 player enhanced script custom configuration
  4. // @namespace https://github.com/xxxily/h5player
  5. // @homepage https://github.com/xxxily/h5player
  6. // @version 0.0.1
  7. // @description HTML5播放器自定义配置,按需定制自己的功能
  8. // @description:en HTML5 video player enhanced script custom configuration
  9. // @author ankvps
  10. // @icon https://cdn.jsdelivr.net/gh/xxxily/h5player@master/logo.png
  11. // @match *://*/*
  12. // @grant unsafeWindow
  13. // @run-at document-start
  14. // @license GPL
  15. // ==/UserScript==
  16.  
  17. /* 自定义配置 */
  18. const customConfiguration = {
  19. media: {
  20. autoPlay: false,
  21. playbackRate: 1,
  22. volume: 1,
  23.  
  24. /* 是否允许存储播放进度 */
  25. allowRestorePlayProgress: {
  26.  
  27. },
  28. /* 视频播放进度映射表 */
  29. progress: {}
  30. },
  31. hotkeys: [
  32. {
  33. desc: '网页全屏',
  34. key: 'shift+enter',
  35. command: 'setWebFullScreen',
  36. /* 如需禁用快捷键,将disabled设为true */
  37. disabled: false
  38. },
  39. {
  40. desc: '全屏',
  41. key: 'enter',
  42. command: 'setFullScreen'
  43. },
  44. {
  45. desc: '切换画中画模式',
  46. key: 'shift+p',
  47. command: 'togglePictureInPicture'
  48. },
  49. {
  50. desc: '视频截图',
  51. key: 'shift+s',
  52. command: 'capture'
  53. },
  54. {
  55. desc: '启用或禁止自动恢复播放进度功能',
  56. key: 'shift+r',
  57. command: 'capture'
  58. },
  59. {
  60. desc: '垂直镜像翻转',
  61. key: 'shift+m',
  62. command: 'setMirror',
  63. args: [true]
  64. },
  65. {
  66. desc: '水平镜像翻转',
  67. key: 'm',
  68. command: 'setMirror'
  69. },
  70. {
  71. desc: '下载音视频文件(实验性功能)',
  72. key: 'shift+d',
  73. command: 'mediaDownload'
  74. },
  75. {
  76. desc: '缩小视频画面 -0.05',
  77. key: 'shift+x',
  78. command: 'setScaleDown'
  79. },
  80. {
  81. desc: '放大视频画面 +0.05',
  82. key: 'shift+c',
  83. command: 'setScaleUp'
  84. },
  85. {
  86. desc: '恢复视频画面',
  87. key: 'shift+z',
  88. command: 'resetTransform'
  89. },
  90. {
  91. desc: '画面向右移动10px',
  92. key: 'shift+arrowright',
  93. command: 'setTranslateRight'
  94. },
  95. {
  96. desc: '画面向左移动10px',
  97. key: 'shift+arrowleft',
  98. command: 'setTranslateLeft'
  99. },
  100. {
  101. desc: '画面向上移动10px',
  102. key: 'shift+arrowup',
  103. command: 'setTranslateUp'
  104. },
  105. {
  106. desc: '画面向下移动10px',
  107. key: 'shift+arrowdown',
  108. command: 'setTranslateDown'
  109. },
  110. {
  111. desc: '前进5秒',
  112. key: 'arrowright',
  113. command: 'setCurrentTimeUp'
  114. },
  115. {
  116. desc: '后退5秒',
  117. key: 'arrowleft',
  118. command: 'setCurrentTimeDown'
  119. },
  120. {
  121. desc: '前进30秒',
  122. key: 'ctrl+arrowright',
  123. command: 'setCurrentTimeUp',
  124. args: [30]
  125. },
  126. {
  127. desc: '后退30秒',
  128. key: 'ctrl+arrowleft',
  129. command: 'setCurrentTimeDown',
  130. args: [-30]
  131. },
  132. {
  133. desc: '音量升高 5%',
  134. key: 'arrowup',
  135. command: 'setVolumeUp',
  136. args: [0.05]
  137. },
  138. {
  139. desc: '音量降低 5%',
  140. key: 'arrowdown',
  141. command: 'setVolumeDown',
  142. args: [-0.05]
  143. },
  144. {
  145. desc: '音量升高 20%',
  146. key: 'ctrl+arrowup',
  147. command: 'setVolumeUp',
  148. args: [0.2]
  149. },
  150. {
  151. desc: '音量降低 20%',
  152. key: 'ctrl+arrowdown',
  153. command: 'setVolumeDown',
  154. args: [-0.2]
  155. },
  156. {
  157. desc: '切换暂停/播放',
  158. key: 'space',
  159. command: 'switchPlayStatus'
  160. },
  161. {
  162. desc: '减速播放 -0.1',
  163. key: 'x',
  164. command: 'setPlaybackRateDown'
  165. },
  166. {
  167. desc: '加速播放 +0.1',
  168. key: 'c',
  169. command: 'setPlaybackRateUp'
  170. },
  171. {
  172. desc: '正常速度播放',
  173. key: 'z',
  174. command: 'resetPlaybackRate'
  175. },
  176. {
  177. desc: '设置1x的播放速度',
  178. key: 'Digit1',
  179. command: 'setPlaybackRatePlus',
  180. args: 1
  181. },
  182. {
  183. desc: '设置1x的播放速度',
  184. key: 'Numpad1',
  185. command: 'setPlaybackRatePlus',
  186. args: 1
  187. },
  188. {
  189. desc: '设置2x的播放速度',
  190. key: 'Digit2',
  191. command: 'setPlaybackRatePlus',
  192. args: 2
  193. },
  194. {
  195. desc: '设置2x的播放速度',
  196. key: 'Numpad2',
  197. command: 'setPlaybackRatePlus',
  198. args: 2
  199. },
  200. {
  201. desc: '设置3x的播放速度',
  202. key: 'Digit3',
  203. command: 'setPlaybackRatePlus',
  204. args: 3
  205. },
  206. {
  207. desc: '设置3x的播放速度',
  208. key: 'Numpad3',
  209. command: 'setPlaybackRatePlus',
  210. args: 3
  211. },
  212. {
  213. desc: '设置4x的播放速度',
  214. key: 'Digit4',
  215. command: 'setPlaybackRatePlus',
  216. args: 4
  217. },
  218. {
  219. desc: '设置4x的播放速度',
  220. key: 'Numpad4',
  221. command: 'setPlaybackRatePlus',
  222. args: 4
  223. },
  224. {
  225. desc: '下一帧',
  226. key: 'F',
  227. command: 'freezeFrame',
  228. args: 1
  229. },
  230. {
  231. desc: '上一帧',
  232. key: 'D',
  233. command: 'freezeFrame',
  234. args: -1
  235. },
  236. {
  237. desc: '增加亮度',
  238. key: 'E',
  239. command: 'setBrightnessUp'
  240. },
  241. {
  242. desc: '减少亮度',
  243. key: 'W',
  244. command: 'setBrightnessDown'
  245. },
  246. {
  247. desc: '增加对比度',
  248. key: 'T',
  249. command: 'setContrastUp'
  250. },
  251. {
  252. desc: '减少对比度',
  253. key: 'R',
  254. command: 'setContrastDown'
  255. },
  256. {
  257. desc: '增加饱和度',
  258. key: 'U',
  259. command: 'setSaturationUp'
  260. },
  261. {
  262. desc: '减少饱和度',
  263. key: 'Y',
  264. command: 'setSaturationDown'
  265. },
  266. {
  267. desc: '增加色相',
  268. key: 'O',
  269. command: 'setHueUp'
  270. },
  271. {
  272. desc: '减少色相',
  273. key: 'I',
  274. command: 'setHueDown'
  275. },
  276. {
  277. desc: '模糊增加 1 px',
  278. key: 'K',
  279. command: 'setBlurUp'
  280. },
  281. {
  282. desc: '模糊减少 1 px',
  283. key: 'J',
  284. command: 'setBlurDown'
  285. },
  286. {
  287. desc: '图像复位',
  288. key: 'Q',
  289. command: 'resetFilterAndTransform'
  290. },
  291. {
  292. desc: '画面旋转 90 度',
  293. key: 'S',
  294. command: 'setRotate'
  295. },
  296. {
  297. desc: '播放下一集',
  298. key: 'N',
  299. command: 'setNextVideo'
  300. },
  301. {
  302. desc: '执行JS脚本',
  303. key: 'ctrl+j ctrl+s',
  304. command: () => {
  305. alert('自定义JS脚本-demo')
  306. },
  307. when: ''
  308. }
  309. ],
  310. enhance: {
  311. /* 不禁用默认的调速逻辑,则在多个视频切换时,速度很容易被重置,所以该选项默认开启 */
  312. blockSetPlaybackRate: true,
  313.  
  314. blockSetCurrentTime: false,
  315. blockSetVolume: false,
  316. allowExperimentFeatures: false
  317. },
  318. debug: false
  319. }
  320.  
  321. /**
  322. * 任务配置中心 Task Control Center
  323. * 用于配置所有无法进行通用处理的任务,如不同网站的全屏方式不一样,必须调用网站本身的全屏逻辑,才能确保字幕、弹幕等正常工作
  324. **/
  325. const customTaskControlCenter = {
  326. /**
  327. * 配置示例
  328. * 父级键名对应的是一级域名,
  329. * 子级键名对应的相关功能名称,键值对应的该功能要触发的点击选择器或者要调用的相关函数
  330. * 所有子级的键值都支持使用选择器触发或函数调用
  331. * 配置了子级的则使用子级配置逻辑进行操作,否则使用默认逻辑
  332. * 注意:include,exclude这两个子级键名除外,这两个是用来进行url范围匹配的
  333. * */
  334. 'demo.demo': {
  335. fullScreen: '.fullscreen-btn',
  336. exitFullScreen: '.exit-fullscreen-btn',
  337. webFullScreen: function () {},
  338. exitWebFullScreen: '.exit-fullscreen-btn',
  339. autoPlay: '.player-start-btn',
  340. pause: '.player-pause',
  341. play: '.player-play',
  342. switchPlayStatus: '.player-play',
  343. playbackRate: function () {},
  344. currentTime: function () {},
  345. addCurrentTime: '.add-currenttime',
  346. subtractCurrentTime: '.subtract-currenttime',
  347. // 自定义快捷键的执行方式,如果是组合键,必须是 ctrl-->shift-->alt 这样的顺序,没有可以忽略,键名必须全小写
  348. shortcuts: {
  349. /* 注册(不可用)要执行自定义回调操作的快捷键 */
  350. register: [
  351. 'ctrl+shift+alt+c',
  352. 'ctrl+shift+c',
  353. 'ctrl+alt+c',
  354. 'ctrl+c',
  355. 'c'
  356. ],
  357. /* 自定义快捷键的回调操作 */
  358. callback: function (h5Player, taskConf, data) {
  359. const { event, player } = data
  360. console.log(event, player)
  361. }
  362. },
  363. /* 当前域名下需包含的路径信息,默认整个域名下所有路径可用 必须是正则 */
  364. include: /^.*/,
  365. /* 当前域名下需排除的路径信息,默认不排除任何路径 必须是正则 */
  366. exclude: /\t/
  367. },
  368. 'netflix.com': {
  369. // 停止在netflix下使用插件的所有功能
  370. // disable: true,
  371. fullScreen: 'button.button-nfplayerFullscreen',
  372. addCurrentTime: 'button.button-nfplayerFastForward',
  373. subtractCurrentTime: 'button.button-nfplayerBackTen',
  374. /**
  375. * 使用netflix自身的调速,因为目前插件没法解决调速导致的服务中断问题
  376. * https://github.com/xxxily/h5player/issues/234
  377. * https://github.com/xxxily/h5player/issues/317
  378. * https://github.com/xxxily/h5player/issues/381
  379. * https://github.com/xxxily/h5player/issues/179
  380. * https://github.com/xxxily/h5player/issues/147
  381. */
  382. playbackRate: true,
  383. shortcuts: {
  384. /**
  385. * TODO
  386. * netflix 一些用户习惯使用F键进行全屏,所以此处屏蔽掉f键的下一帧功能
  387. * 后续开放自定义配置能力后,让用户自行决定是否屏蔽
  388. */
  389. register: [
  390. 'f'
  391. ],
  392. callback: function (h5Player, taskConf, data) {
  393. return true
  394. }
  395. }
  396. }
  397. }
  398.  
  399. /* 注册(不可用)自定义配置信息 */
  400. const pageWin = window.unsafeWindow
  401. if (pageWin) {
  402. const configuration = { customConfiguration, customTaskControlCenter }
  403. pageWin.__h5PlayerCustomConfiguration__ = configuration
  404. pageWin.__setH5PlayerCustomConfiguration__ instanceof Function && pageWin.__setH5PlayerCustomConfiguration__(configuration, 'External')
  405. }

QingJ © 2025

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