aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Paweł Zuzelski <pawelz@pld-linux.org>2010-03-27 01:37:42 +0100
committerGravatar Paweł Zuzelski <pawelz@pld-linux.org>2010-03-27 01:37:42 +0100
commitfc50da64fe96da436896aa077ee8a8f807969220 (patch)
tree4111a2622da172fb5e0dd9eec3162dbea78fbc21 /examples
parent32a4061abdd5f30e4a25c982fb52b09c08b39fb5 (diff)
Use javascript and XPath to find input fields.
Initialize field values.
Diffstat (limited to 'examples')
-rw-r--r--examples/data/scripts/formfiller-helper.js32
-rwxr-xr-xexamples/data/scripts/formfiller.sh17
2 files changed, 34 insertions, 15 deletions
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<window.frames.length;f=f+1) { allFrames.push(window.frames[f]); }; for(j=0;j<allFrames.length;j=j+1) { try { var myf = allFrames[j].document.forms; if(myf.length > 0) { for(k=0;k<myf.length;k=k+1) { output = output + myf[k].outerHTML; } } } catch(err) { } } return output; }; '
-
if [ "$action" = 'load' ]
then
[ -e $keydir/$domain ] || exit 2
@@ -94,19 +92,8 @@ then
elif [ "$action" = "once" ]
then
tmpfile=`mktemp`
- html=`echo 'js '${dumpFunction}' dump(); ' | \
- socat - unix-connect:$socket`
- html=`echo ${html} | \
- tr -d '\n' | \
- sed 's/>/>\n/g' | \
- sed 's/<input/<input type="text"/g' | \
- sed 's/type="text"\(.*\)type="\([^"]\+\)"/type="\2" \1 /g'`
- echo "${html}" | \
- sed -n 's/.*\(<input[^>]\+>\).*/\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/.*<textarea.*name="\([^"]\+\)".*/\1(textarea):/Ip' >> $tmpfile
+ echo "script @scripts_dir/formfiller-helper.js" | \
+ socat - unix-connect:$socket > $tmpfile
${editor} $tmpfile
[ -e $tmpfile ] || exit 2