paintd

Untitled

Sep 17th, 2024 (edited)
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. // Function to auto-click all elements matching a selector
  2. function autoClicker(selector, interval) {
  3. setInterval(() => {
  4. const elements = document.querySelectorAll(selector);
  5. if (elements.length > 0) {
  6. elements.forEach((element, index) => {
  7. // Manually dispatch a click event on the element
  8. const event = new MouseEvent('click', {
  9. bubbles: true, // Allows the event to propagate up the DOM
  10. cancelable: true, // Indicates whether the event can be canceled
  11. view: window
  12. });
  13. element.dispatchEvent(event); // Simulate the click
  14. console.log(`Dispatched click event for element ${index + 1} of ${elements.length}: ${selector}`);
  15. });
  16. } else {
  17. console.log(`No elements found for selector: ${selector}`);
  18. }
  19. }, interval);
  20. }
  21.  
  22. // Call the function with a CSS selector and interval
  23. autoClicker('.css-ie9j0x', 200); // Click every 200 ms
  24.  
Advertisement
Add Comment
Please, Sign In to add comment