From a88474de562df6706c1873584b85b87d74af7dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Norman=20Hauk=C3=A5s?= Date: Sat, 26 Sep 2015 21:06:24 +0200 Subject: [PATCH] able to select words. --- content_script.js | 67 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/content_script.js b/content_script.js index 5ec18f6..b7a38f1 100644 --- a/content_script.js +++ b/content_script.js @@ -1,25 +1,50 @@ $(document).ready(function () { - console.log('hello world!'); - var popoverContent; - - $.get('test-menu-content.html', function (data) { - popoverContent = data; - contentReady(); - }); - - function contentReady () { - $('.selected').popover({ - title: "Please select a semantic tag", - - content: popoverContent, - - html: true, - - placement: 'auto' - - }); - - $('.selected').popover('show'); + function processSelection () { + var focused = document.activeElement; + var selectedText; + if (focused) { + try { + selectedText = focused.value.substring( + focused.selectionStart, focused.selectionEnd); + } catch (err) { + } + } + if (selectedText == undefined) { + var sel = window.getSelection(); + var selectedText = sel.toString(); + } + console.log(selectedText); } + + document.addEventListener('click', function(evt) { + if (!document.hasFocus()) { + return true; + } + processSelection(); + // evt.stopPropagation(); + // evt.preventDefault(); + }, false); + + // var popoverContent; + + // $.get('test-menu-content.html', function (data) { + // popoverContent = data; + // contentReady(); + // }); + + // function contentReady () { + // $('.selected').popover({ + // title: "Please select a semantic tag", + + // content: popoverContent, + + // html: true, + + // placement: 'auto' + + // }); + + // $('.selected').popover('show'); + // } }); \ No newline at end of file