Last active
June 15, 2024 17:23
-
-
Save ohownew/c512223973c0e30cfff920d33711d190 to your computer and use it in GitHub Desktop.
知识星球原生视频组件,无法通过键盘操作前进、后退、暂停、播放,于是写了一个简单的脚本,要先安装好篡改猴Tampermonkey等插件管理器。然后新建脚本,并复制如下代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name 知识星球视频增强 | |
// @namespace http://tampermonkey.net/ | |
// @version 2024-04-21 | |
// @description 知识星球视频,通过键盘控制: 前进 后退 暂停 开始 全屏 | |
// @author ohownew | |
// @match https://wx.zsxq.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=zsxq.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var isFullScreen = false; | |
// 添加键盘事件监听器 | |
document.addEventListener('keydown', function(event) { | |
const key = event.key; | |
// 获取视频元素 | |
const video = document.querySelector('video'); | |
// 按下左键,将视频当前时间减去5秒 | |
if (key === 'ArrowLeft') { | |
video.currentTime -= 5; | |
} | |
// 按下右键,将视频当前时间加上5秒 | |
else if (key === 'ArrowRight') { | |
video.currentTime += 5; | |
} | |
// 按下空格键,播放或暂停视频 | |
else if (key === ' ') { | |
if (video.paused) { | |
video.play(); | |
} else { | |
video.pause(); | |
} | |
} | |
// 按下组合键 Shift + F,全屏或退出全屏 | |
else if (key === 'F') { | |
if (isFullScreen) { | |
video.webkitExitFullscreen(); | |
isFullScreen = false; | |
} else { | |
video.webkitEnterFullscreen(); | |
isFullScreen = true; | |
} | |
} | |
//上键->音量增加10 | |
else if(key === 'ArrowUp') { | |
if (video.volume < 1) { | |
video.volume += 0.1 | |
video.play() | |
} else { | |
//alert('音量已调到最大') | |
} | |
} | |
//下键->音量减小10 | |
else if(key === 'ArrowDown') { | |
if (video.volume > 0) { | |
video.volume -= 0.1 | |
video.play() | |
} else { | |
//alert('音量已调到最小') | |
} | |
} | |
}); | |
})(); |
大佬nb ,好用
更新记录:
2024-06-15 新增上下键调节音量
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
更新记录:
2024-04-21 增加全屏功能:shift+F | video变量的声明移动到addEventListener中