@cdjs/js-clipboard
v0.0.3
Published
Control system clipboard via javascript
Downloads
4
Maintainers
Readme
js-clipboard
Control system clipboard via javascript
Installing
npm install @cdjs/js-clipboard
// or
yarn add @cdjs/js-clipboard
Usage
import jsClipboard from '@cdjs/js-clipboard'
Documentation
| Method | Desc | Args | Type | Return | Support Browser | | ------ | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ----------------------------------------- | ----------------------------------- | --------------------------------------------- | | get | 获取当前剪贴板内容 | - | - | PromisePromise | C: promotF: deniedS: denied | | copy | 复制 | target: 目标元素/文本/元素 id | HTMLElement/string | PromisePromise | C: grantedF: grantedS: granted | | cut | 剪切 | target: 目标元素/元素 id | HTMLElement/string | PromisePromise | C: grantedF: grantedS: granted | | paste | 粘贴 | target: 目标元素/元素 id | HTMLElement/string | PromisePromise | C: promotF: deniedS: denied | | deny | 禁止复制或粘贴,如果是作用于具体的元素,需要等元素渲染出来后再调用该方法 | target: 页面元素/ id/ class, 默认'document'action: 操作行为, 默认 'copy' | HTMLElement/string'copy' | 'paste' | void | C: grantedF: grantedS: granted | | add | 复制时自动加上文字,类似掘进的效果 | text: 目标文字target: 页面元素/ id/ class, 默认'document' | stringHTMLElement/string | void | C: grantedF: grantedS: granted |
Browser
- C: Chrome
- F: Firefox
- S: Safari
Error 类型
- denied: 系统不支持或权限不足
- failed: web api 调用失败,具体原因未知
- usage: api 调用异常
###How to use
#####获取剪贴板内容
jsClipboard
.get()
.then(str => {})
.catch(err => {})
复制、剪切、粘贴
// paste cut 类似 注意传参
// copy 方法可以传入文字 paste / cut 只能传目标元素 或 元素id
jsClipboard
.copy(target)
.then(str => {})
.catch(err => {})
禁止复制、粘贴
// 当 target 为具体的元素时,需要等元素渲染后在调用该方法
jsClipboard.deny(target)
追加文字
// 当 target 为具体的元素时,需要等元素渲染后在调用该方法
jsClipboard.add(
'\n作者: XuKang\nGitHub: https://github.com/BlueBlueBlueSky/js-clipboard',
target
)