您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
打开B站自动聚焦搜索框,适配最新页面结构
// ==UserScript== // @name B站自动聚焦搜索框优化版 // @namespace http://tampermonkey.net/ // @version 1.1 // @description 打开B站自动聚焦搜索框,适配最新页面结构 // @match https://www.bilibili.com/* // @license MIT // @grant none // ==/UserScript== (function() { 'use strict'; // 等待页面关键元素加载的函数,通过MutationObserver监听 function waitForElement(selector, callback) { const observer = new MutationObserver((mutationsList) => { const targetElement = document.querySelector(selector); if (targetElement) { observer.disconnect(); // 找到元素后停止监听 callback(targetElement); } }); observer.observe(document.body, { childList: true, subtree: true }); } // 调用等待函数,定位搜索框(根据实际class定位) waitForElement('.nav-search-input', (searchInput) => { searchInput.focus(); // 聚焦搜索框 console.log('已成功聚焦B站搜索框'); }); })();