javascript - 如何使用 chrome 扩展复制“粘贴图像”
问题描述
我正在开发一个 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.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 嵌入到图像元素中。
例如:_ https://random.image/cute-dog.png会变成
<img src="https://random.image/cute-dog.png" />
推荐阅读
- kubernetes - 重复的大使映射是否会导致 Kubernetes 服务失效?
- r - 如何删除R中的匹配字符?
- php - PHP HTTP 500 试图从 api 发出 GET 请求
- mysql - 重新启动 docker 时表和记录丢失
- python-3.x - 在 ubuntu 中避免使用 /run/user 类型的路径
- java - 如何将 2 个独立列表转换为单个列表
- react-native - 在 TabBar 中的按钮中更改屏幕
- c# - 如何将异步 IO 任务的数量限制到数据库?
- c# - 存储和重用条件表达式
- c# - 'System.ArgumentOutOfRangeException' 类型的异常附加信息:索引超出范围