javascript:var DELAY = 1;var autoClickerStyleElement = document.createElement(“style”);autoClickerStyleElement.innerHTML=“*{cursor: crosshair !important;}”;document.body.appendChild(autoClickerStyleElement);function addClicker(e) {if(!e.isTrusted) {return;}if(e.target.classList.contains(“auto-clicker-target”)) {e.target.classList.remove(“auto-clicker-target”);} else {e.target.classList.add(“auto-clicker-target”);}document.body.removeChild(autoClickerStyleElement);document.body.removeEventListener(“click”, addClicker);e.preventDefault();autoClick(e.target);}function autoClick(element) {if(element.classList.contains(“auto-clicker-target”)) {element.click();setTimeout(function(){ autoClick(element); }, DELAY);}}document.body.addEventListener(“click”, addClicker, 0);
Did you actually make this code? It is in a bookmarklet format which means you likely copied it from somewhere. If you actually made it, please format it correctly with codeblocks and not in bookmarklet format. (I can’t really read your code.)
```js
Your code here
```
2 Likes
Welcome to the community also!
2 Likes
var DELAY = 1;
var autoClickerStyleElement = document.createElement("style");
autoClickerStyleElement.innerHTML = "* { cursor: crosshair!important; }";
document.body.appendChild(autoClickerStyleElement);
function addClicker(e) {
if (!e.isTrusted) {
return;
}
if (e.target.classList.contains("auto - clicker - target")) {
e.target.classList.remove("auto - clicker - target");
} else {
e.target.classList.add("auto - clicker - target");
}
document.body.removeChild(autoClickerStyleElement);
document.body.removeEventListener("click", addClicker);
e.preventDefault();
autoClick(e.target);
}
function autoClick(element) {
if (element.classList.contains("auto - clicker - target")) {
element.click();
setTimeout(function () {
autoClick(element);
}, DELAY);
}
}
document.body.addEventListener("click", addClicker, 0);
@CONNORSEGER CtrlShiftJ to see the error:
Uncaught DOMException: Failed to execute 'add' on 'DOMTokenList': The token provided ('auto - clicker - target') contains HTML space characters, which are not valid in tokens.
Classes are tokens so you can’t have spaces
1 Like
Wouldn’t it be better to use setInterval
rather than a recursive setTimeout
? Also this seems to click on the body or something? Either way, maybe a query selector would be better so you could directly target the auto - clicker - target
class:
const elements = Array.from(document.querySelectorAll(".auto - clicker - target"));
1 Like