Skip to content

Instantly share code, notes, and snippets.

@grrowl
Created May 10, 2016 07:46
Show Gist options
  • Save grrowl/df14cbca50f42a5bffea51902033daf0 to your computer and use it in GitHub Desktop.
Save grrowl/df14cbca50f42a5bffea51902033daf0 to your computer and use it in GitHub Desktop.
GitHub: click anywhere on the "merge message" (with disabled button) and it'll wait until the button enables and click it for you.
(function () {
function handleLoaded() {
var butan = document.querySelector('.merge-message .btn[disabled]')
var checkTimer;
if (butan) {
butan.parentElement.addEventListener('click', function handleClick(event) {
if (checkTimer) {
// already checking
return
}
checkTimer = setInterval(function () {
if (butan.attributes.getNamedItem('disabled')) {
// still disabled
butan.style.outline = (Math.random() * 10)+ 'px outset orange'
} else {
// success -- click the button with our previous event
butan.style.outline = '2px inset green'
butan.dispatchEvent(event)
clearInterval(checkTimer)
}
}, 500)
}, false)
}
}
window.addEventListener('load', handleLoaded)
document.addEventListener('pjax:success', handleLoaded)
})()
@grrowl
Copy link
Author

grrowl commented Jun 3, 2016

Although we hook on load and pjax:success, there's some additional JS re-rendering the button, so this won't work after new commits are added live, for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment