-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.html
169 lines (158 loc) · 8.09 KB
/
demo.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>gistachio demo</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.2/normalize.min.css">
<style>
body {
margin: 3em;
}
textarea {
font-family: monospace,monospace; /*http://goo.gl/90S3wN*/
font-size: 10pt;
line-height: 1;
width: 100%;
max-width: 140ch;
height: 30em;
overflow: scroll;
display: block;
margin: 1.5em 0;
white-space: pre;
word-wrap: normal;
}
</style>
<script src="//stuartpb.github.io/loquate/loquate.js"></script>
</head>
<body>
<h1>gistachio demo</h1>
<div>
<p id="example-goes-here">
</p>
<p id="github-login-prompt">
The form below will create an anonymous gist;
<a href="https://github.com/login/oauth/authorize?client_id=b1b61eb74810488f2135&scope=gist">log in to GitHub</a> to save a gist to your account
</p>
<form>
<h3>gistachio-is-cool.txt</h3>
<textarea id="gist-content" spellcheck="false">
tttt tttt iiii
ttt:::t ttt:::t i::::i
t:::::t t:::::t iiii
t:::::t t:::::t
ttttttt:::::ttttttt eeeeeeeeeeee ssssssssss ttttttt:::::ttttttt iiiiiiinnnn nnnnnnnn ggggggggg ggggg
t:::::::::::::::::t ee::::::::::::ee ss::::::::::s t:::::::::::::::::t i:::::in:::nn::::::::nn g:::::::::ggg::::g
t:::::::::::::::::t e::::::eeeee:::::eess:::::::::::::s t:::::::::::::::::t i::::in::::::::::::::nn g:::::::::::::::::g
tttttt:::::::tttttt e::::::e e:::::es::::::ssss:::::stttttt:::::::tttttt i::::inn:::::::::::::::ng::::::ggggg::::::gg
t:::::t e:::::::eeeee::::::e s:::::s ssssss t:::::t i::::i n:::::nnnn:::::ng:::::g g:::::g
t:::::t e:::::::::::::::::e s::::::s t:::::t i::::i n::::n n::::ng:::::g g:::::g
t:::::t e::::::eeeeeeeeeee s::::::s t:::::t i::::i n::::n n::::ng:::::g g:::::g
t:::::t tttttte:::::::e ssssss s:::::s t:::::t tttttt i::::i n::::n n::::ng::::::g g:::::g
t::::::tttt:::::te::::::::e s:::::ssss::::::s t::::::tttt:::::ti::::::i n::::n n::::ng:::::::ggggg:::::g
tt::::::::::::::t e::::::::eeeeeeee s::::::::::::::s tt::::::::::::::ti::::::i n::::n n::::n g::::::::::::::::g
tt:::::::::::tt ee:::::::::::::e s:::::::::::ss tt:::::::::::tti::::::i n::::n n::::n gg::::::::::::::g
ttttttttttt eeeeeeeeeeeeee sssssssssss ttttttttttt iiiiiiii nnnnnn nnnnnn gggggggg::::::g
g:::::g
gggggg g:::::g
g:::::gg gg:::::g
g::::::ggg:::::::g
gg:::::::::::::g
ggg::::::ggg
gggggg
</textarea>
<button type="button" id="create-gist">Create new Gist</button>
</form>
</div>
<script src="gistachio.js"></script>
<script>
/* global gistachio */
var exampleId = '30747828d7ce3c99852e';
var authToken = null;
function reportGithubLoginError(err) {
console.error(err);
document.getElementById("github-login-prompt").textContent =
"Something went wrong when signing into GitHub. Check the console for errors.";
}
function onReqLoad(evt) {
try {
var body = JSON.parse(req.responseText);
// Apparently the login API will return 200 OK when there's a problem.
// That or it's just a bug in the proxy I'm using.
if (req.status < 400 && !body.error) {
if (body.scope.split(',').indexOf('gist') != -1) {
authToken = body.access_token;
document.getElementById("github-login-prompt").textContent =
'The form below will create a public gist owned by you.';
} else {
document.getElementById("github-login-prompt").innerHTML =
'You appear to have signed in to GitHub without giving this demo write access to gists; '+
'<a href="https://github.com/login/oauth/authorize?client_id=b1b61eb74810488f2135&scope=gist">try logging in again</a>';
}
} else {
reportGithubLoginError(body);
}
} catch (err) {
reportGithubLoginError(err);
}
}
if (location.query && location.query.code) {
var req = new XMLHttpRequest();
req.addEventListener('load', onReqLoad);
req.addEventListener('error', reportGithubLoginError);
req.addEventListener('abort', reportGithubLoginError);
req.addEventListener('timeout', reportGithubLoginError);
// https://github.com/isaacs/github/issues/330
req.open('POST', 'https://cors-anywhere.herokuapp.com/https://github.com/login/oauth/access_token', true);
req.setRequestHeader('Accept', 'application/json');
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send('code=' + encodeURIComponent(location.query.code) +
'&client_id=b1b61eb74810488f2135' +
'&client_secret=4e28b8427970acb4007495626c8e31dd28d5ebc6');
/* *\
################################################################
################################################################
################################################################
################################################################
######## ########
######## I T ' S A S E C R E T ########
######## T O E V E R Y B O D Y . ########
######## ########
######## ,(*; }..{ ,(*; ########
######## (o2) {--} (o2) ########
######## ########
######## /\ ########
######## \/ ########
######## ########
######## ########
######## ########
######## ########
############################ ############################
############################ ############################
############################ ############################
############################ ############################
\* */
}
gistachio.getFiles(exampleId, function(err,files) {
if(err) {
console.error(err);
} else {
document.getElementById('example-goes-here').textContent =
files['example.txt'];
}
});
document.getElementById('create-gist').addEventListener('click',
function createExampleGist() {
gistachio.postFiles({
'gistachio-is-cool.txt':
document.getElementById('gist-content').value
}, {accessToken: authToken, public: !!authToken}, function(err, gistId) {
if(err) {
console.error(err);
} else {
location.href = 'https://gist.github.com/' + gistId;
}
});
});
</script>
</body>
</html>