Bookmark to read local file
copy( | |
encodeURIComponent(`(function() { | |
function readLocalFile(e) { | |
const file = e.target.files[0]; | |
if (!file) { | |
alert('No file selected!') | |
} | |
const reader = new FileReader(); | |
reader.onload = function(e) { | |
const contents = e.target.result; | |
localStorage.setItem('mock', contents) | |
}; | |
reader.readAsText(file); | |
} | |
const element = document.createElement('input'); | |
element.type = 'file'; | |
element.addEventListener('change', readLocalFile, false); | |
element.click(); | |
})();`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment