MCPcopy Create free account
hub / github.com/arfct/itty-bitty / fetchCodepen

Function fetchCodepen

docs/edit.js:229–267  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

227
228var TEMPLATE_MARKER = "/*use-itty-bitty-template*/";
229function fetchCodepen(url) {
230
231 Promise.all([
232 fetch(url + ".html"),
233 fetch(url + ".css"),
234 fetch(url + ".js"),
235 ]).then(async function(responses) {
236 console.log("responses", responses);
237 let h = await responses[0].text();
238 let c = await responses[1].text();
239 let j = await responses[2].text();
240
241 console.log({h,c,j})
242
243 var useTemplate = c.indexOf(TEMPLATE_MARKER) >= 0;
244 var string =
245 '<style type="text/css">' + c + "</style>" +
246 h +
247 '<script type="text/javascript">' + j + "</script>";
248 console.log("string", string);
249
250 let url = `data:text/html;charset=utf-8,${encodeURIComponent(string)}`;
251
252 let durl = new bitty.DataURL(url);
253 durl = await durl.compress(bitty.GZIP_MARKER);
254
255 let ratio = durl.href.length / url.length;
256 console.log(`Compressed from ${url.length} to ${durl.href.length} bytes (${Math.round(ratio * 100)}%)`);
257
258 // setFileName("✒️" + "codepen");
259 var title = QS("#doc-title").innerText;
260 setTimeout(function() {
261 // var data = (useTemplate ? "" : DATA_PREFIX_BXZE) + zip;
262 // importedFileData = url;
263 updateLink(durl.href, {title:"CODEPEN"});
264 }, 300);
265
266 });
267}
268
269function handleInput(e) {
270 handleContentChange(e);

Callers 1

handlePasteFunction · 0.70

Calls 2

allMethod · 0.80
updateLinkFunction · 0.70

Tested by

no test coverage detected