From 72e03632cabe47b21384bbcaa29c228c3509616a Mon Sep 17 00:00:00 2001 From: Alejandro Samboy Date: Thu, 25 Oct 2018 12:13:48 -0400 Subject: [PATCH 1/4] Moved duplicate code to getText function. --- selection.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/selection.js b/selection.js index b919f3f..1ad3f4f 100644 --- a/selection.js +++ b/selection.js @@ -263,6 +263,11 @@ const Selection = (function() { document.body.appendChild(div); } + function getText() { + selection = window.getSelection(); + text = selection.toString(); + } + function attachEvents() { function hasSelection() { return !!window.getSelection().toString(); @@ -278,8 +283,7 @@ const Selection = (function() { setTimeout(function mouseTimeout() { if (hasTooltipDrawn()) { if (hasSelection()) { - selection = window.getSelection(); - text = selection.toString(); + getText(); moveTooltip(); return; } else { @@ -287,8 +291,7 @@ const Selection = (function() { } } if (hasSelection()) { - selection = window.getSelection(); - text = selection.toString(); + getText(); drawTooltip(); } }, 10); From 018874db1dca63a6cd0c05c2a686fdc3b8cbf4a6 Mon Sep 17 00:00:00 2001 From: Alejandro Samboy Date: Thu, 25 Oct 2018 12:34:28 -0400 Subject: [PATCH 2/4] Removed trailing spaces. --- selection.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/selection.js b/selection.js index 1ad3f4f..4db5c7d 100644 --- a/selection.js +++ b/selection.js @@ -45,15 +45,15 @@ const Selection = (function() { ); } - function getBrowserLanguage(){ - let language = navigator.language || navigator.userLanguage || function (){ - const languages = navigator.languages; - if (navigator.languages.length > 0){ - return navigator.languages[0]; - } - }() || 'en'; - return language.split('-')[0]; - } + function getBrowserLanguage(){ + let language = navigator.language || navigator.userLanguage || function (){ + const languages = navigator.languages; + if (navigator.languages.length > 0){ + return navigator.languages[0]; + } + }() || 'en'; + return language.split('-')[0]; + } function _selection() { const menu = { From 53274a1cb2f90e186b791e5b96934774cbb6f25e Mon Sep 17 00:00:00 2001 From: Alejandro Samboy Date: Thu, 25 Oct 2018 12:42:05 -0400 Subject: [PATCH 3/4] Making use of previously unused variable. --- selection.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/selection.js b/selection.js index 4db5c7d..048d12e 100644 --- a/selection.js +++ b/selection.js @@ -48,8 +48,8 @@ const Selection = (function() { function getBrowserLanguage(){ let language = navigator.language || navigator.userLanguage || function (){ const languages = navigator.languages; - if (navigator.languages.length > 0){ - return navigator.languages[0]; + if (languages.length > 0){ + return languages[0]; } }() || 'en'; return language.split('-')[0]; From 24c3a6046b0b2038e36a03a01031cc487b171dc9 Mon Sep 17 00:00:00 2001 From: Alejandro Samboy Date: Thu, 25 Oct 2018 12:50:52 -0400 Subject: [PATCH 4/4] Removed unnecessary else (the code won't execute if the previous if is true because of the return). --- selection.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/selection.js b/selection.js index 048d12e..d7d98cf 100644 --- a/selection.js +++ b/selection.js @@ -286,9 +286,8 @@ const Selection = (function() { getText(); moveTooltip(); return; - } else { - document.querySelector('.selection').remove(); } + document.querySelector('.selection').remove(); } if (hasSelection()) { getText();