AbemaTVでショートカットキーによる操作を可能にします。キーアサインはYouTube準拠。
当前为
// ==UserScript==
// @name AbemaTV Shortcut Key Controller
// @namespace knoa.jp
// @description AbemaTVでショートカットキーによる操作を可能にします。キーアサインはYouTube準拠。
// @include https://abema.tv/*
// @version 1
// @grant none
// ==/UserScript==
(function(){
const SCRIPTNAME = 'ShortcutKeyController';
const DEBUG = false;
if(window === top) console.time(SCRIPTNAME);
let core = {
initialize: function(){
document.addEventListener('keydown', function (e) {
switch(true){
case(location.href.startsWith('https://abema.tv/now-on-air/')):
return core.realtime(e);
case(location.href.startsWith('https://abema.tv/channels/')):
case(location.href.startsWith('https://abema.tv/video/watch/')):
return core.timeshift(e);
}
}, true);
},
/* リアルタイム */
realtime: function(e){
switch(true){
/* テキスト入力中は反応しない */
case(document.activeElement.tagName == 'INPUT'):
case(document.activeElement.tagName == 'TEXTAREA'):
break;
/* コメント入力欄フォーカス */
case(e.key == 'k'):
case(e.key == ' '):
case(e.key == 'Enter'):
/* コメント欄が表示されていなければあらかじめ表示しておく */
if(document.querySelector('div[class*="styles__right-slide--shown___"]') == null){
document.querySelector('div[class*="styles__right-container___"] button[class*="style__container___"]').click();
}
document.querySelector('textarea[class*="styles__opened-textarea___"]').focus();
e.preventDefault();
break;
/* コメント */
case(e.key == 'c'):
if(document.querySelector('div[class*="styles__right-slide--shown___"]') == null){
document.querySelector('div[class*="styles__right-container___"] button[class*="style__container___"]').click();
}else{
document.querySelector('div[class*="style__overlap___"]').click();
}
e.preventDefault();
break;
/* フルスクリーン */
case(e.key == 'f'):
/* どちらか一方のボタンしか同時に存在しない */
document.querySelector('button[aria-label="フルスクリーン表示"]').click();
document.querySelector('button[aria-label="フルスクリーン解除"]').click();
e.preventDefault();
break;
/* ミュート */
case(e.key == 'm'):
document.querySelector('button[aria-label="音声オンオフ切り替え"]').click();
e.preventDefault();
break;
}
},
/* タイムシフト */
timeshift: function(e){
switch(true){
/* テキスト入力中は反応しない */
case(document.activeElement.tagName == 'INPUT'):
case(document.activeElement.tagName == 'TEXTAREA'):
break;
/* 再生・停止トグル */
case(e.key == 'k'):
case(e.key == ' '):
case(e.key == 'Enter'):
document.querySelector('div[class*="styles__play-handle___"]').click();
e.preventDefault();
break;
/* 10秒戻る */
case(e.key == 'j'):
case(e.key == 'ArrowLeft'):
document.querySelector('div[class*="styles__rewind-10___"]').click();
e.preventDefault();
break;
/* 10秒進む */
case(e.key == 'l'):
case(e.key == 'ArrowRight'):
document.querySelector('div[class*="styles__advances-10___"]').click();
e.preventDefault();
break;
/* フルスクリーン */
case(e.key == 'f'):
document.querySelector('div[class*="styles__screen-controler___"]').click();
e.preventDefault();
break;
/* ミュート */
case(e.key == 'm'):
document.querySelector('button[aria-label="音声オンオフ切り替え"]').click();
e.preventDefault();
break;
}
}
};
let log = (DEBUG) ? console.log.bind(null, SCRIPTNAME + ':') : function(){};
core.initialize();
if(window === top) console.timeEnd(SCRIPTNAME);
})();