Random filler

Fills out a form randomly when pressing [CTRL]+[ALT]+[F]. Useful for developers only

Click here to install Browse More Scripts
// ==UserScript==
// @name         Random filler
// @namespace    1e57b10ad57d3b904b98905ade0332d9d341954e
// @version      1.4
// @description  Fills out a form randomly when pressing [CTRL]+[ALT]+[F]. Useful for developers only
// @author       AyrA
// @include      http://*
// @include      https://*
// @grant        none
// ==/UserScript==

//1.4 - tel+url type
//1.3 - Fix max-length issue
//1.2 - Fix number range
//1.1 - Fix error on input element without type attribute
//1.0 - Initial release

(function () {
	'use strict';
	//random integer with range limits. Range: low <= i < high
	var rnd = function (low, high) {
		return Math.random() * (high - low) + low | 0;
	};

	//Returns true/false according to a percent chance
	var chance = function (perc) {
		return Math.random() <= perc / 100;
	};

	//Generates a random text with the given length and optional spaces
	var rndText = function (len, allowSpaces) {
		var ALPHA = "abcdefghi jklmn opq rstuv wxy z".split("");
		var str = "";
		for (var i = 0; i < len; i++) {
			str += ALPHA[rnd(0, ALPHA.length)];
		}
		if (!allowSpaces) {
			//Do not replace with an empty string as it makes the returned string shorter.
			return str.replace(/ /g, "q");
		}
		return str;
	};

	var rndNum = function (len) {
		var ALPHA = "0123456789".split("");
		var str = "";
		for (var i = 0; i < len; i++) {
			str += ALPHA[rnd(0, ALPHA.length)];
		}
		return str;
	};

	//Listen to key presses.
	document.addEventListener("keydown", function (e) {
		//Put a "!" in front of the modifier if you want to not require it.
		if (
			e.ctrlKey &&
			e.altKey &&
			!e.shiftKey &&
			e.keyCode == 70 /*F*/) {
			//Process all input elements
			var eles = document.querySelectorAll("input");
			for (var i = 0; i < eles.length; i++) {
				var ele = eles[i];
				var type = (ele.getAttribute("type") || "text").toLowerCase();
				if (ele.disabled !== true && ele.readonly !== true) {
					switch (type) {
						//generate pseudo-valid email addresses for email fields
					case "email":
						if (ele.value === "") {
							ele.value = rndText(5, false) + "." + rndText(7, false) + "@" + rndText(15, false) + ".com";
						}
						break;
						//Just set random text for text fields
					case "text":
						if (ele.value === "") {
							ele.value = rndText(+ele.maxLength || 50, true);
						}
						break;
					case "checkbox":
						//simulate click event
						if (chance(20)) {
							if (!ele.checked) {
								ele.click();
							}
						} else {
							if (ele.checked) {
								ele.click();
							}
						}
						break;
						//chose a random number for number input fields.
					case "number":
						if (ele.value === "") {
							ele.value = rnd(+ele.min || 0, +ele.max || 100);
						}
						break;
						//Fake telephone number
					case "tel":
						if (ele.value === "") {
							ele.value = rndNum(+ele.maxLength > 0 ? +ele.MaxLength : 10);
						}
						break;
						//Random URL (might actually exist)
					case "url":
						if (ele.value === "") {
							ele.value = "http://" + rndText(rnd(5, 10), false) + ".com/" + rndText(rnd(5, 20), false);
						}
						break;
						//ignore these
					case "hidden":
					case "button":
					case "submit":
					case "file":
						break;
					default:
						console.log("unhandled field type:", type);
						break;
					}
				}
			}
		}
	}, true);
})();

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 3.237.15.145