Skip to content

Instantly share code, notes, and snippets.

@k-tsj
Last active June 14, 2020 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k-tsj/af03233fc023cb9e3280b0bce8c404b5 to your computer and use it in GitHub Desktop.
Save k-tsj/af03233fc023cb9e3280b0bce8c404b5 to your computer and use it in GitHub Desktop.
uc.js for Firefox 77+
// https://gist.github.com/k-tsj/af03233fc023cb9e3280b0bce8c404b5
//
// License: Mozilla Public License 2.0
// Author: k-tsj
(() => {
window.addEventListener("keydown", (aEvent) => {
const keywords = BrowserSearch.searchBar.value.match(/"(?:\\"|\\\\|[^"])*"|\S+/g);
function exec_find() {
gFindBar._findField.value = keywords[aEvent.keyCode - KeyEvent.DOM_VK_1].replace(/^"|"$/g, "");
gFindBar.onFindAgainCommand(aEvent.shiftKey);
gFindBar.close();
}
if (aEvent.altKey && (KeyEvent.DOM_VK_1 <= aEvent.keyCode && aEvent.keyCode <= KeyEvent.DOM_VK_9)) {
if (!gFindBar) {
gLazyFindCommand("onFindCommand");
setTimeout(exec_find, 100);
} else {
exec_find();
}
}
}, false);
})();
// https://gist.github.com/k-tsj/af03233fc023cb9e3280b0bce8c404b5
//
// License: Mozilla Public License 2.0
// Author: k-tsj
(() => {
gBrowser.tabContainer.addEventListener("TabSelect", (event) => {
setTimeout(() => {
const url = new URL(event.target.linkedBrowser.currentURI.spec);
const hostname = url.hostname;
const q = url.searchParams.get("q");
if ((hostname == "www.google.co.jp" || hostname == "www.google.com") && q) {
BrowserSearch.searchBar.value = q;
}
}, (event.target.linkedBrowser.currentURI.spec == "about:blank") ? 500 : 0);
} , 0);
})();
// https://gist.github.com/k-tsj/af03233fc023cb9e3280b0bce8c404b5
//
// License: Mozilla Public License 2.0
// Author: k-tsj
(() => {
var engines;
Services.search.getEngines().then(function (e) {
engines = e;
// set the first engine on startup.
if (engines[0]) {
Services.search.defaultEngine = engines[0];
}
});
function setEngineByAlias(alias) {
for (e of engines) {
if (e._metaData.alias == alias) {
Services.search.defaultEngine = e;
setTimeout(() => {Services.search.defaultEngine = engines[0]}, 60 * 1000);
return true;
}
}
return false;
}
const searchbar = BrowserSearch.searchBar;
searchbar.addEventListener("keydown", (aEvent) => {
if (aEvent.keyCode == KeyEvent.DOM_VK_SPACE) {
setTimeout(() => {
const keywords = searchbar.value.split(/ /);
if (setEngineByAlias(keywords[0])) {
setTimeout(() => {searchbar.value = keywords.slice(1).join(' ');}, 50);
}
}, 50);
}
}, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment