在 Ubuntu 下播放视频使用,把文件拖入 Chrome 的地址栏,F12 打开检查工具,选择console栏,粘贴下面的代码即可
页面刷新后就会失效
实现的快捷键有:左右方向键调整进度(同时使用Ctrl加快调整速度),v/b: 增加/减慢播放速度
const video = document.getElementsByTagName('video')[0];
function setv(speed) {
video.playbackRate = speed;
}
// speed_control
let now_speed_value = 0;
const max_speed_value = 5;
const speed_array = [1, 1.25, 1.5, 2,3];
// play_percent
const total = video.duration;
function right_move(per) {
if(video.currentTime + per <= total) {
video.currentTime += per;
} else {
video.currentTime = total;
}
}
function left_move(per) {
if(video.currentTime - per >= 0) {
video.currentTime -= per;
} else {
video.currentTime = 0;
}
}
function catchKey() {
const input = window.event.keyCode;
const flag = window.event.ctrlKey;
if (input == 86 || input == 66) {
now_speed_value += (input==86?1:(max_speed_value-1));
now_speed_value %= max_speed_value;
speed = speed_array[now_speed_value];
setv(speed);
alert('当前播放速度:'+speed);
} else if(input == 39 || input == 76) { // l 和 右方向键
right_move(flag?30:10);
} else if(input == 37 || input == 72) { // h 和 左方向键
left_move(flag?30:10);
}
}
document.onkeydown = catchKey;