您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Auto focus Youtube player to enable hotkeys
// ==UserScript== // @name YouTube Video Autofocus // @name:ru YouTube автофокус видео // @description Auto focus Youtube player to enable hotkeys // @description:ru Ставит фокус на плеер YouTube для активации хоткеев // @namespace https://github.com/Autapomorph/userscripts // @author Autapomorph // @version 1.0.0 // @run-at document_end // @match *://youtube.com/* // @match *://www.youtube.com/* // @supportURL https://github.com/Autapomorph/userscripts/discussions // @license MIT // ==/UserScript== (function ytVideoAutofocus() { const checkIntervalMs = 1000; function main() { const videoElSelector = '.html5-main-video'; const videoEl = document.querySelector(videoElSelector); if (videoEl) { videoEl.focus({ preventScroll: true, }); } } function isVideoPage(searchString = top.location.search) { const videoSearchParamKey = 'v'; return new URLSearchParams(searchString).has(videoSearchParamKey); } function getVideoSearchParamValue(searchString = top.location.search) { const videoSearchParamKey = 'v'; return new URLSearchParams(searchString).get(videoSearchParamKey); } let currentVideoSearchParamValue = getVideoSearchParamValue(); setInterval(() => { if (!isVideoPage()) { return; } const newVideoSearchParamValue = getVideoSearchParamValue(); if (currentVideoSearchParamValue !== newVideoSearchParamValue) { currentVideoSearchParamValue = newVideoSearchParamValue; main(); } }, checkIntervalMs); if (isVideoPage()) { main(); } })();