aboutsummaryrefslogtreecommitdiffstats
path: root/feedSomeKeys_3.js
diff options
context:
space:
mode:
authoranekos2010-03-07 18:13:37 +0000
committeranekos2010-03-07 18:13:37 +0000
commit0a099734d7a18a68e2f494f4f7399b304437b584 (patch)
tree82939566e6d62c1081004758b97bf056288ac4e0 /feedSomeKeys_3.js
parentb187f68c325bbd84c6c171823b8ef4ce539e49f1 (diff)
downloadvimperator-plugins-0a099734d7a18a68e2f494f4f7399b304437b584.tar.bz2
-xpath -frame の修正
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@36957 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'feedSomeKeys_3.js')
-rwxr-xr-xfeedSomeKeys_3.js31
1 files changed, 24 insertions, 7 deletions
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 =
<name lang="ja">feedSomeKeys 3</name>
<description>feed some defined key events into the Web content</description>
<description lang="ja">キーイベントをWebコンテンツ側に送る</description>
- <version>1.7.0</version>
+ <version>1.7.1</version>
<author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author>
<license>new BSD License (Please read the source code comments of this plugin)</license>
<license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license>
@@ -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,