imported mutation observer code from uBlock: more efficient, robust