Skip to content

Instantly share code, notes, and snippets.

@kkweon
Last active November 9, 2017 09:48
Show Gist options
  • Save kkweon/d6dbfe78c1af4ecb23ebe54fce092dfb to your computer and use it in GitHub Desktop.
Save kkweon/d6dbfe78c1af4ecb23ebe54fce092dfb to your computer and use it in GitHub Desktop.
Jupyter Notebook Viewer boomarklet

Jupyter Notebook Viewer

Nbviewer?

  • Vieweing ipynb files on Nbviewer is so much faster than on the Github.

No more waiting https://i.imgur.com/TnYVaVm.png

Get started

1. Add a bookmark in Chrome/Safari with the following URL

javascript:(function()%7Bjavascript%3A(function()%20%7Bvar%20currentUrl%20%3D%20window.location.href.split(%22%2F%22)%3Bif%20(currentUrl.includes(%22github.com%22))%20%7Bvar%20jupyterUrl%20%3D%20%22https%3A%2F%2Fnbviewer.jupyter.org%2Fgithub%2F%22%20%2B%20currentUrl.slice(3).join(%22%2F%22)%3Bwindow.location%20%3D%20jupyterUrl%3B%7D%20else%20if%20(currentUrl.includes(%22gist.github.com%22))%20%7Bvar%20jupyterUrl%20%3D%20%22https%3A%2F%2Fnbviewer.jupyter.org%2Fgist%2F%22%20%2B%20currentUrl.slice(3).join(%22%2F%22)%3Bwindow.location%20%3D%20jupyterUrl%3B%7Delse%20%7Balert(%22The%20current%20page%20does%20not%20contain%20github%20in%20its%20URL.%22)%3B%7D%7D)()%7D)()

If you are curious, it’s the following javascript but url encoded.

javascript:(function() {
var currentUrl = window.location.href.split("/");
if (currentUrl.includes("github.com")) {
   var jupyterUrl = "https://nbviewer.jupyter.org/github/" + currentUrl.slice(3).join("/");
   window.location = jupyterUrl;
} else if (currentUrl.includes("gist.github.com")) {
    var jupyterUrl = "https://nbviewer.jupyter.org/gist/" + currentUrl.slice(3).join("/");
    window.location = jupyterUrl;
}
  else {
  alert("The current page does not contain github in its URL.");
}
})();

2. Go to any ipynb page in github

3. Click the bookmark

https://i.imgur.com/7LmsxTH.png

4. Done

https://i.imgur.com/tw2myLv.png

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