From d8d73622f1f184d288c55b628d3fba4b29114169 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sat, 14 Sep 2019 01:35:44 -0700 Subject: [PATCH 1/2] Fix whitespace format --- src/js/content.js | 24 ++++++++++++------------ src/js/options.js | 16 ++++++++-------- src/js/popup.js | 5 ++--- src/popup.html | 6 +++--- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/js/content.js b/src/js/content.js index 9779667..6b27892 100644 --- a/src/js/content.js +++ b/src/js/content.js @@ -15,13 +15,13 @@ var DEFAULT_CASE_INSENSITIVE = false; /*** VARIABLES ***/ var searchInfo; /*** VARIABLES ***/ - + /*** LIBRARY FUNCTIONS ***/ Element.prototype.documentOffsetTop = function () { return this.offsetTop + ( this.offsetParent ? this.offsetParent.documentOffsetTop() : 0 ); }; Element.prototype.visible = function() { - return (!window.getComputedStyle(this) || window.getComputedStyle(this).getPropertyValue('display') == '' || + return (!window.getComputedStyle(this) || window.getComputedStyle(this).getPropertyValue('display') == '' || window.getComputedStyle(this).getPropertyValue('display') != 'none') } /*** LIBRARY FUNCTIONS ***/ @@ -57,7 +57,7 @@ function isTextNode(node) { /* Check if the given node is an expandable node that will yield text nodes */ function isExpandable(node) { - return node && node.nodeType === ELEMENT_NODE_TYPE && node.childNodes && + return node && node.nodeType === ELEMENT_NODE_TYPE && node.childNodes && !UNEXPANDABLE.test(node.tagName) && node.visible(); } @@ -73,7 +73,7 @@ function highlight(regex, highlightColor, selectedColor, textColor, maxResults) var matchedText = node.data.match(regex)[0]; var matchedTextNode = node.splitText(index); matchedTextNode.splitText(matchedText.length); - var spanNode = document.createElement(HIGHLIGHT_TAG); + var spanNode = document.createElement(HIGHLIGHT_TAG); spanNode.className = HIGHLIGHT_CLASS; spanNode.style.backgroundColor = highlightColor; spanNode.style.color = textColor; @@ -107,7 +107,7 @@ function removeHighlight() { /* Scroll page to given element */ function scrollToElement(element) { - element.scrollIntoView(); + element.scrollIntoView(); var top = element.documentOffsetTop() - ( window.innerHeight / 2 ); window.scrollTo( 0, Math.max(top, window.pageYOffset - (window.innerHeight/2))) ; } @@ -136,13 +136,13 @@ function selectNode(highlightedColor, selectedColor, getNext) { searchInfo.highlightedNodes[searchInfo.selectedIndex].style.backgroundColor = highlightedColor; if(getNext) { if(searchInfo.selectedIndex === length - 1) { - searchInfo.selectedIndex = 0; + searchInfo.selectedIndex = 0; } else { searchInfo.selectedIndex += 1; } } else { if(searchInfo.selectedIndex === 0) { - searchInfo.selectedIndex = length - 1; + searchInfo.selectedIndex = length - 1; } else { searchInfo.selectedIndex -= 1; } @@ -161,7 +161,7 @@ function selectNode(highlightedColor, selectedColor, getNext) { } /* Forward cycle through regex matched elements */ function selectNextNode(highlightedColor, selectedColor) { - selectNode(highlightedColor, selectedColor, true); + selectNode(highlightedColor, selectedColor, true); } /* Backward cycle through regex matched elements */ @@ -189,7 +189,7 @@ function search(regexString, configurationChanged) { 'selectedColor' : DEFAULT_SELECTED_COLOR, 'textColor' : DEFAULT_TEXT_COLOR, 'maxResults' : DEFAULT_MAX_RESULTS, - 'caseInsensitive' : DEFAULT_CASE_INSENSITIVE}, + 'caseInsensitive' : DEFAULT_CASE_INSENSITIVE}, function(result) { initSearchInfo(regexString); if(result.caseInsensitive){ @@ -203,7 +203,7 @@ function search(regexString, configurationChanged) { } else if (regex && regexString != '' && regexString === searchInfo.regexString) { // elements are already highlighted chrome.storage.local.get({ 'highlightColor' : DEFAULT_HIGHLIGHT_COLOR, - 'selectedColor' : DEFAULT_SELECTED_COLOR}, + 'selectedColor' : DEFAULT_SELECTED_COLOR}, function(result) { selectNextNode(result.highlightColor, result.selectedColor); } @@ -227,7 +227,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { chrome.storage.local.get({ 'highlightColor' : DEFAULT_HIGHLIGHT_COLOR, 'selectedColor' : DEFAULT_SELECTED_COLOR - }, + }, function(result) { selectNextNode(result.highlightColor, result.selectedColor); } @@ -238,7 +238,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { chrome.storage.local.get({ 'highlightColor' : DEFAULT_HIGHLIGHT_COLOR, 'selectedColor' : DEFAULT_SELECTED_COLOR - }, + }, function(result) { selectPrevNode(result.highlightColor, result.selectedColor); } diff --git a/src/js/options.js b/src/js/options.js index 2bfc891..69445a1 100644 --- a/src/js/options.js +++ b/src/js/options.js @@ -18,7 +18,7 @@ function markStatus(text, time){ status.textContent = text; setTimeout(function() { status.textContent = ''; - }, time); + }, time); } /* Validate input for max results */ @@ -57,7 +57,7 @@ function saveOptions() { 'instantResults' : document.getElementById('instantResults').checked, 'maxHistoryLength' : document.getElementById('maxHistoryLength').value } - + chrome.storage.local.set(options, function() { markStatus('New settings saved'); }); @@ -72,7 +72,7 @@ function loadOptions() { 'textColor' : DEFAULT_TEXT_COLOR, 'maxResults' : DEFAULT_MAX_RESULTS, 'instantResults' : DEFAULT_INSTANT_RESULTS, - 'maxHistoryLength' : DEFAULT_MAX_HISTORY_LENGTH }, + 'maxHistoryLength' : DEFAULT_MAX_HISTORY_LENGTH }, function(result) { document.getElementById('highlightColor').value = result.highlightColor; document.getElementById('exampleHighlighted').style.backgroundColor = result.highlightColor; @@ -105,18 +105,18 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById('exampleHighlighted').style.backgroundColor = document.getElementById('highlightColor').value; saveOptions(); }); - + document.getElementById('selectedColor').addEventListener('change', function() { document.getElementById('exampleSelected').style.backgroundColor = document.getElementById('selectedColor').value; saveOptions(); }); - + document.getElementById('textColor').addEventListener('change', function() { document.getElementById('exampleHighlighted').style.color = document.getElementById('textColor').value; document.getElementById('exampleSelected').style.color = document.getElementById('textColor').value; saveOptions(); }); - + document.getElementById('maxResults').addEventListener('change', function() { saveOptions(); }); @@ -128,11 +128,11 @@ document.addEventListener('DOMContentLoaded', function() { document.getElementById('maxHistoryLength').addEventListener('change', function() { saveOptions(); }); - + document.getElementById('buttonSave').addEventListener('click', function() { saveOptions(); }); - + document.getElementById('buttonReset').addEventListener('click', function() { restoreDefaults(); }); diff --git a/src/js/popup.js b/src/js/popup.js index fea3f45..a0e0bb1 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -245,7 +245,7 @@ document.getElementById('copy-to-clipboard').addEventListener('click', function }); }); -/* Received returnSearchInfo message, populate popup UI */ +/* Received returnSearchInfo message, populate popup UI */ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { if ('returnSearchInfo' == request.message) { processingKey = false; @@ -340,7 +340,7 @@ function(tabs) { /* Focus onto input form */ document.getElementById('inputRegex').focus(); -window.setTimeout( +window.setTimeout( function(){document.getElementById('inputRegex').select();}, 0); //Thanks to http://stackoverflow.com/questions/480735#comment40578284_14573552 @@ -350,4 +350,3 @@ chrome.storage.local.set({isSearchHistoryVisible: makeVisible}); setCaseInsensitiveElement(); /*** INIT ***/ - diff --git a/src/popup.html b/src/popup.html index bcb68df..ea4b357 100644 --- a/src/popup.html +++ b/src/popup.html @@ -6,7 +6,7 @@