Created
October 27, 2019 08:39
-
-
Save lelinhtinh/1e329713c4215b3609882ddc2ddd3b75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
// https://stackoverflow.com/a/52549234 | |
function simulateMouseClick(targetNode) { | |
function triggerMouseEvent(targetNode, eventType) { | |
var clickEvent = document.createEvent('MouseEvents'); | |
clickEvent.initEvent(eventType, true, true); | |
targetNode.dispatchEvent(clickEvent); | |
} | |
["mouseover", "mousedown", "mouseup", "click"].forEach(function(eventType) { | |
triggerMouseEvent(targetNode, eventType); | |
}); | |
} | |
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver | |
const config = { | |
attributes: true, | |
childList: true, | |
subtree: true | |
}; | |
const callback = function(mutationsList, observer) { | |
for (let mutation of mutationsList) { | |
if (mutation.type === 'attributes') { | |
if ((mutation.target.classList.contains('view-go') || mutation.target.classList.contains('view-result'))) { | |
simulateMouseClick(targetNode); | |
} else { | |
targetNode.querySelector('h1 div').textContent = 'Wait for [ ᴼ ▃ ᴼ ]_/¯'; | |
} | |
} | |
if (targetNode.querySelector('.hero-button') !== null) { | |
observer.disconnect(); | |
} | |
} | |
}; | |
const observer = new MutationObserver(callback); | |
// [ ᴼ ▃ ᴼ ]_/¯ | |
const targetNode = document.querySelector('.reaction-time-test'); | |
if (targetNode === null) return; | |
observer.observe(targetNode, config); | |
simulateMouseClick(targetNode); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment