From 0a099734d7a18a68e2f494f4f7399b304437b584 Mon Sep 17 00:00:00 2001 From: anekos Date: Sun, 7 Mar 2010 18:13:37 +0000 Subject: -xpath -frame の修正 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@36957 d0d07461-0603-4401-acd4-de1884942a52 --- feedSomeKeys_3.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'feedSomeKeys_3.js') diff --git a/feedSomeKeys_3.js b/feedSomeKeys_3.js index 85f53a5..3e42ac0 100755 --- a/feedSomeKeys_3.js +++ b/feedSomeKeys_3.js @@ -39,7 +39,7 @@ let PLUGIN_INFO = feedSomeKeys 3 feed some defined key events into the Web content キーイベントをWebコンテンツ側に送る - 1.7.0 + 1.7.1 anekos new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) @@ -330,15 +330,14 @@ let INFO = <> v; function or (list, func) - let ([head, tail] = list) - ((func || v)(head) || (tail && or(tail, func))); + (list.length && let ([head,] = list) (func(head) || or(list.slice(1), func))); function getFrames () { function bodyCheck (content) (content.document.body.localName.toLowerCase() === 'body'); function get (content) - (bodyCheck(content) && result.push(content), Array.slice(content.frames).forEach(get)) + (bodyCheck(content) && result.push(content), Array.slice(content.frames).forEach(get)); let result = []; get(content); @@ -402,6 +401,14 @@ let INFO = <> return false; } + function xpathValidator (expr) { + try { + document.evaluate(expr, document, null, null, null); + return true; + } catch (e) {} + return false; + } + function makeListValidator (list) function (values) (values && !values.some(function (value) !list.some(function (event) event === value))); @@ -494,6 +501,13 @@ let INFO = <> }; } + function frameCompleter (context, args) { + return [ + [i, frame.document.location] + for each ([i, frame] in Iterator(getFrames())) + ]; + } + 'fmap fmaps'.split(/\s+/).forEach(function (cmd) { @@ -516,6 +530,7 @@ let INFO = <> let win = document.commandDispatcher.focusedWindow; let frames = getFrames(); + let elem = body(win); if (typeof args['-frame'] !== 'undefined') { @@ -523,8 +538,9 @@ let INFO = <> elem = body(frames[0]); } - if (args['-xpath']) - elem = or(frames, function (f) fromXPath(f, args['-xpath'])) || elem; + if (args['-xpath']) { + elem = or(frames, function (f) fromXPath(f.document, args['-xpath'])) || elem; + } feed(rhs, args['-events'] || ['keypress'], elem); }, @@ -565,7 +581,8 @@ let INFO = <> options: [ [['-urls', '-u'], commands.OPTION_STRING, regexpValidator, urlCompleter({currentURL: true})], [['-desc', '-description'], commands.OPTION_STRING], - [['-frame', '-f'], commands.OPTION_INT], + [['-frame', '-f'], commands.OPTION_INT, null, frameCompleter], + [['-xpath', '-x'], commands.OPTION_STRING, xpathValidator], [ ['-events', '-e'], commands.OPTION_LIST, -- cgit v1.2.3