From fc50da64fe96da436896aa077ee8a8f807969220 Mon Sep 17 00:00:00 2001 From: Paweł Zuzelski Date: Sat, 27 Mar 2010 01:37:42 +0100 Subject: Use javascript and XPath to find input fields. Initialize field values. --- examples/data/scripts/formfiller-helper.js | 32 ++++++++++++++++++++++++++++++ examples/data/scripts/formfiller.sh | 17 ++-------------- 2 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 examples/data/scripts/formfiller-helper.js (limited to 'examples/data/scripts') diff --git a/examples/data/scripts/formfiller-helper.js b/examples/data/scripts/formfiller-helper.js new file mode 100644 index 0000000..999d860 --- /dev/null +++ b/examples/data/scripts/formfiller-helper.js @@ -0,0 +1,32 @@ +/* This script finds all editable input elemnts and generate file for + * formfiller script. It must be invoked from formfiller.sh */ + +(function () { + /* evaluate XPath query */ + var xp_res=document.evaluate("//input", document.documentElement, null, XPathResult.ANY_TYPE,null); + var rv=""; + var input; + + while(input=xp_res.iterateNext()) { + var type=(input.type?input.type:text); + switch (type) { + case "text": + case "password": + case "file": + rv += input.name + "(" + type + "):" + input.value + "\n"; + break; + case "checkbox": + case "radio": + rv += input.name + "[" + input.value + "]" + "(" + type + "):" + (input.checked?"ON":"") + "\n"; + break; + /* Not supported: + * case "button": + * case "image": + * case "reset": + * case "submit": + * case "hidden": + */ + } + } + return rv; +})() diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh index 6f6dc34..9fbe8fc 100755 --- a/examples/data/scripts/formfiller.sh +++ b/examples/data/scripts/formfiller.sh @@ -75,8 +75,6 @@ then action="new" fi -dumpFunction='function dump() { var output = ""; var allFrames = new Array(window); for(f=0;f 0) { for(k=0;k/>\n/g' | \ - sed 's/]\+>\).*/\1/;/type="\(password\|text\|checkbox\)"/Ip' | \ - sed 's/\(.*\)\(type="[^"]\+"\)\(.*\)\(name="[^"]\+"\)\(.*\)/\1\4\3\2\5/I' | \ - sed 's/.*name="\([^"]\+\)".*type="\([^"]\+\)".*/\1(\2):/I' >> $tmpfile - echo "${html}" | \ - sed -n 's/.*> $tmpfile + echo "script @scripts_dir/formfiller-helper.js" | \ + socat - unix-connect:$socket > $tmpfile ${editor} $tmpfile [ -e $tmpfile ] || exit 2 -- cgit v1.2.3