-
Notifications
You must be signed in to change notification settings - Fork 3
/
nbv.html
58 lines (51 loc) · 1.98 KB
/
nbv.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
<html lang="en">
<head>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/themes/prism.min.css'/>
<script src='https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.6/marked.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/prism.min.js' data-manual></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/components/prism-python.min.js' data-manual></script>
<script src="https://rawgit.com/kokes/nbviewer.js/master/lib/nbv.js"></script>
<link rel='stylesheet' src="https://rawgit.com/kokes/nbviewer.js/master/lib/nbv.css">
</head>
<body>
<div id="notebook"></div>
<script>
<!-- https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
-->
var urlParams;
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
if(urlParams['notebook_name'] == null) {
urlParams['notebook_name'] = "sorry.ipynb"
}
var request = new XMLHttpRequest();
console.log(urlParams['notebook_name']);
request.open('GET', urlParams['notebook_name'], true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
console.log("notebook loaded");
var data = JSON.parse(request.responseText);
var target = document.getElementById("notebook");
nbv.render(data, target);
} else {
// We reached our target server, but it returned an error
console.log("notebook not found error");
}
};
request.onerror = function() {
// There was a connection error of some sort
console.log("connection error");
};
request.send();
</script>
</body>
</html>