1globalThis.dialog = (() => { 2 const openFile = async (multiple, accept) => { 3 try { 4 const element = document.getElementById("out"); 5 if (element) { 6 element.focus(); 7 element.dispatchEvent(new PointerEvent("pointerup", { 8 bubbles: true, 9 cancelable: true, 10 pointerId: 1, 11 isPrimary: true, 12 })); 13 } 14 15 const files = await new Promise((resolve, reject) => { 16 const input = document.createElement("input"); 17 input.type = "file"; 18 input.multiple = multiple; 19 input.accept = accept; 20 21 input.addEventListener("change", (event) => { 22 resolve(Array.from(event.target.files)); 23 }); 24 25 input.addEventListener("cancel", () => { 26 reject("cancel"); 27 }); 28 29 input.click(); 30 }); 31 32 for (const file of files) { 33 await globalThis.onFileSelected(file.name, new Uint8Array(await file.arrayBuffer())); 34 } 35 } catch (e) { 36 if (e !== "cancel") { 37 throw e; 38 } 39 } finally { 40 const element = document.getElementById("out"); 41 if (element) { 42 element.dispatchEvent(new PointerEvent("pointerup", { 43 bubbles: true, 44 cancelable: true, 45 pointerId: 1, 46 isPrimary: true, 47 })); 48 } 49 } 50 }; 51 52 const saveFile = async (name, data) => { 53 const blob = new Blob([data], {type: "application/octet-stream"}); 54 const url = URL.createObjectURL(blob); 55 const a = document.createElement("a"); 56 a.href = url;
57 a.download = name; 58 document.body.appendChild(a); 59 a.click(); 60 document.body.removeChild(a); 61 URL.revokeObjectURL(url); 62 }; 63 64 return { 65 openFile, 66 saveFile, 67 }; 68})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.