🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

YouTube:使用 "L" 聚焦搜索栏

此脚本更改了 YouTube 上 "L" 键的行为,使其聚焦于搜索栏,而不是快进 10 秒。不会干扰您输入评论或使用文本字段。

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         YouTube L to Search Focus
// @name         YouTube: Focus Search Bar with "L"
// @name:fr      YouTube : Mettre le focus sur la barre de recherche avec "L"
// @name:de      YouTube: Suchleiste mit "L" fokussieren
// @name:es      YouTube: Enfocar la barra de búsqueda con "L"
// @name:it      YouTube: Focalizza la barra di ricerca con "L"
// @name:pt      YouTube: Focar na barra de pesquisa com "L"
// @name:zh-CN   YouTube:使用 "L" 聚焦搜索栏
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Focus on YouTube's search bar when pressing "L" key, without disrupting comments or text inputs.
// @description         This script changes the behavior of the "L" key on YouTube to focus the search bar instead of skipping 10 seconds. It won't interfere when typing comments or using text fields.
// @description:fr      Ce script modifie le comportement de la touche "L" sur YouTube pour mettre le focus sur la barre de recherche au lieu d'avancer de 10 secondes. Il ne dérange pas lors de la rédaction de commentaires ou l'utilisation de champs texte.
// @description:de      Dieses Skript ändert das Verhalten der "L"-Taste auf YouTube, sodass die Suchleiste fokussiert wird, anstatt 10 Sekunden vorzuspringen. Es stört nicht beim Schreiben von Kommentaren oder der Nutzung von Textfeldern.
// @description:es      Este script modifica el comportamiento de la tecla "L" en YouTube para enfocar la barra de búsqueda en lugar de avanzar 10 segundos. No interfiere al escribir comentarios o usar campos de texto.
// @description:it      Questo script modifica il comportamento del tasto "L" su YouTube per focalizzare la barra di ricerca invece di avanzare di 10 secondi. Non interferisce durante la scrittura di commenti o l'uso di campi di testo.
// @description:pt      Este script altera o comportamento da tecla "L" no YouTube para focar na barra de pesquisa em vez de avançar 10 segundos. Não interfere ao digitar comentários ou usar campos de texto.
// @description:zh-CN   此脚本更改了 YouTube 上 "L" 键的行为,使其聚焦于搜索栏,而不是快进 10 秒。不会干扰您输入评论或使用文本字段。
// @author       MatVampir0
// @match        https://www.youtube.com/*
// @grant        none
// @license      GPL v2.0
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// ==/UserScript==

(function() {
    'use strict';
    document.addEventListener('keydown', function(event) {
        if (event.key.toLowerCase() === 'l') {
            const activeElement = document.activeElement;
            if (
                activeElement.tagName === 'INPUT' ||
                activeElement.tagName === 'TEXTAREA' ||
                activeElement.getAttribute('contenteditable') === 'true'
            ) {
                return;
            }
            event.preventDefault();
            event.stopImmediatePropagation();
            const searchBox = document.querySelector('ytd-searchbox form #search');
            if (searchBox) {
                searchBox.focus();
            }
        }
    }, true);
})();