Skip to content

Instantly share code, notes, and snippets.

@XP1
Created August 4, 2011 09:14
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 XP1/1124807 to your computer and use it in GitHub Desktop.
Save XP1/1124807 to your computer and use it in GitHub Desktop.
Enhance Google Search: Adds a keyboard shortcut that opens the first search result in a Google Search.
// ==UserScript==
// @name Enhance Google Search
// @version 1.00
// @description Adds a keyboard shortcut that opens the first search result in a Google Search.
// @author XP1 (https://github.com/XP1/)
// @namespace https://gist.github.com/1124807/
// @include http*://google.*/search?*
// @include http*://*.google.*/search?*
// ==/UserScript==
/*jslint browser: true, vars: true, white: true, maxerr: 50, indent: 4 */
(function (topWindow)
{
"use strict";
if (window.self !== topWindow)
{
return;
}
var topWindowDocument = topWindow.document;
var options =
{
shortcutKeys:
{
shiftKey: true,
ctrlKey: true,
altKey: false,
keyCode: 70 // F
},
openInNewTab: true,
openInNewBackgroundTab: false
};
var openFirstSearchResult = function (event)
{
var shortcutKeys = options.shortcutKeys;
var pressedShortcutKeys = ((event.shiftKey === shortcutKeys.shiftKey) && (event.ctrlKey === shortcutKeys.ctrlKey) && (event.altKey === shortcutKeys.altKey) && (event.keyCode === shortcutKeys.keyCode));
if (pressedShortcutKeys)
{
event.preventDefault();
event.stopPropagation();
try
{
var firstResult = topWindowDocument.querySelector("a.l").href;
if (options.openInNewTab)
{
window.open(firstResult);
if (options.openInNewBackgroundTab)
{
topWindow.focus();
}
}
else
{
window.location.assign(firstResult);
}
}
catch (exception)
{
//window.opera.postError(exception);
}
}
};
topWindow.addEventListener("keydown", openFirstSearchResult, false);
}(window.top));
@XP1
Copy link
Author

XP1 commented Aug 4, 2011

I posted this user JS in this thread:

first google result key shortcut:
http://my.opera.com/community/forums/findpost.pl?id=10039182

PROTIP: CTRL + SHIFT + F.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment