Skip to content

粘贴板更新 2024 #2

@CracKerMe

Description

@CracKerMe
async function getClipboardContents() {
  try {
    const clipboardItems = await navigator.clipboard.read();
    for (const clipboardItem of clipboardItems) {
      for (const type of clipboardItem.types) {
        const blob = await clipboardItem.getType(type);
        if (blob.type.startsWith('image/')) {
          // 处理图片
          const imageUrl = URL.createObjectURL(blob);
          console.log('图片 URL:', imageUrl);
        } else if (blob.type.startsWith('text/')) {
          // 处理文本
          const text = await blob.text();
          console.log('文本内容:', text);
        } else {
          // 处理其他类型数据
          console.log('其他类型数据:', blob.type, blob);
        }
      }
    }
  } catch (err) {
    console.error('读取剪贴板内容时出错:', err);
  }
}

可以很好的获取 来自word等内容,以便于做富文本解析等

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions