if (navigator.share && navigator.canShare) { const test_file = new File(["abc"], "abc.txt", {type: 'text/plain'}); if (! navigator.canShare({title: "test.txt", files: [ test_file ]})) { $('#sharemem').hide(); } } else { $('#sharemem').hide(); } $('#sharemem').click(() => { const mem_data = H.storage.get_memory(); const filename = H.type_cookie + ".txt"; const file = new File([mem_data], filename, {type: 'text/plain'}); navigator.share({title: filename, files: [ file ]}); }); $('#savemem').click(() => { const mem_data = H.storage.get_memory(); const filename = H.type_cookie + ".txt"; const a = document.createElement('a'); const file = new Blob([mem_data], {type: 'text/plain'}); a.href = URL.createObjectURL(file); a.download = filename; /* if (document.createEvent) { var event = document.createEvent('MouseEvents'); event.initEvent('click', true, true); a.dispatchEvent(event); } else { a.click(); } */ a.click(); setTimeout(() => { URL.revokeObjectURL(a.href); }, 60000); alert("Memory saved as " + filename + "."); }); $('#loadmem').click(() => { $('#loadmem2').trigger('click'); }); $('#loadmem2').change(() => { const ch = document.querySelector('#loadmem2'); if (ch.files.length == 0) { return; } var file = ch.files[0]; ch.value = ""; var reader = new FileReader(); reader.addEventListener('load', (e) => { console.log("File loaded, set as memory"); var data = e.target.result; H.storage.set_memory(data); H.machine.display_all(); }); reader.addEventListener('error', function() { alert('File could not be read.'); }); reader.readAsText(file); console.log("Loading file"); }); Init_hp12c();