TampermonkeyScripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.4 KiB

5 years ago
// ==UserScript==
// @name bilibili播放器快捷键
// @namespace https://kdxcxs.com/
// @version 0.1
// @description 为bilibili web播放器增加快捷键
// @author kdxcxs
// @include https://www.bilibili.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
document.onreadystatechange = function(){
const initVideoInfo = ()=>{ // https://www.v2ex.com/t/640663
const wrap = document.getElementsByClassName('bilibili-player-video-wrap')[0];
wrap.dispatchEvent(new MouseEvent("contextmenu", {
bubbles: true,
cancelable: false,
view: window,
button: 2,
buttons: 0,
clientX: wrap.getBoundingClientRect().x+10,
clientY: wrap.getBoundingClientRect().y+10
}));
const menu = document.getElementsByClassName('bilibili-player-context-menu-origin')[0];
const a = menu.getElementsByTagName('a');
a[a.length - 1].click();}
// 绑定按键
if(document.readyState == "complete"){
document.addEventListener('keydown', (event) => {
const code = event.keyCode
if (code === 53) { // 键盘5
// 网页端全屏
document.getElementsByClassName('bilibili-player-video-web-fullscreen')[0].click()
return;
}
if (code === 220) { // 键盘\|
// 全屏
document.getElementsByClassName('bilibili-player-video-btn-fullscreen')[0].click()
}
if (code === 9) { // tab
// 打开视频统计信息
if(!$('.bilibili-player-video-info-container').length){
// 初始化视频统计信息
initVideoInfo()
}
else{
if($('.bilibili-player-video-info-container').is(":hidden")){
$('.bilibili-player-video-info-container').show()
}
else{
$('.bilibili-player-video-info-container').hide()
}
}
}
}, false);
console.log('Bilibili播放器快捷键绑定完成');
}
}
})();