diff --git a/content.js b/content.js index 04792bd..2ff5641 100644 --- a/content.js +++ b/content.js @@ -3,21 +3,15 @@ window.addEventListener("mouseup", handleSelection); var selectedText; function handleSelection() { - selectedText = window.getSelection().toString(); + selectedText = window.getSelection().toString().replace(/\s/g, ""); } chrome.runtime.onMessage.addListener(gotMessage); -function gotMessage(message, sender, sendResponse){ - if(selectedText.length > 0){ - let msg = { - swor: selectedText.trim() - }; - - sendResponse(msg); - } - - else{ - sendResponse({swor: "error"}); - } -} \ No newline at end of file +function gotMessage(message, sender, sendResponse) { + let msg = + selectedText && selectedText.length > 0 + ? selectedText + : "_TextNotSelected_"; + sendResponse({ swor: msg }); +} diff --git a/popup/popup.html b/popup/popup.html index fbb8dae..9860a2a 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -11,8 +11,8 @@