Use navigator.clipboard.writeText

main
Simon Legner 13 hours ago
parent 34220e61f4
commit ba294a12de

@ -526,21 +526,3 @@ $.highlight = function (el, options) {
el.classList.add(options.className);
setTimeout(() => el.classList.remove(options.className), options.delay);
};
$.copyToClipboard = function (string) {
let result;
const textarea = document.createElement("textarea");
textarea.style.position = "fixed";
textarea.style.opacity = 0;
textarea.value = string;
document.body.appendChild(textarea);
try {
textarea.select();
result = !!document.execCommand("copy");
} catch (error) {
result = false;
} finally {
document.body.removeChild(textarea);
}
return result;
};

@ -217,10 +217,9 @@ app.views.EntryPage = class EntryPage extends app.View {
this.load();
} else if (target.classList.contains("_pre-clip")) {
$.stopEvent(event);
target.classList.add(
$.copyToClipboard(target.parentNode.textContent)
? "_pre-clip-success"
: "_pre-clip-error",
navigator.clipboard.writeText(target.parentNode.textContent).then(
() => target.classList.add("_pre-clip-success"),
() => target.classList.add("_pre-clip-error"),
);
setTimeout(() => (target.className = "_pre-clip"), 2000);
}

Loading…
Cancel
Save