fui-fancyui
Version:
FancyUI Libary
24 lines (23 loc) • 820 B
JavaScript
const a = (r) => {
let e, o;
try {
e = document.createElement("textarea"), e.setAttribute("readonly", "true"), e.setAttribute("contenteditable", "true"), e.style.position = "fixed", e.value = r, document.body.appendChild(e), e.focus(), e.select();
const n = document.createRange();
n.selectNodeContents(e);
const t = window.getSelection();
t == null || t.removeAllRanges(), t == null || t.addRange(n), e.setSelectionRange(0, e.value.length), o = document.execCommand("copy"), e.blur();
} catch (n) {
console.error(n), o = null;
} finally {
e && document.body.removeChild(e);
}
if (!o) {
const t = navigator.platform.toUpperCase().indexOf("MAC") >= 0 ? "⌘C" : "CTRL+C";
if (o = prompt(`Press ${t}`, r), !o)
return !1;
}
return !0;
};
export {
a as default
};