Skip to content

Instantly share code, notes, and snippets.

@SamuelDavis
Last active October 8, 2017 07:38
Show Gist options
  • Select an option

  • Save SamuelDavis/95a52b83eb434363e6255a72d073b9e7 to your computer and use it in GitHub Desktop.

Select an option

Save SamuelDavis/95a52b83eb434363e6255a72d073b9e7 to your computer and use it in GitHub Desktop.
Super simple autofiller, run through http://bookmarklets.org/maker/
(function ($) {
function randInt(max, min) {
max = max || 1;
min = min || 0;
return parseInt(Math.random() * (max - min)) + min;
}
var letters = [
"a", "b", "c", "d", "e", "f", "g", "h",
"i", "j", "k", "l", "m", "n", "o", "p",
"q", "r", "s", "t", "u", "v", "w", "x",
"y", "z", " "
];
$("input[type=\"number\"]").each(function () {
var $this = $(this);
var max = $this.attr("max") || 99999999999;
var min = $this.attr("min") || 0;
$(this).val(randInt(max, min));
});
$("input[type=\"text\"]").each(function () {
var text = new Array(randInt(30, 1))
.fill(undefined)
.reduce(function (acc) {
return acc + letters[randInt(letters.length)];
}, "");
$(this).val(text);
});
$("select").each(function () {
var $this = $(this);
var options = $this.find("option");
$(options[randInt(options.length)]).prop("selected", true);
$this.trigger("change");
});
$("input[type=\"email\"]").each(function () {
var email = new Array(randInt(15, 10))
.fill(undefined)
.reduce(function (acc) {
return acc + letters[randInt(letters.length)];
}, "")
.replace(' ', '_')
.concat('@dev.autofill');
$(this).val(email);
});
var passwordSeed = ["a", "b", "c", 1, 2, 3, '!', '@', '#'];
var password = new Array(randInt(20, 15))
.fill(undefined)
.reduce(function (acc) {
return acc + passwordSeed[randInt(passwordSeed.length)];
}, "");
var passwords = $("input[type=\"password\"]");
passwords.each(function () {
$(this).val(password);
});
if (passwords.length && confirm("Copy password?")) {
var textArea = document.createElement("textarea");
textArea.innerText = password;
document.body.appendChild(textArea);
textArea.select();
try {
if (!document.execCommand("copy")) {
alert("Can't copy.");
}
} catch (err) {
alert("Could not copy password:" + err.message);
}
document.body.removeChild(textArea);
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment