Skip to content

Commit

Permalink
Merge pull request #52 from Decimation/patch-1
Browse files Browse the repository at this point in the history
Fix commands.js (#51)
  • Loading branch information
piroor authored Apr 9, 2024
2 parents be5e7ac + b1f0d72 commit 3c4d66b
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions common/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,30 @@ export async function copyToClipboard(tabs, format) {
if (typeof navigator.clipboard.write == 'function') {
log('trying to write data to clipboard via Clipboard API');
try {
const dt = new DataTransfer();
dt.items.add(plainText, 'text/plain');
dt.items.add(richText, 'text/html');
navigator.clipboard.write(dt)
.then(() => {
notifyCopied(tabs.length, plainText);
})
.catch(error => {
notifyFailed(error);
});
/* const dt = new DataTransfer();
dt.items.add(plainText, 'text/plain');
dt.items.add(richText, 'text/html'); */

const ci1 = new ClipboardItem({
["text/plain"]: plainText,
["text/html"]: richText,
});

/* navigator.clipboard
.write([ci1])
.then(() => {
notifyCopied(tabs.length, plainText);
})
.catch((error) => {
notifyFailed(error);
}); */

await navigator.clipboard.write([ci1]).then(() => {
notifyCopied(tabs.length, plainText);
});

console.log("Text has been copied to clipboard");

return;
}
catch(error) {
Expand Down

0 comments on commit 3c4d66b

Please sign in to comment.