aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwhatsthebeef2012-02-29 17:25:24 -0600
committerwhatsthebeef2012-02-29 17:25:24 -0600
commitbe1c16b8ae168a8b4187bb7a931aafb404eecebe (patch)
tree37a0b354c43dd5133733d4b3152183e0626430b5
parent98a068dc23ddc7c7f5e405087d816a4d7d72fd62 (diff)
downloadvimperator-plugins-be1c16b8ae168a8b4187bb7a931aafb404eecebe.tar.bz2
added ability to select suggestion and changed from position to index
-rwxr-xr-xgoogle-results.js27
1 files changed, 21 insertions, 6 deletions
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 :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();
+ }
});
})();