summaryrefslogtreecommitdiff
path: root/examples/js/formfiller.js
diff options
context:
space:
mode:
authorportix <none@none>2012-06-09 10:44:26 +0200
committerportix <none@none>2012-06-09 10:44:26 +0200
commit24f8b43b392c3fb5d930bf81cb41098c7c694c9d (patch)
treee0e0cfc912ed25d43d85eee2df901a750d878283 /examples/js/formfiller.js
parent44d64cadd95a2240d2ce4aef6d9a161ca126f71f (diff)
downloaddwb-24f8b43b392c3fb5d930bf81cb41098c7c694c9d.zip
Adding googledocs.js to examples
--HG-- rename : examples/autoquvi.js => examples/js/autoquvi.js rename : examples/formfiller.js => examples/js/formfiller.js
Diffstat (limited to 'examples/js/formfiller.js')
-rw-r--r--examples/js/formfiller.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/examples/js/formfiller.js b/examples/js/formfiller.js
new file mode 100644
index 00000000..b89147f9
--- /dev/null
+++ b/examples/js/formfiller.js
@@ -0,0 +1,60 @@
+#!javascript
+
+/*
+ * Formfiller that automatically fills html forms. To get form names the
+ * webinspector can be used (needs 'enable-developer-extras' to be enabled.)
+ *
+ * The script has 2 configurable variables:
+ *
+ * shorcut: the shortcut that fills the form, uses dwb's default shortcut
+ * syntax
+ *
+ * forms: form data that will be filled into the form, the form data entry
+ * follows the following format:
+ *
+ * "[url regexp]" : { submit : [whether to autosubmit form], form { [name attribute of input] : [value], .... } },
+ *
+ *
+ * */
+
+var shortcut = "gF";
+
+var forms = {
+ "http://www.example.com/.*" : { submit : true, form : { name : "name", pass : "password", savepass : "true" } },
+ "http://www.foo.com.uk/.*" : { submit : false, form : { foo_name : "foo", foo_pass : "bar" } }
+};
+
+var injectFunction = function (data, submit) {
+ var name, value;
+ var e;
+ for (name in data) {
+ value = data[name];
+ e = document.getElementsByName(name)[0];
+ if(e.type=="checkbox" || e.type=="radio")
+ e.checked=(value.toLowerCase() !== 'false' && value !== '0');
+ else
+ e.value=value;
+ }
+ if (submit)
+ e.form.submit();
+};
+
+function fillForm () {
+ var key, r, name;
+ var uri = tabs.current.uri;
+ for (key in forms) {
+ r = new RegExp(key);
+ if (r.test(uri)) {
+ var script = "(" + String(injectFunction) + ")(" + JSON.stringify(forms[key].form) + "," + forms[key].submit + ");";
+ var frames = tabs.current.allFrames;
+ for (var i=0; i<frames.length; i++) {
+ frames[i].inject(script);
+ }
+ return;
+ }
+ }
+}
+
+bind(shortcut, fillForm);
+
+// vim: set ft=javascript: