-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit.js
64 lines (59 loc) · 1.68 KB
/
init.js
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
// http://localhost:8081/?gist=660571356ec5eb1da7fad67f1daef979
import { myCode1Mirror } from './edit.js'
function contentFromResponse(gist) {
fetch('https://api.github.com/gists/' + gist)
.then(resp => resp.json())
.then(function (resp) {
var files = resp.files;
var content = [];
for (var file in files) {
content.push(files[file].content)
}
if (content.length > 0) {
myCode1Mirror.setValue(content[0])
}
});
}
;
function queryHash() {
var qd = {};
location.search.substr(1).split("&").forEach(function (item) {
var sIndex = item.indexOf('=')
var k = item.substring(0, sIndex)
var v;
if (k === 'code') {
v = decodeURIComponent(atob(item.substring(sIndex + 1)));
} else {
v = decodeURIComponent((item.substring(sIndex + 1)));
}
// var s = item.split("=")
// , k = s[0]
// , v = s[1] && decodeURIComponent(s[1]);
(k in qd) ? qd[k].push(v) : qd[k] = [v]
});
if (qd.gist) {
if (qd.gist[0]) {
return contentFromResponse(qd.gist[0].replace(/^\/+|\/+$/gm, ''));
} else {
return contentFromResponse(qd.gist.replace(/^\/+|\/+$/gm, ''));
}
} else if (qd.code) {
try {
if(qd.code[0]){
myCode1Mirror.setValue(qd.code[0])
}
} catch (e) {
console.error(e)
}
}
else {
return
}
}
// function loadGist() {
// var gist = queryHash()
// if (gist) {
// contentFromResponse(gist)
// }
// }
queryHash()