-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
86 lines (79 loc) · 5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Open in Jupyter Link Generators</title>
<style>
body {background-color: #FFFFFF;}
h1 {color: #F26722;}
button {background-color: #6F4A9E; color: #FFFFFF; cursor: pointer;}
link {color: #5f68B0;}
#inputs {margin-bottom: 10px;}
#buttons {margin-bottom: 10px;}
#outputUrl {margin-bottom: 10px;}
</style>
</head>
<body>
<h1>Open in Jupyter Link Generators</h1>
<div id="inputs">
<input type="hidden" id="serverUrl" size="70" placeholder="https://callysto.github.io/jupyterlite/lab/index.html">
<input type="text" id="notebookUrl" size="100" placeholder="notebook URL from GitHub">
</div>
<div id="buttons">
<button id="jupyterliteButton">Open in JupyterLite</button>
<button id="colabButton">Open in Colab</button>
<button id="callystoButton">Open in Callysto Hub</button>
</div>
<div id="outputUrl"></div>
<hr>
<br>
<h1>Bookmarklets</h1>
<p>Drag these links to your bookmarks bar to create <a href="https://en.wikipedia.org/wiki/Bookmarklet">bookmarklets</a> that will open the current GitHub notebook in JupyterLite, Colab, or Callysto Hub.</p>
<p><a href='javascript:(()=>{var site=location.href.split("github.com/")[1].replace(/\/blob\//,"/"");var newUrl="https://callysto.github.io/jupyterlite/lab/index.html?fromURL=https://raw.githubusercontent.com/"+site;window.prompt("Open in JupyterLite Link",newUrl);})();''>Open in JupyterLite</a></p>
<p></p><a href='javascript:(function(){var url=location.href;var res=url.split("github.com/");var site=res[1];colabGitUrl="https://colab.research.google.com/github/"+site;window.prompt("Colab gitpuller link",colabGitUrl);})();'>Open in Colab</a></p>
<p></p><a href='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 subPath=url.substring(url.indexOf(branch)+branch.length+1);nbgitputllerUrl+=encodeURIComponent("https://github.com/"+user+"/")+repo+"&branch="+branch+"&subPath="+subPath+"&depth=1";}else{nbgitputllerUrl+=url;}}window.prompt("Callysto nbgitpuller link",nbgitputllerUrl);})();'>Open in Callysto Hub</a></p>
<script>
document.getElementById('jupyterliteButton').addEventListener('click', openInJupyterLite);
function openInJupyterLite() {
let serverUrl = document.getElementById('serverUrl').value;
if (serverUrl === '') {
serverUrl = 'https://callysto.github.io/jupyterlite/lab/index.html';
}
let notebookUrl = document.getElementById('notebookUrl').value;
notebookUrl = "https://raw.githubusercontent.com/" + notebookUrl.trim().split("github.com/")[1].replace(/\/blob\//,'/');
const jupyterLiteUrl = serverUrl + '?fromURL=' + notebookUrl;
document.getElementById('outputUrl').innerHTML = '<a href="'+jupyterLiteUrl+'" target="_blank">'+jupyterLiteUrl+'</a>';
}
document.getElementById('colabButton').addEventListener('click', openInColab);
function openInColab() {
// https://github.com/callysto/hackathon/blob/master/HackathonNotebooks/data.ipynb
// https://colab.research.google.com/github/callysto/hackathon/blob/master/HackathonNotebooks/data.ipynb
let notebookUrl = document.getElementById('notebookUrl').value;
notebookUrl = notebookUrl.trim().split("github.com/")[1];
const colabUrl = 'https://colab.research.google.com/github/'+notebookUrl;
document.getElementById('outputUrl').innerHTML = '<a href="'+colabUrl+'" target="_blank">'+colabUrl+'</a>';
}
document.getElementById('callystoButton').addEventListener('click', openInCallysto);
function openInCallysto() {
let notebookUrl = document.getElementById('notebookUrl').value;
let res = notebookUrl.split("/");
let site = res[2];
let user = res[3];
let repo = res[4];
let treeBlob = res[5];
let branch = res[6];
let callystoUrl = "https://hub.callysto.ca/jupyter/hub/user-redirect/git-pull?repo=";
if (site == "github.com") {
if (treeBlob) {
let subPath = notebookUrl.substring(notebookUrl.indexOf(branch)+branch.length+1);
callystoUrl += encodeURIComponent("https://github.com/"+user+"/")+repo+"&branch="+branch+"&subPath="+subPath+"&depth=1";
} else {
callystoUrl += notebookUrl;
}
document.getElementById('outputUrl').innerHTML = '<a href="'+callystoUrl+'" target="_blank">'+callystoUrl+'</a>';
}
}
</script>
</body>
</html>