-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
42 lines (32 loc) · 893 Bytes
/
app.js
File metadata and controls
42 lines (32 loc) · 893 Bytes
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
var gistID = "gistidjkhdsakjhfkjsadhf";
var defaultURL = "http://example.com";
var getFirstFile = function (files) {
for (var file in files) {
return files[file];
}
};
var getLinks = function (file) {
return JSON.parse(file.content).links;
};
var redirectToDefault = function () {
window.location.href = defaultURL;
};
var getHash = function () {
return window.location.hash.replace("#","");
};
var display404 = function () {
$("body").text("404: Short link not found");
};
if(window.location.hash) {
$.get( "https://api.github.com/gists/"+gistID, function( data ) {
var links = getLinks(getFirstFile(data.files));
if (links[getHash()] != null) {
window.location.href = links[getHash()].url;
}
else {
display404();
}
});
} else {
redirectToDefault();
}