Created
August 4, 2011 09:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.