Guest User

Untitled

a guest
May 7th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. // Version 1.1
  2. // ==UserScript==
  3. // @name Intelligent Form Filler
  4. // @description Fills registration forms with appropriate random data. Press Ctrl+Shift+F when promted.
  5. // @include *
  6. // ==/UserScript==
  7.  
  8. function randomInt(max) {
  9. return Math.floor(Math.random()*max);
  10. }
  11.  
  12. function match(input, regexp) {
  13. return ((input.name && input.name.match(regexp)) ||
  14. (input.id && input.id.match(regexp)));
  15. }
  16.  
  17. function randomWord(length) {
  18. var word="";
  19. for (var i=0; i<length; i++)
  20. word+=String.fromCharCode(randomInt(26)+97);
  21. return word;
  22. }
  23.  
  24. function fillPhoneNumber(input) {
  25. var n=input.getAttribute("maxlength");
  26. if (n<=10)
  27. input.value=(randomInt(8)+2)+""+randomInt(1000000000);
  28. else if (n>10)
  29. input.value=(randomInt(800)+201)+"-"+(randomInt(800)+201)+"-"+(randomInt(10000));
  30. }
  31.  
  32. function makeSelection(select) {
  33. if (select.length>2)
  34. select.selectedIndex=randomInt(select.length-2)+2;
  35. else
  36. select.selectedIndex=0;
  37. }
  38.  
  39. var retype;
  40. function fillTextBox(input) {
  41. if (match(input,/retype|c(on)?fi?rm/i) && retype)
  42. input.value=retype;
  43. else if (match(input,/e-?mail/i)) {
  44. input.value=email+"@mailinator.com";
  45. GM_setValue("form filler email", email);
  46. }
  47. else if (match(input,/login|use?r/i)) //user or login name
  48. input.value=username;
  49. else if (match(input,/phone/i)) //phone number
  50. fillPhoneNumber(input);
  51. else if (match(input,/zip/i) || input.getAttribute("maxlength")==5) //zip code
  52. input.value=randomInt(90000)+10000;
  53. else if (match(input,/code|ima?ge?/i)) {//CAPTCHA
  54. input.focus(); captcha=true;}
  55. else if (match(input,/year/i) || input.getAttribute("maxlength")==4) //year of birth
  56. input.value=1926+randomInt(60);
  57. else if (match(input,/day|date/i) || input.getAttribute("maxlength")==2) //date of birth
  58. input.value=randomInt(28)+1;
  59. else if (match(input,/nu?m?be?r/i))
  60. input.value=randomInt(10000000)+42;
  61. else
  62. input.value=randomWord(7+randomInt(4));
  63. retype=input.value;
  64. }
  65.  
  66. function fillField(input) {
  67. if (input.type=="hidden")
  68. return;
  69. else if (input.type=="password")
  70. input.value=password;
  71. else if (input.type=="text")
  72. fillTextBox(input);
  73. else if (input.type=="checkbox")
  74. input.checked=true;
  75. else if (input.type=="radio" && input.name) {
  76. var r=document.getElementsByName(input.name);
  77. r[randomInt(r.length)].checked=true;
  78. }
  79. else if (input.type=="radio")
  80. input.checked=true;
  81. else if (input.type && input.type.match(/select/))
  82. makeSelection(input);
  83. else if (input.type=="submit" && !captcha)
  84. input.focus();
  85. }
  86.  
  87. if (GM_getValue("form filler email")!=undefined && GM_getValue("form filler email")!="") {
  88. var a=document.createElement("a");
  89. a.setAttribute("href","http://mailinator.com/mailinator/maildir.jsp?email="+GM_getValue("form filler email")+"");
  90. a.appendChild(document.createTextNode("Check your email for confirmation link."));
  91. document.body.insertBefore(a, document.body.firstChild);
  92. GM_setValue("form filler email", "");
  93. }
  94.  
  95.  
  96. if (!document.forms.length)
  97. return;
  98.  
  99. var f=document.forms[0];
  100. for (var i=1; i<document.forms.length; i++)
  101. if (document.forms[i].elements.length>f.elements.length)
  102. f=document.forms[i];
  103. if (f.elements.length<7)
  104. return;
  105.  
  106. var div=document.createElement("div");
  107. div.appendChild(document.createTextNode("Press CTRL+SHIFT+F to fill in form."));
  108. f.parentNode.insertBefore(div, f);
  109.  
  110. var username, password, email, captcha;
  111. function submitForm() {
  112. username=randomWord(randomInt(4)+8);
  113. password=randomWord(8)+randomInt(100);
  114. email=randomWord(10);
  115. captcha=false;
  116. for (var i=0; i<f.elements.length; i++)
  117. fillField(f.elements[i]);
  118. }
  119.  
  120. function keyPressed(e) {
  121. if( e.ctrlKey && e.shiftKey && e.keyCode == 70 )
  122. submitForm();
  123.  
  124. }
  125.  
  126. window.addEventListener('keydown', keyPressed, false)
Add Comment
Please, Sign In to add comment