2 ms·
I like it! Here's something convenient :D class ClipboardItemList extends Array { add(content, type) { let entry = {}; if
by opusonline 7y ago
I like it!
Here's something convenient :D
class ClipboardItemList extends Array {
add(content, type) {
let entry = {};
if (typeof content === 'string' && type.startsWith('text/')) {
content = new Blob([content], {'type': type});
}
if (!(content instanceof Blob)) {
throw new TypeError('Data must be a Blob');
}
if (!type) {
type = content.type || 'application/octet-stream';
}
entry[type] = content;
this.push(new ClipboardItem(entry));
return this;
}
}
let items = new ClipboardItemList();
items.add(blob);
items.add('test-image.png', 'text/plain');
navigator.clipboard.write(items).then(() => log('yeah!'), (err) => log(err));