-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjson_frontend.html
More file actions
223 lines (190 loc) · 6 KB
/
json_frontend.html
File metadata and controls
223 lines (190 loc) · 6 KB
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
<html>
<head>
<title>JSON MSF Frontend</title>
<script>
function processMSF()
{
// parse the user's JSON string into an object
var item = JSON.parse(document.querySelector("#jsonbox").value);
return item;
}
function displayItem(item)
{
// now display the item's meta data to the user
document.querySelector("#title").innerHTML = item.title;
document.querySelector("#type").innerHTML = (!!item.type) ? item.type : "other";
document.querySelector("#description").innerHTML = (!!item.description) ? item.description : "";
var screenElem = document.querySelector("#screen");
screenElem.classList.add("hidden");
if( !!item.screen )
screenElem.src = item.screen;
var marqueeElem = document.querySelector("#marquee");
marqueeElem.classList.add("hidden");
if( !!item.marquee )
marqueeElem.src = item.marquee;
var previewElem = document.querySelector("#preview");
previewElem.classList.add("hidden");
if( !!item.preview && item.preview !== "" )
{
previewElem.href = item.preview;
previewElem.classList.remove("hidden");
}
var streamElem = document.querySelector("#stream");
streamElem.classList.add("hidden");
if( !!item.stream && item.stream !== "" )
{
streamElem.href = item.stream;
streamElem.classList.remove("hidden");
}
var referenceElem = document.querySelector("#reference");
referenceElem.classList.add("hidden");
if( !!item.reference && item.reference !== "" )
{
referenceElem.href = item.reference;
referenceElem.classList.remove("hidden");
}
var downloadElem = document.querySelector("#download");
downloadElem.classList.add("hidden");
if( !!item.download && item.download !== "" )
{
downloadElem.href = item.download;
downloadElem.classList.remove("hidden");
}
var nolaunchElem = document.querySelector("#nolaunch");
nolaunchElem.classList.add("hidden");
var fileimageElem = document.querySelector("#fileimage");
fileimageElem.classList.add("hidden");
var fileElem = document.querySelector("#file");
fileElem.classList.add("hidden");
if( item.file.indexOf("/") != -1 )
{
fileElem.href = item.file;
fileElem.classList.remove("hidden");
fileElem.innerHTML = "Launch Shortcut - <font class='link'>" + item.file + "</font>";
fileimageElem.src = item.file;
}
else
nolaunchElem.classList.remove("hidden");
}
function loaded(elem)
{
elem.classList.remove("hidden");
}
</script>
</head>
<body>
<form id="form">
JSON: <input type="text" id="jsonbox" autocomplete="off" placeholder="(Paste your MSF JSON here from the GitHub's README.md.)" /><input type="submit" value="Process MSF JSON" />
</form>
<hr />
<img id="fileimage" class="hidden" onload="loaded(this);" />
<img id="screen" class="hidden" onload="loaded(this);" />
<img id="marquee" class="hidden" onload="loaded(this);" />
<div id="title"></div>
<div id="type"></div>
<div id="description"></div>
<a id="preview" class="hidden" target="_blank">View Preview</a>
<a id="stream" class="hidden" target="_blank">View Stream</a>
<a id="reference" class="hidden" target="_blank">View Reference</a>
<a id="download" class="hidden" target="_blank">View Download</a>
<a id="file" class="hidden" target="_blank">Launch Shortcut</a>
<div id="nolaunch" class="hidden" target="_blank">This shortcut references a local file. The user is probably expected to resolve this shortcut's file target to a local file on their PC, or otherwise specify a file target that works for them in order to launch it.</div>
<script>
function submitForm()
{
if( !!document.activeElement && typeof document.activeElement.blur === "function" )
document.activeElement.blur();
// process & display the MSF item
var item = processMSF();
displayItem(item);
// update the URL for easy link sharing
history.replaceState({}, document.title, "?json=" + JSON.stringify(item));
}
var form = document.querySelector("#form");
form.addEventListener("submit", function(e)
{
submitForm();
e.preventDefault();
});
var jsonbox = document.querySelector("#jsonbox");
jsonbox.addEventListener("focus", function(e)
{
e.target.select();
});
jsonbox.focus();
function getParameterByName(name, url)
{
// method from http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
if (!url)
url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results)
return null;
if (!results[2])
return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
function checkForJSON()
{
var givenJSON = getParameterByName("json");
if( !!givenJSON )
{
jsonbox.value = givenJSON;
submitForm();
}
}
checkForJSON();
</script>
<style>
#jsonbox
{
width: 800px;
}
#title
{
font-size: 20pt;
}
#type
{
font-style: italic;
font-size: 12pt;
margin-bottom: 8px;
}
#description
{
width: 800px;
margin-bottom: 8px;
}
#download, #nolaunch, #preview, #stream, #reference, #file
{
display: block;
margin: 4px;
padding: 8px;
width: 800px;
border-radius: 8px;
border: 1px solid rgb(40, 40, 40);
}
#download:hover, #preview:hover, #stream:hover, #reference:hover, #file:hover
{
background-color: rgb(240, 240, 240);
}
#screen, #marquee, #fileimage
{
max-width: 200px;
max-height: 100px;
}
a
{
text-decoration: none;
font-weight: bold;
font-family: Arial;
}
.hidden
{
display: none !important;
}
</style>
</body>
</html>