Add short link button for code

This commit is contained in:
Jacob Strieb 2019-06-30 03:07:52 -07:00
parent 14beaf04b9
commit b72caa0b91
2 changed files with 27 additions and 7 deletions

View File

@ -63,9 +63,6 @@ function update() {
// Update the URL for the "Get Link" button
document.getElementById("getLinkLink").href = getViewLink(html);
// Update the URL for the "Short Link" button
document.getElementById("url").value = getViewLink(html);
// Update the download link
document.getElementById("downloadLink").href = `data:text/html,${html}`
@ -73,7 +70,29 @@ function update() {
window.frames[0].location.replace(`data:text/html,${html}`);
}
/* Show a prompt with the HTML so the user can copy the code */
/* Set the TinyUrl form hidden 'url' field to the view URL */
function setViewUrl() {
var data = {
"css" : document.getElementById("css").value,
"js" : document.getElementById("javascript").value,
"html" : document.getElementById("html").value
};
var html = encodeURIComponent(getHTML(data));
// Update the URL for the "Short Link" button
document.getElementById("url").value = getViewLink(html);
}
/* Set the TinyUrl form hidden 'url' field to the code URL */
function setCodeUrl() {
document.getElementById("url").value = window.location.href;
}
/* Show a prompt with the HTML page data so the user can copy the code */
function showCopyCodePrompt() {
var data = {
"css" : document.getElementById("css").value,

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Create and edit URL pages</title>
<title>URL Pages Editor</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="editor.js" type="text/javascript"></script>
</head>
@ -18,9 +18,10 @@
<form action="http://tinyurl.com/create.php" method="get" target="_blank">
<input type="hidden" id="source" name="source" value="indexpage">
<input type="hidden" name="url" id="url" />
<button>Get Short Link</button>
<button onclick="setCodeUrl()">Get Short Link to Editor</button>
<button onclick="setViewUrl()">Get Short Link to Publish</button>
</form>
<button><a id="getLinkLink" href="" target="_blank">Get Link</a></button>
<button><a id="getLinkLink" href="" target="_blank">Get Link to Publish</a></button>
<button onclick="showCopyCodePrompt()">Copy Code</button>
<button><a id="downloadLink" href="" target="_blank" download="export.html">Download Code</a></button>
</div>