Skip to content

Commit

Permalink
Implement Reverso Context #19
Browse files Browse the repository at this point in the history
Fix: Send events with empty selectedText from Safari extension
  • Loading branch information
filimo committed Oct 11, 2019
1 parent cb4e010 commit 97bb099
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions ReaderTranslatorSafari/reader-translate-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,21 @@
}

function _send(name, source, e) {
var txt = document.getSelection().toString()
if(txt.trim()) {
let event = {
time: Date(), // to prevent removing duplicate events
name: name,
source: source,
extra: {
ctrlKey: e.ctrlKey || keysStatus.ctrlKey,
altKey: e.altKey || keysStatus.altKey,
metaKey: e.metaKey || keysStatus.metaKey, //⌘ Command
shiftKey: e.shiftKey || keysStatus.shiftKey,
which: e.which || keysStatus.which,
keyCode: e.keyCode || keysStatus.keyCode,
selectedText: txt,
}
let event = {
time: Date(), // to prevent removing duplicate events
name: name,
source: source,
extra: {
ctrlKey: e.ctrlKey || keysStatus.ctrlKey,
altKey: e.altKey || keysStatus.altKey,
metaKey: e.metaKey || keysStatus.metaKey, //⌘ Command
shiftKey: e.shiftKey || keysStatus.shiftKey,
which: e.which || keysStatus.which,
keyCode: e.keyCode || keysStatus.keyCode,
selectedText: document.getSelection().toString(),
}
safari.extension.dispatchMessage(JSON.stringify(event))
}
safari.extension.dispatchMessage(JSON.stringify(event))
}

var sendIn100 = debounce(_send, 100)
Expand Down

0 comments on commit 97bb099

Please sign in to comment.