let isListening = false;

export function listenForUrlChange(cb: (url: string) => void) {
  let currentUrl = window.location.href;

  function listen() {
    if (window.location.href !== currentUrl) {
      currentUrl = window.location.href;
      cb(currentUrl);
    }
    requestAnimationFrame(listen);
  }

  if (!isListening) {
    isListening = true;
    listen();
  }
}
