Skip to content

Commit

Permalink
Merge pull request #3 from ALSHLKANY/master
Browse files Browse the repository at this point in the history
FIX copy Button
  • Loading branch information
Mohab Yaser authored Mar 20, 2024
2 parents 9a2449e + 003a84b commit 9b56c4a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,25 @@ function view_problems(problems) {
let btn = codes_btns[i];

btn.addEventListener("click", () => {
// Check if clipboard API is supported [requires HTTPS]
if (navigator.clipboard) {
navigator.clipboard.writeText(showed_codes[i]);
Swal.fire({
title: "Code Copied",
icon: "success",
});
}
// Fallback is the solution for browsers without clipboard API or insecure connections
else {
const textArea = document.createElement("textarea");
textArea.value = showed_codes[i];
document.body.appendChild(textArea);
textArea.select();

document.execCommand("copy");

document.body.removeChild(textArea);
}
Swal.fire({
title: "Code Copied",
icon: "success",
});
});
}
}
Expand Down Expand Up @@ -523,4 +537,4 @@ document.querySelector("#github span").addEventListener("click", () => {

document.querySelector("#github img").addEventListener("click", () => {
window.open("https://github.com/Mohab96", "_blank");
});
});

0 comments on commit 9b56c4a

Please sign in to comment.