Last active
January 2, 2018 13:09
-
-
Save daneov/07cdc6feb11a248185113be001d77bec to your computer and use it in GitHub Desktop.
Getting notified when a block is found on pool.sumokoin.ch
This file contains 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
$('#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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍