Created
July 4, 2013 17:07
-
-
Save apskii/5929152 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Enviance Form Filler | |
| // --------------------------------------------------------------------------------------------- | |
| // | |
| // Form-filling script for custom enviance applications. | |
| // Currently can into many basic things but doesn't support complex dependencies between fields. | |
| // | |
| // --------------------------------------------------------------------------------------------- | |
| // | |
| // ==UserScript== | |
| // @name Enviance Form Filler | |
| // @author Andriy P | |
| // @description Form-filling script for custom enviance applications. | |
| // @include https://*.qa.enviance.kiev.ua/* | |
| // ==/UserScript== | |
| function waitUntilThenDo (until, then, timeout) { | |
| function wait () { | |
| window.setTimeout(function() { | |
| if (until()) then(); | |
| else window.setTimeout(arguments.callee, timeout); | |
| }, timeout); | |
| } | |
| wait(); | |
| } | |
| function delayed (timeout, proc) { | |
| window.setTimeout(proc, timeout); | |
| } | |
| function keyDown (keyCode) { | |
| var event = $.Event("keydown"); | |
| event.keyCode = $.ui.keyCode[keyCode]; | |
| return event; | |
| } | |
| var down = keyDown('DOWN'); | |
| var enter = keyDown('ENTER'); | |
| $(document).keypress(function(e){ | |
| if (e.which == 102 || e.keyCode == 102 || window.event.keyCode == 102) { | |
| // * Dates | |
| $('input.reqval.dateonly').val('07/02/2013'); | |
| // * Times | |
| $('input.reqval.timeonly').val('08:34 AM'); | |
| // * DateTimes | |
| $('input.reqval.datetimeval').val('07/15/2013 12:00 AM'); | |
| // * Checkboxes and Radiobuttons | |
| $('div.field-group') | |
| .find('input[type="checkbox"]:first, input[type="radio"]:first') | |
| .attr('checked', true); | |
| // * Comboboxes (static first, ac-data-rich later) | |
| var comboboxes = $('input.ui-combobox-input'); | |
| var acComboboxes = []; | |
| function fillNthAutocompleteCombobox (n) { | |
| var elem = $(acComboboxes[n]); | |
| delayed(1000, function () { | |
| elem.val(''); | |
| elem.autocomplete('search', ''); | |
| waitUntilThenDo( | |
| function () { return !elem.hasClass('ui-autocomplete-loading'); }, | |
| function () { | |
| delayed(500, function () { | |
| elem.trigger(down); | |
| delayed(500, function () { | |
| elem.trigger(enter); | |
| if (n < acComboboxes.length - 1) | |
| fillNthAutocompleteCombobox(n+1); | |
| }); | |
| }); | |
| }, 500); | |
| }); | |
| } | |
| $('ul.ui-autocomplete').each(function (i) { | |
| var elem = $(comboboxes[i]); | |
| if (elem.val()) return; | |
| var span = elem.parent().find('span')[0]; | |
| if (elem.attr('readonly')) { | |
| span.click(); | |
| var li = $(this).find('li')[0]; | |
| var text = li && $(li).text(); | |
| elem.val(text); | |
| span.click(); | |
| } else { | |
| acComboboxes.push(elem.get(0)); | |
| } | |
| if (acComboboxes[0]) | |
| fillNthAutocompleteCombobox(0); | |
| }); | |
| // * Phones | |
| $('input.reqval.phone').val('12312312432'); | |
| // * Remaining reqvals | |
| $('*.reqval:not(.ui-combobox-input)').each(function () { | |
| var elem = $(this); | |
| if (!elem.val()) | |
| elem.val('hohoho'); | |
| }); | |
| } | |
| }); | |
| $(document).keypress(function(e){ | |
| if (e.which == 103 || e.keyCode == 103 || window.event.keyCode == 103) { | |
| $('*.reqval').each(function () { | |
| var elem = $(this); | |
| if (!elem.val()) | |
| elem.val('L4L'); | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment