Bluesky:用「/」键快速搜索
按「/」或 Ctrl/Cmd + K 直接聚焦 Bluesky 搜索框,无需点击。
可复制的代码
// Focus the search box with "/" (or Ctrl/Cmd + K)
(function () {
function focusSearch() {
var input = document.querySelector(
'[data-testid="searchTextInput"], input[aria-label="Search"], input[placeholder*="Search" i]'
);
if (input) {
input.focus();
try { input.select(); } catch (e) {}
return true;
}
var link = document.querySelector('a[href="/search"], a[aria-label="Search"]');
if (link) { link.click(); return true; }
return false;
}
document.addEventListener('keydown', function (e) {
var t = e.target;
var typing = t && (t.isContentEditable || /^(INPUT|TEXTAREA)$/.test(t.tagName));
if (e.key === '/' && !typing) {
if (focusSearch()) { e.preventDefault(); }
} else if ((e.ctrlKey || e.metaKey) && (e.key === 'k' || e.key === 'K')) {
if (focusSearch()) { e.preventDefault(); }
}
});
})();
如何使用此示例
- 用上方按钮复制代码。
- 安装 JustZix(2 分钟),在目标页面打开扩展。
- 添加一条匹配该页面的新规则。
- 将代码粘贴到规则的 JavaScript 面板并保存 — 每次访问页面时都会运行。
为此示例评分
暂无评分 — 成为第一个。