[youtube.com] Arrow keys hate focus

No focus depending arrow keys binding. Left/Right - always playback, down/up - always volume.

目前為 2019-12-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            [youtube.com] Arrow keys hate focus
// @name:ru         [youtube.com] Клавиши стрелок гнобят фокус
// @description     No focus depending arrow keys binding. Left/Right - always playback, down/up - always volume.
// @description:ru  Клавиши стрелок не зависят от фокуса. Влево/Вправо - всегда перемотка, вниз/вверх - всегда громкость.
// @namespace       youtube.com/arrows.hate.focus
// @author          Zaytsev Artem
// @version         0.0.1.1
// @match           https://*.youtube.com/*
// ==/UserScript==

/*
document.addEventListener('focusin', (event) => {
	console.log("GM-youtube-novf: Focusin: " + event.target.className);
});
*/

//Sound volume panel.
//console.log("GM-youtube-novf: Quering the .ytp-volume-panel...");
var q_vp = document.querySelector(".ytp-volume-panel");
if (q_vp) {
	q_vp.addEventListener('focus', (event) => {
		//console.log("GM-youtube-novf: .ytp-volume-panel tried to get focus.");
		//event.target.focusout();
		//event.target.blur();
		document.querySelector(".html5-video-player").focus({preventScroll:true});
	});
	console.log("GM-youtube-novf: .ytp-volume-panel element found.");
	window.setTimeout(function(){
		//console.log("GM-youtube-novf: Setting .ytp-volume-panel's tabindex to -1...");
		q_vp.setAttribute("tabindex", "-1");
	}, 3000)
}

//Somehow the slider also wants to get the focus although it doesn't have a tabindex set.
var q_vsh = document.querySelector(".ytp-volume-slider-handle");
if (q_vsh) {
	q_vsh.addEventListener('focus', (event) => {
		//console.log("GM-youtube-novf: .ytp-volume-slider-handle tried to get focus.");
		document.querySelector(".html5-video-player").focus({preventScroll:true});
	});
	window.setTimeout(function(){
		//console.log("GM-youtube-novf: Setting .ytp-volume-slider-handle's tabindex to -1...");
		q_vsh.setAttribute("tabindex", "-1");
	}, 3000)
}

//The player playback seekbar.
var q_pb = document.querySelector(".ytp-progress-bar");
if (q_pb) {
	q_pb.addEventListener('focus', (event) => {
		//console.log("GM-youtube-novf: .ytp-progress-bar tried to get focus.");
		document.querySelector(".html5-video-player").focus({preventScroll:true});
	});
	window.setTimeout(function(){
		//console.log("GM-youtube-novf: Setting .ytp-progress-bar's tabindex to -1...");
		q_pb.setAttribute("tabindex", "-1");
	}, 3000)
}