Skip to content

Commit 17937b2

Browse files
committed
Use versioned API with (hopefully) shorter URLs
1 parent 7848df1 commit 17937b2

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

api.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
* Global Variables
1313
******************************************************************************/
1414

15-
const LATEST_API_VERSION = "0.0.1";
16-
// const LATEST_API_VERSION = "0.2.0";
15+
const LATEST_API_VERSION = "0.2.0";
1716

1817
var apiVersions = {};
1918

@@ -31,12 +30,19 @@ apiVersions["0.2.0"] = {
3130
getViewLink: function(pageData) {
3231
var urlData = {
3332
version: this.VERSION,
33+
compressed: false,
34+
body: pageData,
3435
};
3536

3637
const hashObject = b64.encode(JSON.stringify(urlData));
3738
return `http://jstrieb.github.io/urlpages/#${hashObject}`;
3839
},
3940

41+
/* Return the page data from the object */
42+
decode: function(urlData) {
43+
return urlData.body;
44+
},
45+
4046
}
4147

4248

editor/editor.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function setViewUrl() {
5050
"html" : document.getElementById("html").value
5151
};
5252

53-
var html = encodeURIComponent(getHTML(data));
53+
var html = getHTML(data);
5454

5555
// Update the URL for the "Short Link" button
5656
document.getElementById("url").value = api.getViewLink(html);
@@ -118,7 +118,7 @@ function update() {
118118
"html" : document.getElementById("html").value
119119
};
120120

121-
var html = encodeURIComponent(getHTML(data));
121+
var html = getHTML(data);
122122

123123
// Save encoded page data to the URL
124124
window.location.hash = "#" + b64.encode(JSON.stringify(data));
@@ -130,5 +130,5 @@ function update() {
130130
document.getElementById("downloadLink").href = `data:text/html,${html}`
131131

132132
// Update the <iframe> to display the generated page
133-
window.frames[0].location.replace(`data:text/html;charset=utf-8;base64,${b64.encode(decodeURIComponent(html))}`);
133+
window.frames[0].location.replace(`data:text/html;charset=utf-8;base64,${b64.encode(html)}`);
134134
}

index.html

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<noscript>JavaScript is required to convert the URL into a usable web page.</noscript>
77

88
<script type="text/javascript" src="b64.js"></script>
9+
<script type="text/javascript" src="api.js"></script>
910
<script type="text/javascript">
1011
if (window.location.hash) {
1112
// Try to get page data from the URL if possible

0 commit comments

Comments
 (0)