Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

best practices of comparing operators, var replaced by let and const in engine #41

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Tortoise SVN
#################

.idea
.svn
bin
obj
Expand Down Expand Up @@ -220,4 +221,4 @@ pip-log.txt
*.mo

#Mr Developer
.mr.developer.cfg
.mr.developer.cfg
2 changes: 1 addition & 1 deletion lib/colorpicker/colorpicker.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions lib/colorpicker/colorpicker.themes.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Common stuff */
.picker-wrapper,
.picker-wrapper,
.slide-wrapper {
position: relative;
float: left;
Expand Down Expand Up @@ -95,7 +95,7 @@
.cp-small .slide-indicator {
width: 100%;
height: 2px;
left: 0px;
left: 0;
background-color: black;
}

Expand All @@ -104,7 +104,7 @@
.cp-fancy {
padding: 10px;
/* background-color: #C5F7EA; */
background: -webkit-linear-gradient(top, #aaa 0%, #222 100%);
background: -webkit-linear-gradient(top, #aaa 0%, #222 100%);
float: left;
border: 1px solid #999;
box-shadow: inset 0 0 10px white;
Expand Down Expand Up @@ -174,4 +174,4 @@
border: 4px solid gray;
background-color: white;
pointer-events: none;
}
}
2 changes: 1 addition & 1 deletion lib/jquery/jquery.min.js

Large diffs are not rendered by default.

488 changes: 245 additions & 243 deletions src/advanced.html

Large diffs are not rendered by default.

669 changes: 327 additions & 342 deletions src/advanced.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/background.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<html>

<head>
<title>Sprint Reader</title>

<!-- Link to jQuery library -->
<script src="../lib/jquery/jquery.min.js"></script>

Expand All @@ -16,4 +15,4 @@
<body>
<textarea id="sandbox"></textarea>;
</body>
</html>
</html>
86 changes: 43 additions & 43 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// This event is triggered on mouseup
document.addEventListener('mouseup',function(event) {
// 1. See what text is selected
var sel = window.getSelection().toString();
const sel = window.getSelection().toString();
// 2. Enable this line to see what the selected text is
//alert(sel);
// 3. Pass the text selection to the background page
Expand All @@ -20,14 +20,14 @@ document.addEventListener('mouseup',function(event) {
// Pass the selected text and variables to the background page
function passSelectionToBackground(selectedText, openReaderAlso) {
// Determine if we have a selection or not
var haveSelection = false;
let haveSelection = false;
if(selectedText.length) { haveSelection = true; }
// Determine if the document is right-to-left
var direction = is_script_rtl(selectedText);

// Determine if the document is right-to-left
let direction = is_script_rtl(selectedText);
if (typeof direction == 'undefined') direction = false;
//alert('RTL: ' + direction);

// Send a message back to the background page
// The message is any valid JSON string
if (openReaderAlso) {
Expand All @@ -46,9 +46,9 @@ function passSelectionToBackground(selectedText, openReaderAlso) {

// Check for RTL
function is_script_rtl(t) {
var d, s1, s2, bodies;
let d, s1, s2, bodies;

//If the browser doesnt support this, it probably doesnt support Unicode 5.2
//If the browser doesn't support this, it probably doesn't support Unicode 5.2
if (!("getBoundingClientRect" in document.documentElement))
return false;

Expand All @@ -74,22 +74,22 @@ function is_script_rtl(t) {

bodies = document.getElementsByTagName('body');
if (bodies) {
var body, r1, r2;
let body, r1, r2;

body = bodies[0];
body = bodies[0];
body.appendChild(d);
var r1 = s1.getBoundingClientRect();
var r2 = s2.getBoundingClientRect();
body.removeChild(d);
r1 = s1.getBoundingClientRect();
r2 = s2.getBoundingClientRect();
body.removeChild(d);

return r1.left > r2.left;
}

return false;
return false;
}

var x;
var y;
let x;
let y;
// Listen for instruction and then return the mouse X,Y coordinates
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.action == 'getMouseCoordinates') {
Expand All @@ -103,70 +103,70 @@ document.addEventListener('mousemove',function(event) {
})

// Access the extension local storage to determine if the hotkey is enabled
var hotKeyEnabled = 'false';
let hotKeyEnabled = 'false';
chrome.runtime.sendMessage({message: "getHotkeyEnabledStatus"}, function(response) {
hotKeyEnabled = response.status;
//console.log(response.status);
});

// Hotkey, auto-text selection management
var keys = {};
var autoSelectEnabled = false;
var keyDown = function(event){
const keys = {};
let autoSelectEnabled = false;
let hoveredEvent;
const outlineElementClass = 'outlineElement_SR';
const notificationClass = 'autoselectNotification_SR';
const notificationText = "Sprint Reader Auto-selection Enabled";
const keyDown = function (event) {
keys[event.which] = true;

// Only proceed with auto-selection if it's enabled
if (hotKeyEnabled == 'false') {
if (hotKeyEnabled === 'false') {
autoSelectEnabled = false;
return;
}
return;
}

// Check for CONTROL+ALT
if(keys.hasOwnProperty(17) && keys.hasOwnProperty(18)) {
if (keys.hasOwnProperty(17) && keys.hasOwnProperty(18)) {
// Toggle the auto-selection
window.autoSelectEnabled = !window.autoSelectEnabled;
window.autoSelectEnabled = !window.autoSelectEnabled;
if (window.autoSelectEnabled) $('body').append('<div class="' + notificationClass + '">' + notificationText + '</div>');
else {
// CONTROL+ALT toggle OFF, let's kill all highlights
$('body').find('div:contains(' + notificationText + ')').remove();
$(hoveredEvent).removeClass(outlineElementClass);
$(hoveredEvent).removeClass(outlineElementClass);
hoveredEvent = "";
}
}
}

// If auto select is enabled and the user hits 'Z'
// we select the text and open the reader
if (window.autoSelectEnabled && event.keyCode === 90) {
var selectedText = $(hoveredEvent).text();
const selectedText = $(hoveredEvent).text();
passSelectionToBackground(selectedText, true);
}
};
window.addEventListener? document.addEventListener('keydown', keyDown) : document.attachEvent('keydown', keyDown);

var keyUp = function(event){
const keyUp = function (event) {
delete keys[event.which];
};
window.addEventListener? document.addEventListener('keyup', keyUp) : document.attachEvent('keyup', keyUp);

var hoveredEvent;
var outlineElementClass = 'outlineElement_SR';
var notificationClass = 'autoselectNotification_SR';
var notificationText = "Sprint Reader Auto-selection Enabled";
$(document).ready(function(){
$(document).ready(function(){
// Only proceed with auto-selection if it's enabled
if (hotKeyEnabled == 'false') {
return;
if (hotKeyEnabled === 'false') {
return;
}

$('*')
.mouseover(function(event) {
if (autoSelectEnabled) {
$(event.target).addClass(outlineElementClass);
$(event.target).addClass(outlineElementClass);
hoveredEvent = event.target;
}
})
.mouseout(function(event) {
$(event.target).removeClass(outlineElementClass);
$(event.target).removeClass(outlineElementClass);
hoveredEvent = "";
});
});
});
Loading