Skip to content

Instantly share code, notes, and snippets.

@matijs
Last active December 28, 2015 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matijs/7526365 to your computer and use it in GitHub Desktop.
Save matijs/7526365 to your computer and use it in GitHub Desktop.
Random password generator bookmarklet
javascript:void(function() {
var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var password = "";
for (var i = 0, length = 64; i < length; ++i) {
password += chars[~~(Math.random() * chars.length)];
}
var input = document.getElementById("f773da90-5044-11e3-8f96-0800200c9a66") || document.createElement("input");
if (!input.id) {
input.id = "f773da90-5044-11e3-8f96-0800200c9a66";
input.setAttribute("style", "background:deeppink;border:2px solid #000;border-radius:.25em;box-shadow:0 0 1em .25em rgba(0,0,0,.5);color:#fff;position:fixed;top:1em;left:1em;font:16px/1 Helvetica,sans-serif;padding:.5em;z-index:9999;opacity:1;transition:opacity .5s;");
input.addEventListener("copy", function() {
if (typeof document.body.style["transition"] === "string") {
input.style["opacity"] = 0;
input.addEventListener("transitionend", function() {
document.body.removeChild(input);
});
}
else {
setTimeout(function() {
document.body.removeChild(input);
}, 500);
}
});
document.body.appendChild(input);
}
input.value = password;
input.select();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment