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

Function handleContentChange

docs/edit.js:285–334  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

283}
284
285async function handleContentChange() {
286
287 sessionStorage.setItem("editor-content", editor.innerHTML);
288 var text = editor.innerText;
289 let hasContent = text.trim().length > 0;
290
291 updateBodyClass(hasContent);
292 if (!hasContent) return;
293
294 var metadata = getMetadata();
295 var rawHTML = text.indexOf("</") > 0;
296 if (rawHTML) {
297 text = text.replace(/[ |\t]+/g, " ").replace(/> +</g, "> <");
298 } else {
299 text = editor.innerHTML;
300 }
301
302 if (text.trim().length) {
303 let url = `data:text/html;charset=utf-8,${encodeURIComponent(text)}`;
304 let durl = new bitty.DataURL(url)
305
306 if (metadata.password) {
307 durl.params.cipher = "aes-gcm"
308 durl.params.style = "default"
309 durl.params._password = metadata.password;
310 }
311
312 durl = await durl.compress(bitty.GZIP_MARKER);
313 let ratio = durl.href.length / url.length;
314 console.debug(`Compressed from ${url.length} to ${durl.href.length} bytes (${Math.round(ratio * 100)}%)`);
315
316
317
318
319 if (ratio <= 0.95) url = durl.href;
320 if (rawHTML) {
321 updateLink(url, metadata);
322 } else if (metadata.password) {
323 updateLink(durl.href, metadata);
324 } else {
325 updateLink("?" + durl.data, metadata);
326 }
327 setFileName("");
328 } else if (importedFileData) {
329 updateLink(importedFileData, {title});
330 } else {
331 updateLink("");
332 }
333
334}
335
336var maxLengths = {
337 // "#twitter": 4088,

Callers 3

edit.jsFile · 0.85
handleInputFunction · 0.85
handleMetadataCheckboxFunction · 0.85

Calls 4

getMetadataFunction · 0.85
updateBodyClassFunction · 0.70
updateLinkFunction · 0.70
setFileNameFunction · 0.70

Tested by

no test coverage detected