Wednesday, October 16, 2019

nbgitpuller bookmarklet

Using nbgitpuller with JupyterHub to distribute notebooks from GitHub, I got tired of manually formatting the URLs or using a link generator. So here's a basic bookmarklet that automatically generates nbgitpuller links for our CallystoHub:

javascript:(function(){var url=location.href;var res=url.split("/");var site=res[2];var user=res[3];var repo=res[4];var treeBlob=res[5];var branch=res[6];var nbgitputllerUrl="https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=";if(site=="github.com"){if(treeBlob){var urlpath="notebooks/"+repo+url.substring(url.indexOf(branch)+branch.length);nbgitputllerUrl+="https://github.com/"+user+"/"+repo+"&branch="+branch+"&urlpath="+urlpath;}else{nbgitputllerUrl+=url;}}window.prompt("Callysto nbgitpuller link",nbgitputllerUrl);})();

If you're not familiar with bookmarklets, they're basically bits of Javascript in the URL portion of a browser bookmark. To set one up, drag this link to your bookmark bar/menu:

CallystoGitPuller

Then when you are on a GitHub page you can click that bookmark and it will pop up a prompt with an nbgitpuller link to open that GitHub notebook or repository in CallystoHub.

Here is the code as a GitHub gist if you'd like to make your own and perhaps use JavaScript Cruncher to condense it to a single URL-encoded link.

Edit:

I've also posted about a similar bookmarklet to open notebooks in Colab.

No comments: