Permalink
Browse files

added ability to select suggestion and changed from position to index

  • Loading branch information...
1 parent 98a068d commit be1c16b8ae168a8b4187bb7a931aafb404eecebe whatsthebeef committed Feb 29, 2012
Showing with 21 additions and 6 deletions.
  1. +21 −6 google-results.js
View
@@ -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 :gr<Space>0<CR>
-* nmap ,2 :gr<Space>1<CR>
+* nmap ,0 :gr<Space>0<CR>
+* nmap ,1 :gr<Space>1<CR>
+* nmap ,2 :gr<Space>2<CR>
* 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();
+ }
});
})();

0 comments on commit be1c16b

Please sign in to comment.