@@ -6,13 +6,15 @@ var ERROR_TEXT = "Content script was not loaded. Are you currently in the Chrome
66var SHOW_HISTORY_TITLE = "Show search history" ;
77var HIDE_HISTORY_TITLE = "Hide search history" ;
88var HISTORY_IS_EMPTY_TEXT = "Search history is empty." ;
9+ var CLEAR_ALL_HISTORY_TEXT = "Clear History" ;
910var MAX_HISTORY_LENGTH = 30 ;
1011/*** CONSTANTS ***/
1112
1213/*** VARIABLES ***/
1314var sentInput = false ;
1415var processingKey = false ;
1516var searchHistory = null ;
17+ var maxHistoryLength = MAX_HISTORY_LENGTH ;
1618/*** VARIABLES ***/
1719
1820/*** FUNCTIONS ***/
@@ -102,6 +104,7 @@ function createHistoryLineElement(text) {
102104 if ( document . getElementById ( 'inputRegex' ) . value !== text ) {
103105 document . getElementById ( 'inputRegex' ) . value = text ;
104106 passInputToContentScript ( ) ;
107+ document . getElementById ( 'inputRegex' ) . focus ( ) ;
105108 }
106109 } ) ;
107110 var lineDiv = document . createElement ( 'div' ) ;
@@ -123,6 +126,13 @@ function updateHistoryDiv() {
123126 for ( var i = searchHistory . length - 1 ; i >= 0 ; i -- ) {
124127 historyDiv . appendChild ( createHistoryLineElement ( searchHistory [ i ] ) ) ;
125128 }
129+ var clearButton = document . createElement ( 'a' ) ;
130+ clearButton . href = '#' ;
131+ clearButton . type = 'button' ;
132+ clearButton . textContent = CLEAR_ALL_HISTORY_TEXT ;
133+ clearButton . className = 'clearHistoryButton' ;
134+ clearButton . addEventListener ( 'click' , clearSearchHistory ) ;
135+ historyDiv . appendChild ( clearButton ) ;
126136 }
127137 }
128138}
@@ -137,8 +147,8 @@ function addToHistory(regex) {
137147 searchHistory . splice ( i , 1 ) ;
138148 }
139149 }
140- if ( searchHistory . length > MAX_HISTORY_LENGTH ) {
141- searchHistory . splice ( 0 , searchHistory . length - MAX_HISTORY_LENGTH ) ;
150+ if ( searchHistory . length > maxHistoryLength ) {
151+ searchHistory . splice ( 0 , searchHistory . length - maxHistoryLength ) ;
142152 }
143153 chrome . storage . local . set ( { searchHistory : searchHistory } ) ;
144154 updateHistoryDiv ( ) ;
@@ -150,6 +160,13 @@ function setHistoryVisibility(makeVisible) {
150160 document . getElementById ( 'show-history' ) . title = makeVisible ? HIDE_HISTORY_TITLE : SHOW_HISTORY_TITLE ;
151161}
152162
163+ function clearSearchHistory ( ) {
164+ searchHistory = [ ] ;
165+ chrome . storage . local . set ( { searchHistory : searchHistory } ) ;
166+ updateHistoryDiv ( ) ;
167+ }
168+
169+
153170/*** LISTENERS ***/
154171document . getElementById ( 'next' ) . addEventListener ( 'click' , function ( ) {
155172 selectNext ( ) ;
@@ -217,6 +234,7 @@ onkeydown = onkeyup = function(e) {
217234/* Retrieve from storage whether we should use instant results or not */
218235chrome . storage . local . get ( {
219236 'instantResults' : DEFAULT_INSTANT_RESULTS ,
237+ 'maxHistoryLength' : MAX_HISTORY_LENGTH ,
220238 'searchHistory' : null ,
221239 'isSearchHistoryVisible' : false } ,
222240 function ( result ) {
@@ -229,6 +247,10 @@ chrome.storage.local.get({
229247 passInputToContentScript ( ) ;
230248 } ) ;
231249 }
250+ console . log ( result ) ;
251+ if ( result . maxHistoryLength ) {
252+ maxHistoryLength = result . maxHistoryLength ;
253+ }
232254 if ( result . searchHistory ) {
233255 searchHistory = result . searchHistory . slice ( 0 ) ;
234256 } else {
0 commit comments