Fix slowdown when clipboard contains pictures

This commit is contained in:
Kamil Tomala 2017-08-13 18:19:36 +02:00
parent f5005a877e
commit e977862e44
1 changed files with 9 additions and 1 deletions

View File

@ -25,6 +25,14 @@ browser.browserAction.onClicked.addListener(() => {
.then(([t]) => toggleTab(t.id)) .then(([t]) => toggleTab(t.id))
}) })
window.onload = () => {
document.querySelector("#paste-target").addEventListener("paste", e => {
if(e.clipboardData.getData("text/plain") === "") {
e.preventDefault() // prevent anything that is not representable as plain text from being pasted
}
})
}
function toggleTab(id) { function toggleTab(id) {
const index = listeningTabs.indexOf(id) const index = listeningTabs.indexOf(id)
if(index >= 0) { if(index >= 0) {
@ -57,7 +65,7 @@ function checkClipboard() {
pasteTarget.focus() pasteTarget.focus()
document.execCommand("paste") document.execCommand("paste")
const content = pasteTarget.textContent const content = pasteTarget.textContent
if(content != previousContent) { if(content != previousContent && content != "") {
listeningTabs.forEach(id => notifyForeground(id, content)) listeningTabs.forEach(id => notifyForeground(id, content))
previousContent = content previousContent = content
} }