mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-05-30 22:55:40 +02: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 {
|
try {
|
||||||
const task = JSON.parse(text)
|
const task = JSON.parse(text)
|
||||||
restoreTaskToUI(task)
|
restoreTaskToUI(task)
|
||||||
|
return true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`JSON text content couldn't be parsed.`, e)
|
console.warn(`JSON text content couldn't be parsed.`, e)
|
||||||
}
|
}
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
// Normal txt file.
|
// Normal txt file.
|
||||||
const task = parseTaskFromText(text)
|
const task = parseTaskFromText(text)
|
||||||
if (task) {
|
if (task) {
|
||||||
restoreTaskToUI(task)
|
restoreTaskToUI(task)
|
||||||
|
return true
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Raw text content couldn't be parsed.`)
|
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))
|
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.
|
// Adds a copy and a paste icon if the browser grants permission to write to clipboard.
|
||||||
function checkWriteToClipboardPermission (result) {
|
function checkWriteToClipboardPermission (result) {
|
||||||
if (result.state != "granted" && result.state != "prompt") {
|
if (result.state != "granted" && result.state != "prompt") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user