diff options
author | mitsugu oyama | 2011-02-18 15:37:13 +0900 |
---|---|---|
committer | mitsugu oyama | 2011-02-18 15:37:13 +0900 |
commit | 2176f8fae5a39fbdcf3f303b74343f921504ea99 (patch) | |
tree | 89c35659b694a676df1bf96c73ed58c49d407bc3 | |
parent | 59345d949b0378daa1cdddd87b2eeb582357243a (diff) | |
download | vimperator-plugins-2176f8fae5a39fbdcf3f303b74343f921504ea99.tar.bz2 |
add XPath Name Suggestion
-rw-r--r-- | onclick.js | 53 |
1 files changed, 41 insertions, 12 deletions
@@ -1,6 +1,6 @@ // INFO // var INFO = -<plugin name="onclick.js" version="0.1" +<plugin name="onclick.js" version="0.2" summary="Emulate onClick event." href="http://github.com/vimpr/vimperator-plugins/blob/master/onclick.js" xmlns="http://vimperator.org/namespaces/liberator"> @@ -21,7 +21,7 @@ For Exsample, js <<EOM liberator.globalVariables.onclickTable={ 'github':'//span[@class="toggle"][1]', - 'pixiv':'//span[@class="trigger"][1]' + 'pixiv' :'//span[@class="trigger"][1]' }; EOM ]]></code> @@ -29,10 +29,8 @@ For Exsample, </item> </plugin>; -commands.addUserCommand( - ['onclick'], - 'Emulate onClick event.', - function(args){ +(function(){ + let onclick=function(args){ if(args.length<1){ liberator.echoerr('Usage: onclick {xpath_id}'); return false; @@ -78,9 +76,40 @@ commands.addUserCommand( null //relatedTarget ); elms[0].dispatchEvent(evt); - }, - { - literal: false - }, - true -); + }; + let tblSuggest; + let comp=function(context, args){ + context.completions=tblSuggest; + }; + let addSuggestTable=function(){ + if(liberator.globalVariables.onclickTable==undefined){ + liberator.echoerr('Not Found XPath Table'); + return false; + } + tblSuggest=new Array(); + let item; + let i; + for(i in liberator.globalVariables.onclickTable){ + item=new Array(i,liberator.globalVariables.onclickTable[i]); + tblSuggest.push(item); + } + }; + let initialize=function(){ + addSuggestTable(); + commands.addUserCommand( + ['onclick'], + 'Emulate onClick event.', + onclick, + { + completer : comp, + argCount : 0, + hereDoc : false, + bang : false, + count : false, + literal : false + }, + true + ); + } + initialize(); +})(); |