mirror of
https://github.com/jstrieb/urlpages.git
synced 2024-12-22 05:42:16 +01:00
Use versioned API with (hopefully) shorter URLs
This commit is contained in:
parent
7848df1b1b
commit
17937b2db6
3 changed files with 12 additions and 5 deletions
10
api.js
10
api.js
|
@ -12,8 +12,7 @@
|
|||
* Global Variables
|
||||
******************************************************************************/
|
||||
|
||||
const LATEST_API_VERSION = "0.0.1";
|
||||
// const LATEST_API_VERSION = "0.2.0";
|
||||
const LATEST_API_VERSION = "0.2.0";
|
||||
|
||||
var apiVersions = {};
|
||||
|
||||
|
@ -31,12 +30,19 @@ apiVersions["0.2.0"] = {
|
|||
getViewLink: function(pageData) {
|
||||
var urlData = {
|
||||
version: this.VERSION,
|
||||
compressed: false,
|
||||
body: pageData,
|
||||
};
|
||||
|
||||
const hashObject = b64.encode(JSON.stringify(urlData));
|
||||
return `http://jstrieb.github.io/urlpages/#${hashObject}`;
|
||||
},
|
||||
|
||||
/* Return the page data from the object */
|
||||
decode: function(urlData) {
|
||||
return urlData.body;
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ function setViewUrl() {
|
|||
"html" : document.getElementById("html").value
|
||||
};
|
||||
|
||||
var html = encodeURIComponent(getHTML(data));
|
||||
var html = getHTML(data);
|
||||
|
||||
// Update the URL for the "Short Link" button
|
||||
document.getElementById("url").value = api.getViewLink(html);
|
||||
|
@ -118,7 +118,7 @@ function update() {
|
|||
"html" : document.getElementById("html").value
|
||||
};
|
||||
|
||||
var html = encodeURIComponent(getHTML(data));
|
||||
var html = getHTML(data);
|
||||
|
||||
// Save encoded page data to the URL
|
||||
window.location.hash = "#" + b64.encode(JSON.stringify(data));
|
||||
|
@ -130,5 +130,5 @@ function update() {
|
|||
document.getElementById("downloadLink").href = `data:text/html,${html}`
|
||||
|
||||
// Update the <iframe> to display the generated page
|
||||
window.frames[0].location.replace(`data:text/html;charset=utf-8;base64,${b64.encode(decodeURIComponent(html))}`);
|
||||
window.frames[0].location.replace(`data:text/html;charset=utf-8;base64,${b64.encode(html)}`);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<noscript>JavaScript is required to convert the URL into a usable web page.</noscript>
|
||||
|
||||
<script type="text/javascript" src="b64.js"></script>
|
||||
<script type="text/javascript" src="api.js"></script>
|
||||
<script type="text/javascript">
|
||||
if (window.location.hash) {
|
||||
// Try to get page data from the URL if possible
|
||||
|
|
Loading…
Reference in a new issue