Remove dead code and provide the return value for error detection.
This commit is contained in:
+1
-8
@@ -1,23 +1,16 @@
|
|||||||
export const clipboard = function(superClass) {
|
export const clipboard = function(superClass) {
|
||||||
return class extends superClass {
|
return class extends superClass {
|
||||||
copy(content) {
|
copy(content) {
|
||||||
copyToClipboard(content);
|
return copyToClipboard(content);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const copyToClipboard = async (content) => {
|
export const copyToClipboard = async (content) => {
|
||||||
const txtEl = document.createElement('input');
|
|
||||||
txtEl.type = 'hidden';
|
|
||||||
document.body.appendChild(txtEl);
|
|
||||||
txtEl.value = content;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(content);
|
await navigator.clipboard.writeText(content);
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
|
||||||
document.body.removeChild(txtEl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user