Skip to content

Instantly share code, notes, and snippets.

@daneov
Last active January 2, 2018 13:09
Show Gist options
  • Save daneov/07cdc6feb11a248185113be001d77bec to your computer and use it in GitHub Desktop.
Save daneov/07cdc6feb11a248185113be001d77bec to your computer and use it in GitHub Desktop.
Getting notified when a block is found on pool.sumokoin.ch
$('#poolLastBlockFound').on('DOMSubtreeModified', function(x) {
var blockFoundText="1 minute";
if (x.target.innerHTML.includes(blockFoundText)) {
alert('Block found!');
}
})
// OR
var elementId = "poolLastBlockFound";
var stringToFind = "1 minute ago";
function containsBlock(value) {
return value.indexOf(stringToFind) != -1;
}
function blockFoundIn(elements) {
for(var adjustedNode of elements) {
if (containsBlock(adjustedNode.textContent)) {
return true;
}
}
return false;
}
var element = document.getElementById(elementId);
var config = { attributes: true, attributeOldValue: true, childList: true };
// Callback function to execute when mutations are observed
var callback = function(mutationsList) {
for(var mutation of mutationsList) {
if (mutation.type == 'childList') {
var blockFound = blockFoundIn(mutation.addedNodes);
blockFound &= !blockFoundIn(mutation.removedNodes);
}
if (blockFound) {
alert('We found a block!');
}
}
};
// Create an observer instance linked to the callback function
var observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(element, config);
@jeroenev
Copy link

jeroenev commented Jan 2, 2018

👍

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