bilibili 倍速播放
// ==UserScript==
// @name bilibili 倍速播放
// @namespace https://bbs.tampermonkey.net.cn/
// @version 1.0.0
// @description 简易小 demo,看道总、之一gg的教程写的~
// @author Xbai-hang
// @match https://www.bilibili.com/video/*
// ==/UserScript==
(function() {
var input = document.createElement('input');
input.id = 'self-rate';
input.placeholder = '输入倍速(0, 16]';
input.type = 'text';
var dom = document.querySelector('.video-desc-v1');
dom.insertBefore(input, dom.firstChild);
var rateDom = document.querySelector('#self-rate');
rateDom.onblur = function() {
var rate = rateDom.value;
while(Object.is(parseInt(rate), NaN) || rate <= 0 || rate > 16) {
rate = parseInt(prompt("倍速播放应该在 (0, 16] 之间, 输入数据不合法, 请更改数据"));
rateDom.value = rate;
}
document.querySelector('video').playbackRate = rate;
}
rateDom.onkeydown = function(e){
if(e.keyCode == 13){
rateDom.onblur()
}
}
})();