Javascript 如何复制';粘贴图像';带镀铬延长线
我正在开发一个chrome扩展,它可以保存和粘贴代码片段 文本项非常有用:Javascript 如何复制';粘贴图像';带镀铬延长线,javascript,google-chrome-extension,Javascript,Google Chrome Extension,我正在开发一个chrome扩展,它可以保存和粘贴代码片段 文本项非常有用: export function copyText(text: string): void { const textarea = window.document.createElement('textarea'); textarea.style.position = 'fixed'; textarea.style.opacity = '0'; textarea.value = text; window.
export function copyText(text: string): void {
const textarea = window.document.createElement('textarea');
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
textarea.value = text;
window.document.body.appendChild(textarea);
textarea.select();
window.document.execCommand('copy');
window.document.body.removeChild(textarea);
}
export function pasteText(element: HTMLElement): void {
element.focus();
window.document.execCommand('paste');
}
现在,我正在尝试为图像实现同样的功能。当它工作时,discord.com就是这样看的:
目前,我一直在尝试重现这种行为(例如在Chrome控制台中)
您知道如何实现它吗?我猜它正在检查您粘贴的内容。如果以png、jpg、webp或avif等图像格式结束。然后,它将把url嵌入到图像元素中 例如:uu将成为
如何通过编程方式粘贴图像?