This repository has been archived on 2025-01-09. You can view files and clone it, but cannot push or open issues or pull requests.
2025-01-09 18:30:49 +08:00

31 lines
971 B
JavaScript

const { clipboard, nativeImage } = require('electron')
window.onload = () => {
// 获取元素
let aBtn = document.getElementsByTagName('button')
let aInput = document.getElementsByTagName('input')
let oBtn = document.getElementById('clipImg')
let ret = null
aBtn[0].onclick = () => {
// 复制内容
ret = clipboard.writeText(aInput[0].value)
}
aBtn[1].onclick = () => {
// 粘贴内容
aInput[1].value = clipboard.readText(ret)
}
oBtn.onclick = () => {
// 将图片放置于剪切板的时候要求图片类型属于 nativeImage 类型
let oImage = nativeImage.createFromPath('c.png')
clipboard.writeImage(oImage)
// 将剪切板中的图片作为 DOM 元素显示在界面上
let oImg = clipboard.readImage()
let oImgDom = new Image()
oImgDom.src = oImg.toDataURL() // 转换为base64
document.body.appendChild(oImgDom)
}
}