Socket
Book a DemoInstallSign in
Socket

clipboarder

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clipboarder

用于获取浏览器页面的剪贴板内容

2.0.5
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

clipboarder

用于获取浏览器页面的剪贴板内容

使用

下载

npm install clipboarder 

引入

import clipboarder from 'clipboarder'

API

readBlob

获取剪贴板内的blob对象

语法

clipboarder.readBlob((blob) => {
  // 回调函数
  // blob 获取的blob对象
})

getContent

获取剪贴板内的blob解析后的文本或者图片数据

语法

clipboarder.getContent((type, data) => {
  // 回调函数
  // type 获取的数据的类型
  // data 解析后的blob数据
  // 结果在 data.target.result 字段内
})

getText

仅获取剪贴板内的文本数据,没有文本则不会调用回调函数

语法

clipboarder.getText((text) => {
  // 回调函数
  // text 获取的文本数据
})

getImage

仅获取剪贴板内的图片类型数据,没有文本则不会调用回调函数

语法

clipboarder.getImage((base64) => {
  // 回调函数
  // base64 获取的图片的base64图片
})

writeBlob

将文件写入剪贴板内,部分文件类型可能无法写入

语法

// 传入 blob 类型数据
clipboarder.writeBlob(blob, () => {
  // 写入成功时的回调
}, (err) => {
  // 写入失败时执行的回调
  // err 为错误信息
})

writeText

向剪贴板内写入文本信息

语法

// 传入 blob 类型数据
clipboarder.writeText('需要写入的文本内容', () => {
  // 写入成功时的回调
}, (err) => {
  // 写入失败时执行的回调
  // err 为错误信息
})

writeDataURL

向剪贴板内写入base64,该api主要用于复制base64图片到剪贴板,并且可以粘贴出去

语法

clipboarder.writeDataURL('需要复制的图片的base64', () => {
  // 写入成功时的回调
}, (err) => {
  // 写入失败时执行的回调
  // err 为错误信息
})

writeWebImg

向剪贴板写入网络图片,该api主要用于复制网络图片到剪贴板,该图片必须没有跨域限制的,并且在有网络环境下才能复制成功

语法

clipboarder.writeWebImg('需要复制的图片的url', () => {
  // 写入成功时的回调
}, (err) => {
  // 写入失败时执行的回调
  // err 为错误信息
})

版本标注

  • 2.0.4 修复粘贴板为空时获取数据报错的问题
  • 2.0.5 更新阅读文档

Keywords

js

FAQs

Package last updated on 23 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.