Greasy Fork is available in English.
Focus search bar on pressing SLASH (/) or BACKSLASH (\) on amazon.de, bing.com, userscript.zone, github, aliexpress, hornbach, readly
当前为
// ==UserScript==
// @name slash search bar focus
// @namespace guebosch
// @author guebosch
// @match https://www.bing.com/search*
// @match https://www.userscript.zone/search*
// @match https://github.com/*
// @match https://go.readly.com/*
// @match https://www.hornbach.at/*
// @match https://*.aliexpress.com/*
// @match https://www.amazon.de/*
// @match https://piratehaven.xyz/search.php?*
// @icon https://www.google.com/s2/favicons?sz=64&domain=bing.com
// @grant none
// @description Focus search bar on pressing SLASH (/) or BACKSLASH (\) on amazon.de, bing.com, userscript.zone, github, aliexpress, hornbach, readly
// @version 0.7
// ==/UserScript==
//debugger;
// Note: google seems to work out of the box.
(function() {
const hostname = window.location.hostname;
var searchField;
window.addEventListener("keypress", e => {
if (['TEXTAREA', 'INPUT'].includes(e.target.nodeName)) return;
if (e.key !== "/" && e.key !== "\\") return;
if (['www.bing.com', 'foo.bing.com', 'www.hornbach.at'].includes(hostname)) {
searchField = document.querySelector('textarea[type="search"], input[type="search"], input[name="search"], input[placeholder*="Search"]');
}
else if (['www.userscript.zone','piratehaven.xyz'].includes(hostname)) {
searchField = document.querySelector('#search');
}
else if (['github.com'].includes(hostname)) {
searchField = document.querySelector('#js-issues-search');
}
else if (['de.aliexpress.com','en.aliexpress.com','www.aliexpress.com'].includes(hostname)) {
searchField = document.querySelector('#search-words');
}
else if (['www.amazon.de'].includes(hostname)) {
searchField = document.querySelector('#twotabsearchtextbox');
}
else if (['go.readly.com'].includes(hostname)) {
searchField = document.querySelector('#content-gate-input');
}
if (!searchField) return;
searchField.focus();
// move cursor to the right
searchField.setSelectionRange(searchField.value.length, searchField.value.length);
e.preventDefault();
});
})();