mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-03-26 23:06:45 +01:00
Use the document paste event for pasting json and text data.
This commit is contained in:
parent
1364fd5c45
commit
c13f662e2d
@ -332,17 +332,20 @@ async function parseContent(text) {
|
||||
try {
|
||||
const task = JSON.parse(text)
|
||||
restoreTaskToUI(task)
|
||||
return true
|
||||
} catch (e) {
|
||||
console.warn(`JSON text content couldn't be parsed.`, e)
|
||||
}
|
||||
return
|
||||
return false
|
||||
}
|
||||
// Normal txt file.
|
||||
const task = parseTaskFromText(text)
|
||||
if (task) {
|
||||
restoreTaskToUI(task)
|
||||
return true
|
||||
} else {
|
||||
console.warn(`Raw text content couldn't be parsed.`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -423,6 +426,17 @@ function checkReadTextClipboardPermission (result) {
|
||||
}
|
||||
navigator.permissions.query({ name: "clipboard-read" }).then(checkReadTextClipboardPermission, (reason) => console.log('clipboard-read is not available. %o', reason))
|
||||
|
||||
document.addEventListener('paste', (event) => {
|
||||
const paste = (event.clipboardData || window.clipboardData).getData('text')
|
||||
const selection = window.getSelection()
|
||||
console.log(selection)
|
||||
console.log(selection.toString())
|
||||
if (selection.toString().trim().length <= 0 && parseContent(paste)) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// Adds a copy and a paste icon if the browser grants permission to write to clipboard.
|
||||
function checkWriteToClipboardPermission (result) {
|
||||
if (result.state != "granted" && result.state != "prompt") {
|
||||
|
Loading…
Reference in New Issue
Block a user