From becc28d51ccf7be469eba6f5b81a0ed7b1582261 Mon Sep 17 00:00:00 2001 From: Nicholas Jitkoff Date: Sun, 8 Jul 2018 08:17:48 -0700 Subject: [PATCH] Add base target to html content --- index.css | 5 +++ index.html | 81 ++++++----------------------------------------- index.js | 53 +++++++++++++++++++++++++++++++ manifest.appcache | 2 +- 4 files changed, 69 insertions(+), 72 deletions(-) create mode 100644 index.css create mode 100644 index.js diff --git a/index.css b/index.css new file mode 100644 index 0000000..74558a9 --- /dev/null +++ b/index.css @@ -0,0 +1,5 @@ + #iframe {border:none;position:absolute;top:0;left:0;width:100%;height:100%} + #edit {font-family:monospace; font-weight:bold;color:rgba(0,0,0,0.54); position:absolute;z-index:100;position:absolute;top:0.85em; right:1em; display:none;} + #edit:not(:hover) {text-decoration:none;} + #warning {position: absolute;border-radius:4px;background-color:#feecc2;padding:1em;font-size:16px;font-family:sans-serif;width:20em;z-index:100;top:10vh;left:50vw;margin-left:-10em;} + #warning:empty {display:none;} \ No newline at end of file diff --git a/index.html b/index.html index 283a03d..6ca615a 100644 --- a/index.html +++ b/index.html @@ -1,73 +1,12 @@ - - - - - - - - -edit -
- + + + +
+edit \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..0714efc --- /dev/null +++ b/index.js @@ -0,0 +1,53 @@ +var HEAD_TAGS = "PGJhc2UgdGFyZ2V0PSJfdG9wIj4K"; +var HEAD_TAGS_EXTENDED = "PG1ldGEgY2hhcnNldD0idXRmLTgiPjxtZXRhIG5hbWU9InZpZXdwb3J0IiBjb250ZW50PSJ3aWR0aD1kZXZpY2Utd2lkdGgiPjxiYXNlIHRhcmdldD0iX3RvcCI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj5ib2R5e21hcmdpbjowIGF1dG87cGFkZGluZzoxMnZtaW4gMTB2bWluO21heC13aWR0aDozNWVtO2xpbmUtaGVpZ2h0OjEuNWVtO2ZvbnQtZmFtaWx5OiAtYXBwbGUtc3lzdGVtLEJsaW5rTWFjU3lzdGVtRm9udCxzYW5zLXNlcmlmO3dvcmQtd3JhcDogYnJlYWstd29yZDt9PC9zdHlsZT4g"; +window.onhashchange = window.onload = function() { + var hash = window.location.hash.substring(1); + if (hash.length < 3) { + location.href = "/edit"; + } else { + var iframe = document.getElementById('iframe'); + var link = document.getElementById('edit'); + var preamble = undefined; + + var slashIndex = hash.indexOf("/"); + var title = hash.substring(0, slashIndex); + document.title = title.length ? decodeURIComponent(title.replace(/_/g, " ")) : location.hostname; + + hash = hash.substring(slashIndex + 1); + var editable = hash.charAt(0) == '?'; + if (editable) { + hash = hash.substring(1); + }; + if (hash.indexOf("data:") != 0) { + var compressed = true; + preamble = HEAD_TAGS_EXTENDED; + hash = 'data:text/html;charset=utf-8;' + (compressed ? 'bxze64,' : 'base64,') + hash; + } else if (hash.indexOf("data:text/html;") == 0) { + preamble = HEAD_TAGS; + }; + link.onclick = function() { location.href = "/edit" + location.hash; }; + + var isIE = navigator.userAgent.match(/rv:11/); + var isEdge = navigator.userAgent.match(/Edge\//); + if ((isEdge || isIE) && location.href.length == 2083) { + document.getElementById('warning').innerHTML = 'Edge only supports shorter URLs (maximum 2083 bytes).
Larger sites may require a different browser.
Learn more'; + }; + decompressDataURI(hash, preamble, function(hash) { + if (!hash) return; + iframe.sandbox="allow-scripts allow-forms allow-top-navigation allow-popups allow-modals"; + if (!isIE) { + if (hash) iframe.src = hash; + } else { + dataToString(hash, function(content){ + var doc = iframe.contentWindow.document; + doc.open(); + doc.write(content); + doc.close(); + }) + } + }); + var link = document.getElementById('edit'); + link.href = "/edit" + location.hash; + link.style.display = editable ? "block" : "none"; + } +} \ No newline at end of file diff --git a/manifest.appcache b/manifest.appcache index 78b322a..469f94c 100644 --- a/manifest.appcache +++ b/manifest.appcache @@ -1,2 +1,2 @@ CACHE MANIFEST -# \ No newline at end of file +# v7 \ No newline at end of file