Skip to content

Instantly share code, notes, and snippets.

@joshuabaker
Created September 25, 2024 14:45
Show Gist options
  • Save joshuabaker/e2693178674e3e6e9f133f8eb8f9d12c to your computer and use it in GitHub Desktop.
Save joshuabaker/e2693178674e3e6e9f133f8eb8f9d12c to your computer and use it in GitHub Desktop.
Hide Chrome link preview for screen recording

Generate bookmarket using this tool.

(function() {
  const isNextApp = !!document.getElementById("__next");

  function hasUserDefinedCursor(link) {
    for (let sheet of document.styleSheets) {
        try {
            for (let rule of sheet.cssRules) {
                if (rule instanceof CSSStyleRule && link.matches(rule.selectorText)) {
                    if (rule.style.cursor) {
                        return true;
                    }
                }
            }
        } catch (e) {
            // Catch any potential cross-origin stylesheet access issues
        }
    }
    return false;
}

  function processLinks() {
    document.querySelectorAll("a[href]").forEach(link => {
        const url = link.href;
        link.removeAttribute("href");

        if (isNextApp) {
          link.addEventListener("click", () => window.history.pushState({}, "", url));
        } else {
          link.addEventListener("click", () => window.location = url);
        }

        if (!hasUserDefinedCursor(link)) {
          link.style.cursor = "pointer";
        }
    });
  }

  const observer = new MutationObserver(processLinks);
  observer.observe(document.documentElement, { childList: true, subtree: true });

  processLinks();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment