From debbca424278eaeb66a7d03d27f8cfd9f6a42651 Mon Sep 17 00:00:00 2001 From: mitsugu oyama Date: Mon, 15 Nov 2010 13:22:14 +0900 Subject: add onclick.js --- onclick.js | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 onclick.js (limited to 'onclick.js') diff --git a/onclick.js b/onclick.js new file mode 100644 index 0000000..d975efc --- /dev/null +++ b/onclick.js @@ -0,0 +1,86 @@ +// INFO // +var INFO = + + Mitsugu Oyama + MIT + +

+ Emulate onClick event. +

+ + 'onclick' + :onclick target + +

Emulate onClick event.

+

Should add hash table to .vimperatorrc.

+ +
+
+
; + +commands.addUserCommand( + ['onclick'], + 'Emulate onClick event.', + function(args){ + if(args.length<1){ + liberator.echoerr('Usage: onclick {xpath_id}'); + return false; + } + let strXpath=liberator.globalVariables.onclickTable[args[0]]; + if(undefined==strXpath){ + liberator.echoerr('Not Found XPath'); + return false; + } + let contents=gBrowser.selectedBrowser.contentDocument; + let evaluateXPath=function(aNode,aExpr){ + let xpe=new XPathEvaluator(); + let nsResolver=xpe.createNSResolver(aNode.ownerDocument==null ? + aNode.documentElement : aNode.ownerDocument.documentElement); + let result=xpe.evaluate(aExpr,aNode,nsResolver,0,null); + let found=[]; + let res; + while(res=result.iterateNext()) + found.push(res); + return found; + }; + let elms=evaluateXPath(contents,strXpath); + if(elms.length==0){ + liberator.echoerr('Not Found Element. Can you check it?'); + return false; + } + let evt=contents.createEvent("MouseEvents"); + evt.initMouseEvent( + 'click', + true, // canBubble + true, // cancelable + window, // view + 0, // detail + 0, // screenX + 0, // screenY + 0, // clientX + 0, // clientY + false, // ctrlKey + false, // altKey + false, // shiftKey + false, // metaKey + 0, // button + null //relatedTarget + ); + elms[0].dispatchEvent(evt); + }, + { + literal: false + }, + true +); -- cgit v1.2.3