Исправление багов

This commit is contained in:
Book Pauk
2022-10-14 21:16:26 +07:00
parent 7799bba9f2
commit ecc7e2b2c3
5 changed files with 48 additions and 18 deletions

View File

@@ -842,7 +842,7 @@ class Search {
d.click();
} else if (action == 'copyLink') {
//копирование ссылки
if (utils.copyTextToClipboard(href))
if (await utils.copyTextToClipboard(href))
this.$root.notify.success('Ссылка успешно скопирована');
else
this.$root.notify.error('Копирование ссылки не удалось');

View File

@@ -48,7 +48,29 @@ export function wordEnding(num, type = 0) {
}
}
export function fallbackCopyTextToClipboard(text) {
let textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
let result = false;
try {
result = document.execCommand('copy');
} catch (e) {
console.error(e);
}
document.body.removeChild(textArea);
return result;
}
export async function copyTextToClipboard(text) {
if (!navigator.clipboard) {
return fallbackCopyTextToClipboard(text);
}
let result = false;
try {
await navigator.clipboard.writeText(text);