// // Copyright (c) 2012 Stefan Bolte // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // // /* *Fill forms automatically * * Extension that saves form data and fills forms with previously saved data * * To use this extension load it with a userscript in * $HOME/.config/dwb/userscripts/, e.g. * * ------------------------------------------------------------------------------ * |#!javascript | * | | * |extensions.load("formfiller"); | * ------------------------------------------------------------------------------ * * * Configuration options: * * formData : A path to a file where formdata will be saved, the default * path is $XDG_CONFIG_HOME/dwb/forms * * scGetForm : Shortcut that gets and saves form data, the default value is * 'efg' * * scFillForm : Shortcut that fills a form, the default value is 'eff' * * useGPG : Whether to use gpg2 to encrypt the formData file with a * password. * * GPGOptEncrypt : Additional options that will be passed to gpg2 for * encryption, the default gpg2 options are: * --passphrase --batch --no-tty --yes -c --output * default value: "" * * GPGOptDecrypt : Additional options that will be passed to gpg2 for * decryption, the default gpg2 options are * --passphrase --batch --no-tty --yes -d * default value: "" * * keepPassword : Whether to save the gpg password in memory, if set to false the * user will be prompted for the password every time a form * is filled or new data is saved, default value: true * * keepFormdata : If useGPG is enabled and this value is set to true the * complete formdata will be kept in memory, if set to false * gpg2 will be called every time a form is filled, default * value: false. * * * Example (loading config with extensions.load()) * * ------------------------------------------------------------------------------ * |extensions.load("formfiller", { | * | formData : system.getEnv("HOME") + "/data/forms", | * | scGetForm : "Control f", | * | useGPG : true | * |}); | * ------------------------------------------------------------------------------ * * Example extensionrc: * * ------------------------------------------------------------------------------ * |return { | * | foo : { ... }, | * | | * | formfiller : { | * | scGetForm : "efg", | * | scFillForm : "eff", | * | formData : "/path/to/data" | * | }, | * | bar : { ... } | * |} | * ------------------------------------------------------------------------------ * * */ var me = "formfiller"; var defaultConfig = { //DEFAULT_CONFIG }; var config = {}; var passWord = null; var formData = null; var injectGetForm = function () {//{{{ var ret = null; var forms = document.forms; function objectifyForm(f) { var query = "descendant::input[not(@type='hidden') and (@type='text' or @type='password' or @type='checkbox' or not(@type) or @type='email')]"; var input, data; var r = document.evaluate(query, f, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); var o = {}; o.id = f.id || null; o.form = {}; var hasValue = false; var hasIds = true; while ((input = r.iterateNext()) !== null) { if (input.value && !(/^\s*$/.test(input.value))) { if (/^\**$/.test(input.value) ) return null; if (!input.type || input.type.toLowerCase() === "text" || input.type.toLowerCase() === "password") hasValue = true; data = {}; if (input.id) data.id = input.id; else hasIds = false; data.value = input.value; o.form[input.name] = data; } } if (hasValue) { var ret = {}; o.hasIds = hasIds; ret[window.location.host] = o; return ret; } return null; } for (var i=0; i 0;") == "true") return true; } return false; }//}}} function fillForm() {//{{{ var data, frames, host, i, ret = false; if (! system.fileTest(config.formData, FileTest.regular | FileTest.symlink)) { io.error("No formdata found"); return; } frames = tabs.current.allFrames; if (!getHasForms(frames)) { io.error("No form found"); return; } data = getFormData(); if (data === null) return; for (i=0; i