add fallback for copying to clipboard

This commit is contained in:
Evgenii Alekseev 2022-11-23 02:11:59 +02:00
parent 336784519b
commit 89944eb2b6
3 changed files with 17 additions and 2 deletions

View File

@ -25,7 +25,7 @@
async function copyLogs() {
const logs = packageInfoLogs.text();
await navigator.clipboard.writeText(logs);
await copyToClipboard(logs);
packageInfoLogsCopyButton.html("<i class=\"bi bi-clipboard-check\"></i> copied");
setTimeout(()=> {

View File

@ -101,7 +101,7 @@ SigLevel = Database{% if has_repo_signed %}Required{% else %}Never{% endif %} Pa
async function copyPacmanConf() {
const conf = pacmanConf.text();
await navigator.clipboard.writeText(conf);
await copyToClipboard(conf);
pacmanConfCopyButton.html("<i class=\"bi bi-clipboard-check\"></i> copied");
setTimeout(() => {

View File

@ -11,3 +11,18 @@
<script src="https://unpkg.com/bootstrap-table@1.21.1/dist/extensions/export/bootstrap-table-export.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.21.1/dist/extensions/resizable/bootstrap-table-resizable.js"></script>
<script>
async function copyToClipboard(text) {
if (navigator.clipboard === undefined) {
const input = document.createElement("textarea");
input.innerHTML = text;
document.body.appendChild(input);
input.select();
document.execCommand('copy');
document.body.removeChild(input);
} else {
await navigator.clipboard.writeText(text);
}
}
</script>