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) {
|
||||
return class extends superClass {
|
||||
copy(content) {
|
||||
copyToClipboard(content);
|
||||
return copyToClipboard(content);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const copyToClipboard = async (content) => {
|
||||
const txtEl = document.createElement('input');
|
||||
txtEl.type = 'hidden';
|
||||
document.body.appendChild(txtEl);
|
||||
txtEl.value = content;
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(content);
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
} finally {
|
||||
document.body.removeChild(txtEl);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user