You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
954 B
JavaScript
32 lines
954 B
JavaScript
const exportText = document.getElementById("export-text");
|
|
|
|
exportText.addEventListener("click", (e) => {
|
|
let text = document.querySelector("ol").innerText;
|
|
let title = fileName.slice(0, fileName.indexOf(".")) || "export";
|
|
title += ".txt";
|
|
download(text, title, "text/plain;charset=utf-8");
|
|
});
|
|
|
|
// https://stackoverflow.com/questions/13405129/javascript-create-and-save-file
|
|
// Thank you Kanchu!
|
|
// Function to download data to a file
|
|
function download(data, filename, type) {
|
|
var file = new Blob([data], { type: type });
|
|
if (window.navigator.msSaveOrOpenBlob)
|
|
// IE10+
|
|
window.navigator.msSaveOrOpenBlob(file, filename);
|
|
else {
|
|
// Others
|
|
var a = document.createElement("a"),
|
|
url = URL.createObjectURL(file);
|
|
a.href = url;
|
|
a.download = filename;
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
setTimeout(function () {
|
|
document.body.removeChild(a);
|
|
window.URL.revokeObjectURL(url);
|
|
}, 0);
|
|
}
|
|
}
|