Skip to main content

Bookmarklet to view source for a GitHub Pages site

Apr 7, 2023 · Last updated: Apr 11, 2023 ·
Posted in weblog#tech
Categories: javascript

Do you ever come across some site hosted on GitHub Pages with a URL like https://user.github.io/repo and you look around but the link to the source repository is nowhere to be found?

I have a bookmarklet that opens the source in a new tab directly. It works for GitLab Pages as well. Sometimes this comes in very handy:

javascript: (() => {
  const getRepo = (urlObj) => {
    const [user, site, ...rest] = urlObj.host.split('.');
    const repo = urlObj.pathname.split('/')[1] || `${user}.${site}.io`;
    return `https://${site}.com/${user}/${repo}`;
  };

  window.open(getRepo(location));
})();