Nurutomo2

Auto Cliker [BETA]

Sep 25th, 2018
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function AutoClicker(key = "F2", mode = 1, speed = 1000, isActive = false) {
  2.     this.speed = speed;
  3.     this.key = key;
  4.     this.isActive = isActive;
  5.     this.mode = mode;
  6.     this.toggle = function() {
  7.         isActive = !isActive;
  8.         option.document.querySelector('body').style.backgroundColor = isActive ? "#0F0" : "#F00";
  9.             option.document.querySelectorAll('p')[1].innerHTML = isActive ? "On" : "Off";
  10.     }
  11.     option = window.open("", "", "width=220,height=140");
  12.     isClosed = false;
  13.  
  14.     document.querySelectorAll('*').forEach(function(elem) {
  15.         elem.addEventListener("mouseover", function moIn(e) {
  16.             if (!isClosed) {
  17.                 elem.AutoClick = setInterval(() => {
  18.                     if (isActive) {
  19.                         leftClick(elem, e)
  20.                     }
  21.                 }, speed);
  22.             }
  23.         });
  24.         elem.addEventListener("mouseout", function moOut() {
  25.             clearInterval(elem.AutoClick);
  26.         });
  27.     });
  28.  
  29.     function leftClick(el, event) {
  30.         if (mode = 1) {
  31.             el.dispatchEvent(new MouseEvent('click', event));
  32.         } else {
  33.             el.click();
  34.         }
  35.     }
  36.  
  37.     document.addEventListener('keydown', keydown);
  38.  
  39.     function keydown(e) {
  40.         key = option.document.querySelector('p').innerHTML
  41.         if (e.code == key) {
  42.             isActive = !isActive;
  43.             option.document.querySelector('body').style.backgroundColor = isActive ? "#0F0" : "#F00";
  44.             option.document.querySelectorAll('p')[1].innerHTML = isActive ? "On" : "Off";
  45.         }
  46.     }
  47.  
  48.     option.document.write(`
  49. <style>*{user-select:none;transition: all 0.2s;}</style>
  50. <body style="background-color: #F00; font-family: Verdana">
  51. <input type="number" min="1" value="${speed}">ms
  52. <br>
  53. <label for="key">Toggle Key</label>
  54. <select id="opt"><option value="1">Dispatch</option><option value="2">Click</option></select>
  55. <input type="text" id="key" style="visibility: hidden;width: 0px;height: 0px;margin: 0px;">
  56. <p>${key}</p>
  57. <p>Off</p>
  58. </body>
  59. <title>${location.href + ' - Auto Clicker Options'}</title>
  60. `);
  61.  
  62.     option.document.addEventListener('keydown', keydown);
  63.  
  64.     keys = option.document.querySelector('#key');
  65.     keys.onkeydown = keys.onkeyup = function(e) {
  66.         option.document.querySelectorAll('p')[0].innerHTML = e.code;
  67.     }
  68.  
  69.     modes = option.document.querySelector('select#opt');
  70.     modes.addEventListener('change', function() {
  71.         mode = modes.value;
  72.     });
  73.  
  74.     window.addEventListener('mousemove', function() {
  75.         speed = option.document.querySelectorAll('input')[0].value;
  76.     });
  77.  
  78.     window.addEventListener('beforeunload', function() {
  79.         option.close();
  80.         document.querySelectorAll('*').forEach(function(elem) {
  81.             elem.removeEventListener('mouseover', moIn);
  82.             elem.removeEventListener('mouseout' , moOut);
  83.         })
  84.     });
  85.  
  86.     option.document.addEventListener('beforeunload', function() {
  87.         isClosed = true;
  88.     });
  89. }
Advertisement
Add Comment
Please, Sign In to add comment