really hard to understand the logic what the statements above do. Looks like it's detecting if link points to the same document, could you add the comment about that?

I think `isLink = (evt.target.href.replace(/#.*$/, '') === window.location.href.replace(/#.*$/, ''));` will be simpler to understand