Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax authored Sep 18, 2024
1 parent 3194904 commit be3266f
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion public/assets/salam/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const elm_refactor = document.querySelector('.refactor');
const elm_save = document.querySelector('.save');
const elm_title = document.querySelector('.input_title');
const elm_copy_code = document.querySelector('.copy_code');
const elm_download_project = document.querySelector('.download_project');

// Global variables
var Module = {
Expand Down Expand Up @@ -179,7 +180,31 @@ elm_save.addEventListener("click", (e) => {
elm_title.classList.remove("w-0")
elm_title.classList.remove("p-0")
}
})
});

elm_download_project.addEventListener("click", (e) => {
const code = elm_output.textContent;

if (elm_error.textContent !== "") {
alert(elm_error.textContent); // TODO
return;
}

if (code === "") {
alert("Error: code is empty"); // TODO
return;
}

const blob = new Blob([code], { type: "text/html" });

const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "project.html";

document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});

// Init
const script = document.createElement('script');
Expand Down

0 comments on commit be3266f

Please sign in to comment.