JSFiddle - React, Tailwind, and code Playground
by Alex
HTML
<input type="text" name="pass" id="pass" value="">
<input type="text" name="pass2" id="pass" value="">
<a id="generate">Генерировать пароли</a>
JavaScript
function getPass( object, object2 ){
var i, interval, words = "";
words += "qwertyuiopasdfghjklzxcvbnm";
words += "QWERTYUIOPASDFGHJKLZXCVBNM";
words += "1234567890";
var obj = document.getElementsByName(object);
var obj2 = document.getElementsByName(object2);
obj = obj[0];
obj2 = obj2[0];
obj.setAttribute("type", "text");
obj2.setAttribute("type", "text");
obj.value = "";
obj2.value = "";
var new_word_timeout = 100; // время между появлением новых букв.
var word_timeout = 10; // время между сменой букв
var word_count = 10; // количество букв
new function(){
this.getNextWord = function(){
obj.value += " ";
obj2.value += " ";
}
this.getWord = function(){
obj.value = obj.value.substring( 0, obj.value.length - 1 ) + words.charAt( getRand( 0, words.length -1 ) );
obj2.value = obj.value;
}
this.stop = function(){
clearInterval( interval );
}
for( i = 0; i < word_count; i ++ ){
setTimeout( this.getNextWord, i * new_word_timeout );
}
interval = setInterval( this.getWord, word_timeout );
setTimeout( this.stop, new_word_timeout * word_count );
}
}
function getRand( min, max ){
return Math.round( Math.random( ) * ( max - min ) ) + min;
}
$('#generate').click(function(){
getPass('pass', 'pass2');
});