aboutsummaryrefslogtreecommitdiffstats
path: root/feedSomeKeys_3.js
diff options
context:
space:
mode:
authoranekos2010-03-01 12:22:31 +0000
committeranekos2010-03-01 12:22:31 +0000
commit003e5cf18c7c57a97a33a1a8b6596903365d4347 (patch)
tree443f0b6f4bb4ef425be5d8e1c422ab56aed1a5d4 /feedSomeKeys_3.js
parent86cc633dde8b89cbea651b4b4b9ca9a8de0de3d7 (diff)
downloadvimperator-plugins-003e5cf18c7c57a97a33a1a8b6596903365d4347.tar.bz2
XPath 指定対応
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@36881 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'feedSomeKeys_3.js')
-rwxr-xr-xfeedSomeKeys_3.js23
1 files changed, 22 insertions, 1 deletions
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);
},
{