-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
496 lines (434 loc) · 14.4 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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<!DOCTYPE html>
<html lang="en">
<head>
<title>Scrapbook Customizer</title>
<link rel="icon" type="image/png" href="https://assets.hackclub.com/icon-rounded.png" />
<link href="https://fonts.googleapis.com/css2?family=Fira+Code&family=Inter:wght@400;800&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.55.0/codemirror.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.55.0/codemirror.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.55.0/mode/css/css.js"></script>
</head>
<body>
<style>
body {
height: 100vh;
font-family: 'Inter', sans-serif;
margin: 0;
padding: 0;
}
h3 {
margin: unset;
}
.container {
display: inline-flex;
width: 100vw;
height: 94vh;
}
.col {
width: 50vw;
}
#editor,
.CodeMirror {
font-family: 'Fira Code', monospace;
resize: none;
overflow: auto;
width: 50vw;
height: 94vh;
padding: 0%;
margin: 0%;
outline: none;
border-style: none;
}
.header {
text-align: center;
font-family: 'Inter', sans-serif;
}
.left {
background-color: #0093c4;
background-image: url("Spinner-1s-200px.svg");
background-repeat: no-repeat;
background-attachment: local;
background-position: center;
}
.right {
background-color: #00c1fb;
}
#iframe {
outline: none;
border: 0%;
width: 50vw;
height: 94vh;
padding: 0%;
margin: 0%;
border-style: none;
}
.mainhead {
width: 25vw;
color: #1d201d;
line-height: 6vh;
z-index: 1;
}
.sechead1 {
width: 58vw;
background-color: red;
padding: 0%;
margin: 0%;
line-height: 6vh;
z-index: 2;
}
.sechead2 {
width: 7vw;
padding: 0%;
margin: 0%;
line-height: 6vh;
text-align: center;
cursor: pointer;
}
.sechead3 {
width: 10vw;
padding: 0%;
line-height: 6vh;
text-align: center;
cursor: pointer;
outline-color: #0093c44f;
outline-style: solid;
outline-width: 1px;
}
.head {
background-color: #00c1fb;
height: 6vh;
}
.sechead3>h5 {
margin: 0;
}
.sechead2:hover,
.sechead3:hover {
background-color: #0093c4;
}
.top {
display: inline-flex;
padding: 0%;
margin: 0%;
}
#scrappyuser {
resize: none;
overflow: none;
padding: 0%;
margin: 0%;
outline: none;
width: 100%;
height: 100%;
border: 0%;
border-style: none;
font-family: 'Inter', sans-serif;
line-height: 6vh;
font-size: small;
padding: 0% 0% 0% 1vh;
background-color: aliceblue;
}
.mainhead h3 {
padding: 0% 0% 0% 1vh;
}
/* The Modal (background) */
.modal {
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 100;
/* Sit on top */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.4);
/* Black w/ opacity */
-webkit-animation-name: fadeIn;
/* Fade in the background */
-webkit-animation-duration: 0.4s;
animation-name: fadeIn;
animation-duration: 0.4s
}
/* Modal Content */
.modal-content {
position: fixed;
bottom: 0;
background-color: #fefefe;
width: 100%;
-webkit-animation-name: slideIn;
-webkit-animation-duration: 0.4s;
animation-name: slideIn;
animation-duration: 0.4s
}
/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal-header {
padding: 2px 16px;
background-color: #00c1fb;
color: white;
}
.modal-body {
padding: 2px 16px;
}
/* Add Animation */
@-webkit-keyframes slideIn {
from {
bottom: -300px;
opacity: 0
}
to {
bottom: 0;
opacity: 1
}
}
@keyframes slideIn {
from {
bottom: -300px;
opacity: 0
}
to {
bottom: 0;
opacity: 1
}
}
@-webkit-keyframes fadeIn {
from {
opacity: 0
}
to {
opacity: 1
}
}
@keyframes fadeIn {
from {
opacity: 0
}
to {
opacity: 1
}
}
</style>
<div class="top">
<div class="head mainhead">
<h3>Scrapbook Customizer</h3>
</div>
<div class="head sechead1">
<textarea id="scrappyuser" rows="1" placeholder="Enter your Scrappy username here! (the part after scrapbook.hackclub.com/)"></textarea>
</div>
<div class="head sechead2" onclick="newUrl()">
<h3>Go</h3>
</div>
<div class="head sechead3" onclick="gistButton()">
<h5>Add to Gist</h5>
</div>
</div>
<div class="container">
<div class="left col" id="scrapbookspace">
<iframe id="iframe"></iframe>
</div>
<div class="right col">
<textarea id="editor" placeholder="Enter CSS here..."></textarea>
</div>
</div>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2 id="m-head-content">Modal Header</h2>
</div>
<div class="modal-body">
<p id="m-body-content">Some text in the Modal Body</p>
</div>
</div>
</div>
<script src="https://unpkg.com/github-api/dist/GitHub.bundle.min.js"></script>
<script>
// :)
console.log("Hey! Check this out on GitHub: https://github.com/jasonaa/scrapbook-customizer")
var scrappyuser = "jasonaa"
var url = "https://scrapbook.hackclub.com/" + scrappyuser
var frame = document.getElementById('iframe');
var doc, html;
var formdata = new FormData()
var token = ""
var modal = document.getElementById("myModal");
newUrl()
var editor = document.getElementById('editor');
editor.addEventListener("input", editPage);
var myCodeMirror = CodeMirror.fromTextArea(editor, {
mode: "css",
value: "/* Put your CSS here and see it previewed on the left! */",
lineWrapping: true,
lineNumbers: true
});
myCodeMirror.on("change", editPage)
frame.addEventListener("load", function() {
doc = frame.contentDocument;
html = doc.body.innerHTML;
})
// Execute a function when the user releases a key on the keyboard
document.getElementById("scrappyuser").addEventListener("keyup", function(event) {
// Number 13 is the "Enter " key on the keyboard
if (event.keyCode == 13) {
// Cancel the default action, if needed
event.preventDefault();
document.getElementById("scrappyuser").value = document.getElementById("scrappyuser").value.trim()
newUrl();
}
});
window.onload = function() {
try {
editor.value = localStorage.getItem("customCSS");
myCodeMirror.getDoc().setValue(localStorage.getItem("customCSS"))
console.log("Restored stored CSS")
editPage()
} catch {
console.log("No stored CSS")
}
authGitHub()
}
function gistButton() {
if (token != "") {
const octokit = new Octokit({
auth: token,
});
makeGist()
} else {
authGitHub(true)
}
}
function authGitHub(force = false) {
console.log("running authgithub")
const urlParams = new URLSearchParams(window.location.search);
console.log(urlParams)
if (urlParams.has('token')) {
token = urlParams.get('token')
makeGist()
} else if (force) {
window.location.href = "/customizer/api/callback"
}
if (urlParams.has('error')) {
document.getElementById('m-head-content').innerText = "Something went wrong!"
document.getElementById('m-body-content').innerText = error
modal.style.display = "block"
// When the user clicks on <span> (x), close the modal
document.getElementsByClassName("close")[0].onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
window.history.replaceState(null, null, window.location.pathname);
}
}
function makeGist() {
console.log("running makegist")
var files = {
'style.css': {
content: getCSS()
}
}
console.log(files)
var gh = new GitHub({
token: token
})
var gist = gh.getGist()
gist.create({
public: true,
description: "CSS uploaded by scrapbook.hackclub.com/customizer",
files: {
"style.css": {
content: getCSS()
}
}
}).then(function({
data
}) {
// Promises!
let createdGist = data;
return gist.read();
}).then(function({
data
}) {
let retrievedGist = data;
tmp(data)
});
function tmp(stuff) {
// Request finished. Do processing here.
try {
var gistUrl = stuff["files"]["style.css"]["raw_url"]
} catch (e) {
var gistUrl = ""
console.error(e)
console.log(stuff)
}
console.log("gistUrl: " + gistUrl)
// Get the modal
if (gistUrl == "") {
document.getElementById('m-head-content').innerText = "Uh oh!"
document.getElementById('m-body-content').innerText = `We were unable to create the gist. Response: ${this.response}`
} else {
document.getElementById('m-head-content').innerText = "Successfully created gist!"
document.getElementById('m-body-content').innerHTML = `The gist URL is <a href="${gistUrl}">${gistUrl}</a>. Now hop over to the #scrapbook-css channel in Slack and paste the link into a new message to apply it to your scrapbook!`
}
modal.style.display = "block"
// When the user clicks on <span> (x), close the modal
document.getElementsByClassName("close")[0].onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
window.history.replaceState(null, null, window.location.pathname);
xhr = null
}
}
function newUrl() {
console.log("loading scrapbook")
if (document.getElementById("scrappyuser").value == "") {
scrappyuser = "jasonaa"
} else {
scrappyuser = document.getElementById("scrappyuser").value
}
url = "https://scrapbook.hackclub.com/" + scrappyuser
frame.src = url
}
function getCSS() {
return myCodeMirror.getValue() || editor.value
}
function editPage() {
css = getCSS()
if (typeof(Storage) !== "undefined") {
// Code for localStorage/sessionStorage.
localStorage.setItem("customCSS", css);
}
doc.body.innerHTML = html + `<style>${css}</style>`;
}
</script>
</body>
</html>