soiz1's picture
Upload 2891 files
6bcb42f verified
raw
history blame
846 Bytes
export default async ({ addon, console }) => {
if (!addon.tab.redux.state) return console.warn("Redux is not available!");
addon.tab.redux.initialize();
addon.tab.redux.addEventListener("statechanged", ({ detail }) => {
if (addon.self.disabled) return;
const e = detail;
if (!e.action || e.action.type !== "scratch-paint/clipboard/SET") return;
const items = e.next.scratchPaint.clipboard.items;
if (items.length !== 1) return;
const firstItem = items[0];
// TODO vector support
if (!Array.isArray(firstItem) || firstItem[0] !== "Raster") return console.log("copied element is vector");
const dataURL = firstItem[1].source;
addon.tab
.copyImage(dataURL)
.then(() => console.log("Image successfully copied"))
.catch((e) => console.error(`Image could not be copied: ${e}`));
});
};