Skip to content

Commit 85527fe

Browse files
committed
Highlight search text when re-opening the popup. Fixes rogershen#3.
Also changed the few remaining tabs to spaces for consistency.
1 parent ea47d49 commit 85527fe

File tree

6 files changed

+67
-59
lines changed

6 files changed

+67
-59
lines changed

LICENSE

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ The MIT License (MIT)
22

33
Copyright (c) 2015 Roger Shen
44

5+
Additional contributors: Chris White (GitHub @cxw42)
6+
57
Permission is hereby granted, free of charge, to any person obtaining a copy
68
of this software and associated documentation files (the "Software"), to deal
79
in the Software without restriction, including without limitation the rights
810
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
911
copies of the Software, and to permit persons to whom the Software is
1012
furnished to do so, subject to the following conditions:
1113

12-
The above copyright notice and this permission notice shall be included in
13-
all copies or substantial portions of the Software.
14+
The above copyright notice and list of contributors, and this permission
15+
notice, shall be included in all copies or substantial portions of the
16+
Software.
1417

1518
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1619
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1720
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1821
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1922
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2023
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
24+
THE SOFTWARE.
25+

src/js/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Received returnSearchInfo message, set badge text with number of results */
22
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
3-
if ('returnSearchInfo' == request.message) {
3+
if ('returnSearchInfo' == request.message) {
44
chrome.browserAction.setBadgeText({
55
'text': String(request.numResults),
66
'tabId': sender.tab.id
77
});
8-
}
8+
}
99
});

src/js/content.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ function search(regexString) {
206206
/*** LISTENERS ***/
207207
/* Received search message, find regex matches */
208208
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
209-
if ('search' == request.message) {
209+
if ('search' == request.message) {
210210
search(request.regexString);
211-
}
211+
}
212212
});
213213

214214
/* Received selectNextNode message, select next regex match */
215215
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
216-
if ('selectNextNode' == request.message) {
216+
if ('selectNextNode' == request.message) {
217217
chrome.storage.local.get({
218218
'highlightColor' : DEFAULT_HIGHLIGHT_COLOR,
219219
'selectedColor' : DEFAULT_SELECTED_COLOR
@@ -222,12 +222,12 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
222222
selectNextNode(result.highlightColor, result.selectedColor);
223223
}
224224
);
225-
}
225+
}
226226
});
227227

228228
/* Received selectPrevNode message, select previous regex match */
229229
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
230-
if ('selectPrevNode' == request.message) {
230+
if ('selectPrevNode' == request.message) {
231231
chrome.storage.local.get({
232232
'highlightColor' : DEFAULT_HIGHLIGHT_COLOR,
233233
'selectedColor' : DEFAULT_SELECTED_COLOR
@@ -236,19 +236,19 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
236236
selectPrevNode(result.highlightColor, result.selectedColor);
237237
}
238238
);
239-
}
239+
}
240240
});
241241

242242
/* Received getSearchInfo message, return search information for this tab */
243243
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
244-
if ('getSearchInfo' == request.message) {
244+
if ('getSearchInfo' == request.message) {
245245
sendResponse({message: "I'm alive!"});
246246
returnSearchInfo();
247-
}
247+
}
248248
});
249249
/*** LISTENERS ***/
250250

251251

252252
/*** INIT ***/
253253
initSearchInfo();
254-
/*** INIT ***/
254+
/*** INIT ***/

src/js/options.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function restoreDefaults() {
9999

100100
/*** LISTENERS ***/
101101
document.addEventListener('DOMContentLoaded', function() {
102-
loadOptions();
102+
loadOptions();
103103

104104
document.getElementById('highlightColor').addEventListener('change', function() {
105105
document.getElementById('exampleHighlighted').style.backgroundColor = document.getElementById('highlightColor').value;
@@ -130,12 +130,12 @@ document.addEventListener('DOMContentLoaded', function() {
130130
saveOptions();
131131
});
132132

133-
document.getElementById('buttonSave').addEventListener('click', function() {
134-
saveOptions();
135-
});
133+
document.getElementById('buttonSave').addEventListener('click', function() {
134+
saveOptions();
135+
});
136136

137-
document.getElementById('buttonReset').addEventListener('click', function() {
138-
restoreDefaults();
139-
});
137+
document.getElementById('buttonReset').addEventListener('click', function() {
138+
restoreDefaults();
139+
});
140140
});
141-
/*** LISTENERS ***/
141+
/*** LISTENERS ***/

src/js/popup.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,20 @@ function passInputToContentScript(){
6060
} else {
6161
document.getElementById('inputRegex').style.backgroundColor = WHITE_COLOR;
6262
}
63-
chrome.tabs.query({
64-
'active': true,
65-
'currentWindow': true
66-
},
67-
function(tabs) {
68-
if ('undefined' != typeof tabs[0].id && tabs[0].id) {
69-
processingKey = true;
70-
chrome.tabs.sendMessage(tabs[0].id, {
71-
'message' : 'search',
72-
'regexString' : regexString,
73-
'getNext' : true
74-
});
75-
sentInput = true;
63+
chrome.tabs.query(
64+
{ 'active': true, 'currentWindow': true },
65+
function(tabs) {
66+
if ('undefined' != typeof tabs[0].id && tabs[0].id) {
67+
processingKey = true;
68+
chrome.tabs.sendMessage(tabs[0].id, {
69+
'message' : 'search',
70+
'regexString' : regexString,
71+
'getNext' : true
72+
});
73+
sentInput = true;
74+
}
7675
}
77-
});
76+
);
7877
}
7978
}
8079

@@ -96,7 +95,7 @@ document.getElementById('clear').addEventListener('click', function() {
9695

9796
/* Received returnSearchInfo message, populate popup UI */
9897
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
99-
if ('returnSearchInfo' == request.message) {
98+
if ('returnSearchInfo' == request.message) {
10099
processingKey = false;
101100
if (request.numResults > 0) {
102101
document.getElementById('numResults').textContent = String(request.currentSelection+1) + ' of ' + String(request.numResults);
@@ -109,7 +108,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
109108
if (request.regexString !== document.getElementById('inputRegex').value) {
110109
passInputToContentScript();
111110
}
112-
}
111+
}
113112
});
114113

115114
/* Key listener for selectNext and selectPrev
@@ -172,4 +171,9 @@ function(tabs) {
172171

173172
/* Focus onto input form */
174173
document.getElementById('inputRegex').focus();
175-
/*** INIT ***/
174+
window.setTimeout(
175+
function(){document.getElementById('inputRegex').select();}, 0);
176+
//Thanks to http://stackoverflow.com/questions/480735#comment40578284_14573552
177+
178+
/*** INIT ***/
179+

src/manifest.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33

44
"name": "Chrome Regex Search",
55
"description": "An extension for Regex Search in lieu of Chrome's CTRL+F",
6-
"version": "1.0.2",
7-
"icons": {
8-
"16": "icons/icons_16.png",
9-
"24": "icons/icons_24.png",
10-
"32": "icons/icons_32.png",
11-
"48": "icons/icons_48.png",
12-
"64": "icons/icons_64.png",
13-
"72": "icons/icons_72.png",
14-
"96": "icons/icons_96.png",
15-
"128": "icons/icons_128.png",
16-
"256": "icons/icons_256.png"
17-
},
6+
"version": "1.0.3",
7+
"icons": {
8+
"16": "icons/icons_16.png",
9+
"24": "icons/icons_24.png",
10+
"32": "icons/icons_32.png",
11+
"48": "icons/icons_48.png",
12+
"64": "icons/icons_64.png",
13+
"72": "icons/icons_72.png",
14+
"96": "icons/icons_96.png",
15+
"128": "icons/icons_128.png",
16+
"256": "icons/icons_256.png"
17+
},
1818
"browser_action": {
19-
"default_icon": {
19+
"default_icon": {
2020
"16": "icons/icons_16.png",
2121
"24": "icons/icons_24.png",
2222
"32": "icons/icons_32.png",
@@ -26,7 +26,7 @@
2626
"96": "icons/icons_96.png",
2727
"128": "icons/icons_128.png",
2828
"256": "icons/icons_256.png"
29-
},
29+
},
3030
"default_popup": "popup.html"
3131
},
3232
"permissions": [
@@ -38,10 +38,10 @@
3838
"persistent": true
3939
},
4040
"content_scripts": [
41-
{
42-
"matches": ["http://*/*", "https://*/*", "file://*/*"],
43-
"js": ["js/content.js"]
44-
}
45-
],
41+
{
42+
"matches": ["http://*/*", "https://*/*", "file://*/*"],
43+
"js": ["js/content.js"]
44+
}
45+
],
4646
"options_page": "options.html"
47-
}
47+
}

0 commit comments

Comments
 (0)