From 003e5cf18c7c57a97a33a1a8b6596903365d4347 Mon Sep 17 00:00:00 2001 From: anekos Date: Mon, 1 Mar 2010 12:22:31 +0000 Subject: XPath 指定対応 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@36881 d0d07461-0603-4401-acd4-de1884942a52 --- feedSomeKeys_3.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/feedSomeKeys_3.js b/feedSomeKeys_3.js index 31bd2b6..72ccf4e 100755 --- a/feedSomeKeys_3.js +++ b/feedSomeKeys_3.js @@ -133,6 +133,13 @@ let INFO = '\'': KeyEvent.DOM_VK_QUOTE }; + function id (v) + v; + + function or (list, func) + let ([head, tail] = list) + ((func || v)(head) || (tail && or(tail, func))); + function getFrames () { function bodyCheck (content) (content.document.body.localName.toLowerCase() === 'body'); @@ -145,6 +152,11 @@ let INFO = return result; } + function fromXPath (doc, xpath) { + let result = util.evaluateXPath(xpath, doc); + return result.snapshotLength && result.snapshotItem(0); + } + function virtualize (event) { event.keyCode = VKeys[String.fromCharCode(event.charCode).toLowerCase()]; event.charCode = 0; @@ -196,14 +208,23 @@ let INFO = [lhs], args['description'] || 'by feedSomeKeys_3.js', function () { + let win = document.commandDispatcher.focusedWindow; let frames = getFrames(); - let elem = document.commandDispatcher.focusedWindow; + let elem = win; if (typeof args['-frame'] !== 'undefined') { frames = [frames[args['-frame']]]; elem = frames[0]; } + if (args['-xpath']) + elem = or(frames, function (f) fromXPath(args['-xpath'])); + + if (!elem) { + liberator.log('feedSomeKeys_3: Not found target element'); + elem = win; + } + feed(rhs, args['-events'] || ['keypress'], elem); }, { -- cgit v1.2.3