From e6204f6959c5872f65508ab697db27d93f2f5291 Mon Sep 17 00:00:00 2001 From: Nicholas Jitkoff Date: Sat, 22 Jan 2022 13:49:38 -0800 Subject: [PATCH] Add legacy code --- build-index.sh | 6 +-- docs/legacy.html | 18 +++++++++ docs/legacy/data-min.js | 1 + docs/legacy/data.js | 79 ++++++++++++++++++++++++++++++++++++++ docs/legacy/index-min.css | 1 + docs/legacy/index-min.js | 1 + docs/legacy/index.css | 62 ++++++++++++++++++++++++++++++ docs/legacy/index.html | 18 +++++++++ docs/legacy/index.js | 78 +++++++++++++++++++++++++++++++++++++ docs/legacy/index.src.html | 19 +++++++++ 10 files changed, 279 insertions(+), 4 deletions(-) create mode 100644 docs/legacy.html create mode 100644 docs/legacy/data-min.js create mode 100644 docs/legacy/data.js create mode 100644 docs/legacy/index-min.css create mode 100644 docs/legacy/index-min.js create mode 100644 docs/legacy/index.css create mode 100644 docs/legacy/index.html create mode 100644 docs/legacy/index.js create mode 100644 docs/legacy/index.src.html diff --git a/build-index.sh b/build-index.sh index 61c671f..1fb5abe 100755 --- a/build-index.sh +++ b/build-index.sh @@ -1,9 +1,7 @@ #! /bin/bash -cd docs +cd docs/legacy terser data.js > data-min.js - -cd index.src terser index.js > index-min.js uglifycss index.css > index-min.css -awk '$1 == "@include"{system("cat " $2); next} 1' index.html > ../index.html +awk '$1 == "@include"{system("cat " $2); next} 1' index.src.html > index.html diff --git a/docs/legacy.html b/docs/legacy.html new file mode 100644 index 0000000..7c0b3c1 --- /dev/null +++ b/docs/legacy.html @@ -0,0 +1,18 @@ + + + + +
itty.bitty is experimental technology that renders linked content from outside sources. Learn more. +

This content is only as trustworthy as its source, and it should be treated with the caution +you would show any insecure web page. +

+ +
+edit + diff --git a/docs/legacy/data-min.js b/docs/legacy/data-min.js new file mode 100644 index 0000000..d8f251c --- /dev/null +++ b/docs/legacy/data-min.js @@ -0,0 +1 @@ +var BASE64_MARKER=";base64,";var LZMA64_MARKER=";bxze64,";function compressDataURI(dataURI,callback){var base64Index=dataURI.indexOf(BASE64_MARKER);var base64=dataURI.substring(base64Index+BASE64_MARKER.length);stringToZip(base64ToByteArray(base64),(function(result){callback(dataURI.substring(0,base64Index)+LZMA64_MARKER+result)}))}function base64ToByteArray(base64){var raw=window.atob(base64);var rawLength=raw.length;var array=new Uint8Array(new ArrayBuffer(rawLength));for(i=0;i0){var base64=dataURI.substring(base64Index+LZMA64_MARKER.length);zipToString(base64,(function(result){stringToData(result,(function(data){if(!data)return callback(undefined);callback(dataURI.substring(0,base64Index)+BASE64_MARKER+(preamble||"")+data.split(",")[1])}))}))}else{callback(dataURI)}}function zipToString(data,callback){var array=base64ToByteArray(data);LZMA.decompress(array,(function(result,error){if(!(typeof result==="string"))result=new Uint8Array(result);if(error)console.error(error);callback(result)}))}function stringToData(string,callback){if(!string.length)return callback("");var a=new FileReader;a.onload=function(e){callback(e.target.result.replace())};a.readAsDataURL(new Blob([string],{encoding:"UTF-8",type:"text/html;charset=UTF-8"}))}function dataToString(data,callback){var blob=dataURItoBlob(data);var reader=new FileReader;reader.onload=function(e){callback(reader.result)};reader.readAsText(blob)}function dataURItoBlob(dataURI){var byteString=atob(dataURI.split(",")[1]);var mimeString=dataURI.split(",")[0].split(":")[1].split(";")[0];var arrayBuffer=new ArrayBuffer(byteString.length);var _ia=new Uint8Array(arrayBuffer);for(var i=0;i 0) { + var base64 = dataURI.substring(base64Index + LZMA64_MARKER.length); + zipToString(base64, function(result) { + stringToData(result, function(data) { + if (!data) return callback(undefined); + callback(dataURI.substring(0, base64Index) + BASE64_MARKER + (preamble || '') + data.split(',')[1]) + }) + }) + } else { + callback(dataURI) + } +} + +function zipToString(data, callback) { + var array = base64ToByteArray(data); + LZMA.decompress(array, function(result, error) { + if (!(typeof result === 'string')) result = new Uint8Array(result) + if (error) console.error(error); + callback(result); + }); +} + +function stringToData(string, callback) { + if (!string.length) return callback(""); + var a = new FileReader(); + a.onload = function(e) { callback(e.target.result.replace()) } + a.readAsDataURL(new Blob([string], {encoding:"UTF-8",type:"text/html;charset=UTF-8"})); +} + +function dataToString(data, callback) { + var blob = dataURItoBlob(data) + var reader = new FileReader(); + reader.onload = function(e) { callback(reader.result) } + reader.readAsText(blob); +} + +function dataURItoBlob(dataURI) { + var byteString = atob(dataURI.split(',')[1]); + var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; + var arrayBuffer = new ArrayBuffer(byteString.length); + var _ia = new Uint8Array(arrayBuffer); + for (var i = 0; i < byteString.length; i++) { + _ia[i] = byteString.charCodeAt(i); + } + var dataView = new DataView(arrayBuffer); + var blob = new Blob([dataView.buffer], { type: mimeString }); + return blob; +} diff --git a/docs/legacy/index-min.css b/docs/legacy/index-min.css new file mode 100644 index 0000000..a5b1624 --- /dev/null +++ b/docs/legacy/index-min.css @@ -0,0 +1 @@ +body{font-family:sans-serif}#iframe{border:0;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:.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;width:20em;z-index:100;top:10vh;left:50vw;margin-left:-10em}#warning:empty{display:none}body.toasting #iframe,body.toasting #edit{opacity:.5;pointer-events:none}body.toasting #toast{box-sizing:border-box;background-color:#feecc2;border-radius:4px;font-size:13px;left:50%;top:10px;margin-left:-160px;padding:1em;position:absolute;max-width:320px;z-index:101}body:not(.toasting) #toast,body.toasting #warning{display:none} diff --git a/docs/legacy/index-min.js b/docs/legacy/index-min.js new file mode 100644 index 0000000..9f4917a --- /dev/null +++ b/docs/legacy/index-min.js @@ -0,0 +1 @@ +var HEAD_TAGS="PGJhc2UgdGFyZ2V0PSJfdG9wIj4K";var HEAD_TAGS_EXTENDED="PG1ldGEgY2hhcnNldD0idXRmLTgiPjxtZXRhIG5hbWU9InZpZXdwb3J0IiBjb250ZW50PSJ3aWR0aD1kZXZpY2Utd2lkdGgiPjxiYXNlIHRhcmdldD0iX3RvcCI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj5ib2R5e21hcmdpbjowIGF1dG87cGFkZGluZzoxMnZtaW4gMTB2bWluO21heC13aWR0aDozNWVtO2xpbmUtaGVpZ2h0OjEuNWVtO2ZvbnQtZmFtaWx5OiAtYXBwbGUtc3lzdGVtLEJsaW5rTWFjU3lzdGVtRm9udCxzYW5zLXNlcmlmO3dvcmQtd3JhcDogYnJlYWstd29yZDt9PC9zdHlsZT4g";function dismiss(){if(document.getElementById("never").checked)window.localStorage.setItem("toasted",true);document.body.classList.remove("toasting")}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 colon=hash.indexOf(":");if(colon>0&&colon<15){document.body.classList.remove("toasting");return window.location.replace(hash)}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}else if(hash.indexOf("data:text/plain;")==0){preamble=HEAD_TAGS_EXTENDED}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-downloads allow-forms allow-top-navigation allow-popups allow-modals allow-popups-to-escape-sandbox";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"}}; diff --git a/docs/legacy/index.css b/docs/legacy/index.css new file mode 100644 index 0000000..5e6f4bc --- /dev/null +++ b/docs/legacy/index.css @@ -0,0 +1,62 @@ +body { + font-family: sans-serif; +} +#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; + width: 20em; + z-index: 100; + top: 10vh; + left: 50vw; + margin-left: -10em; +} +#warning:empty { + display: none; +} +body.toasting #iframe, +body.toasting #edit { + opacity: 0.5; + pointer-events: none; +} +body.toasting #toast { + box-sizing: border-box; + background-color: #feecc2; + border-radius: 4px; + font-size: 13px; + left: 50%; + top: 10px; + margin-left: -160px; + padding: 1em; + position: absolute; + max-width: 320px; + z-index: 101; +} +body:not(.toasting) #toast, +body.toasting #warning { + display: none; +} diff --git a/docs/legacy/index.html b/docs/legacy/index.html new file mode 100644 index 0000000..7c0b3c1 --- /dev/null +++ b/docs/legacy/index.html @@ -0,0 +1,18 @@ + + + + +
itty.bitty is experimental technology that renders linked content from outside sources. Learn more. +

This content is only as trustworthy as its source, and it should be treated with the caution +you would show any insecure web page. +

+ +
+edit + diff --git a/docs/legacy/index.js b/docs/legacy/index.js new file mode 100644 index 0000000..113eab6 --- /dev/null +++ b/docs/legacy/index.js @@ -0,0 +1,78 @@ +var HEAD_TAGS = "PGJhc2UgdGFyZ2V0PSJfdG9wIj4K"; +var HEAD_TAGS_EXTENDED = + "PG1ldGEgY2hhcnNldD0idXRmLTgiPjxtZXRhIG5hbWU9InZpZXdwb3J0IiBjb250ZW50PSJ3aWR0aD1kZXZpY2Utd2lkdGgiPjxiYXNlIHRhcmdldD0iX3RvcCI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj5ib2R5e21hcmdpbjowIGF1dG87cGFkZGluZzoxMnZtaW4gMTB2bWluO21heC13aWR0aDozNWVtO2xpbmUtaGVpZ2h0OjEuNWVtO2ZvbnQtZmFtaWx5OiAtYXBwbGUtc3lzdGVtLEJsaW5rTWFjU3lzdGVtRm9udCxzYW5zLXNlcmlmO3dvcmQtd3JhcDogYnJlYWstd29yZDt9PC9zdHlsZT4g"; + +function dismiss() { + if (document.getElementById("never").checked) window.localStorage.setItem('toasted', true); + document.body.classList.remove("toasting") +} + +window.onhashchange = window.onload = function() { + var hash = window.location.hash.substring(1); + if (hash.length < 3) { + location.href = "/edit"; + } else { + // if (!window.localStorage.getItem('toasted')) document.body.classList.add("toasting"); + + 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 colon = hash.indexOf(":"); + if ( colon > 0 && colon < 15) { + document.body.classList.remove("toasting"); + return window.location.replace(hash); + } + 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; + } else if (hash.indexOf("data:text/plain;") == 0) { + preamble = HEAD_TAGS_EXTENDED; + } + 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-downloads allow-forms allow-top-navigation allow-popups allow-modals allow-popups-to-escape-sandbox"; + 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"; + } +}; diff --git a/docs/legacy/index.src.html b/docs/legacy/index.src.html new file mode 100644 index 0000000..10dd2c3 --- /dev/null +++ b/docs/legacy/index.src.html @@ -0,0 +1,19 @@ + + + + +
itty.bitty is experimental technology that renders linked content from outside sources. Learn more. +

This content is only as trustworthy as its source, and it should be treated with the caution +you would show any insecure web page. +

+ +
+edit + \ No newline at end of file