Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var board = document
- .getElementsByClassName("memory-test")[0]
- .firstChild
- .children[1]
- .firstChild
- .children[1]
- .firstChild;
- function triggerMouseEvent(node, eventType) {
- var clickEvent = document.createEvent('MouseEvents');
- clickEvent.initEvent(eventType, true, true);
- node.dispatchEvent(clickEvent);
- }
- function click(node) {
- triggerMouseEvent(node, "mousedown");
- triggerMouseEvent(node, "mouseup");
- triggerMouseEvent(node, "click");
- }
- var callback = (mutationList, observer) => {
- // check if the mutation is not the board changing size
- if (mutationList.length < board.childElementCount ** 2) {
- mutationList.forEach((mut) => {
- click(mut.target);
- })
- }
- }
- var ob = new MutationObserver(callback)
- ob.observe(board, {
- attributes: true,
- childList: true,
- subtree: true,
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement