Advertisement
Guest User

Untitled

a guest
Nov 30th, 2023
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var board = document
  2.     .getElementsByClassName("memory-test")[0]
  3.     .firstChild
  4.     .children[1]
  5.     .firstChild
  6.     .children[1]
  7.     .firstChild;
  8.  
  9. function triggerMouseEvent(node, eventType) {
  10.   var clickEvent = document.createEvent('MouseEvents');
  11.   clickEvent.initEvent(eventType, true, true);
  12.   node.dispatchEvent(clickEvent);
  13. }
  14.  
  15. function click(node) {
  16.   triggerMouseEvent(node, "mousedown");
  17.   triggerMouseEvent(node, "mouseup");
  18.   triggerMouseEvent(node, "click");
  19. }
  20.  
  21. var callback = (mutationList, observer) => {
  22.   // check if the mutation is not the board changing size
  23.   if (mutationList.length < board.childElementCount ** 2) {
  24.     mutationList.forEach((mut) => {
  25.       click(mut.target);
  26.     })
  27.   }
  28. }
  29. var ob = new MutationObserver(callback)
  30.  
  31. ob.observe(board, {
  32.     attributes: true,
  33.     childList: true,
  34.     subtree: true,
  35.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement