Skip to content

Instantly share code, notes, and snippets.

@NullDev
Last active July 6, 2022 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NullDev/a5f84e7a7d96c7b3a4eb4ee3ce4f0ddf to your computer and use it in GitHub Desktop.
Save NullDev/a5f84e7a7d96c7b3a4eb4ee3ce4f0ddf to your computer and use it in GitHub Desktop.
Repo to GitHub.io Page Bookmarklet

Repository to GitHub.io Page Bookmarklet

This bookmarklet automatically converts the current GitHub Repo URL to the GitHub.io Page.

  • Create a new Bookmark and name it "Repo to GH Page" or something.
  • Paste this as the URL:
    javascript:(()=>{const{href:a}=window.location;if(a.startsWith("https://github.com/")){const b=(a.split("/").pop()||"").split("#")[0];if(b){const c=(a.split("/")[3]||"").split(".")[0];c&&(window.location.href=`https://${c}.github.io/${b}`)}}})();
  • Move it to your bookmarks bar (optional)

Source Code:

(() => {
    "use strict";
    
    const { href } = window.location;
    if (!href.startsWith("https://github.com/")) return;
    
    const repo = (href.split("/").pop() || "").split("#")[0];
    if (!repo) return;

    const username = (href.split("/")[3] || "").split(".")[0];
    if (!username) return;

    window.location.href = `https://${username}.github.io/${repo}`;
})();

GitHub.io Page to Repository Bookmarklet

This bookmarklet is the reverse version of the one above. It automatically converts the current GitHub.io Page to the Repository URL.

  • Create a new Bookmark and name it "GH Page to Repo" or something.
  • Paste this as the URL:
    javascript:(()=>{const{href:a}=window.location;if(!a.includes("github.io"))return;const b=a.split("//")[1].split(".")[0];if(!b)return;let c=a.replace(`https://${b}.github.io/`,"");"/"===c.at(-1)&&(c=c.split("/")[0]);c&&(window.location.href=`https://github.com/${b}/${c}`)})();
  • Move it to your bookmarks bar (optional)

Source Code:

(() => {
    "use strict";
    
    const { href } = window.location;
    if (!href.includes("github.io")) return;

    const username = href.split("//")[1].split(".")[0];
    if (!username) return;

    let repo = href.replace(`https://${username}.github.io/`, ""); 
    if (repo.at(-1) === "/") repo = repo.split("/")[0];
    if (!repo) return;

    window.location.href = `https://github.com/${username}/${repo}`;
})();

Demo:

(click GIF to enlarge)

Screen Recording

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment