From be1c16b8ae168a8b4187bb7a931aafb404eecebe Mon Sep 17 00:00:00 2001 From: whatsthebeef Date: Wed, 29 Feb 2012 17:25:24 -0600 Subject: added ability to select suggestion and changed from position to index --- google-results.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'google-results.js') diff --git a/google-results.js b/google-results.js index 14161c7..1118106 100755 --- a/google-results.js +++ b/google-results.js @@ -11,18 +11,21 @@ * Creative Commons * * USAGE -* :gr [index] -* index - the index of the result you would like to access +* :gr [position] +* position - the position of the result you would like to access +* if position = 0 it will use the suggestion or if there isn't one with will +* search same string again * * EXAMPLE * keys can be mapped like so -* nmap ,1 :gr0 -* nmap ,2 :gr1 +* nmap ,0 :gr0 +* nmap ,1 :gr1 +* nmap ,2 :gr2 * etc... * the you only need to press ,1 to access first result... * * HISTORY -* 2012/02/27 ver. 0.1 - initial written. +* 2012/02/29 ver. 0.2 - initial written. * */ @@ -31,6 +34,18 @@ commands.addUserCommand(["gr"], "Google Results", function (args) { - window.content.document.querySelectorAll("div > ol > li > div > h3 > a")[args].click(); + var doc = window.content.document; + if(args >= 1) { + var results = doc.querySelectorAll("div > ol > li > div > h3 > a"); + if(args <= results.length) { + results[args - 1].click(); + } + else { + console.error("Not that many results"); + } + } + else { + (doc.querySelector("div > p > a.spell") || doc.querySelector("div > button")).click(); + } }); })(); -- cgit v1.2.3