Skip to content

Commit 3ed79b5

Browse files
committed
Fixed search for domain starts with value
1 parent ba10983 commit 3ed79b5

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

background.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var EXTENSION_ID = chrome.runtime.id,
3131
WEBSITES = {},
3232
URL_PARTS_REGEX = /\/[^/?#]+/g,
3333
PROTOCOL_REGEX = /[^/]+/g,
34+
PROTOCOL_WWW_REGEX = /[^/]+\/\/(www\.)?/,
3435
SEARCH_REGEX = new RegExp('[?&](' + SEARCH_PARAMS.join('|') + ')=([^&]+)');
3536

3637

@@ -185,7 +186,10 @@ function cacheHistory() {
185186
}
186187

187188
BY_DOMAIN.push([key, item.d]);
188-
SEARCH.push([key, item.c || 0, key.match(/\/\/([^/]+)/)[1]]);
189+
190+
var start_with = key.match(PROTOCOL_WWW_REGEX)[0];
191+
192+
SEARCH.push([key.replace(start_with, ''), item.c || 0, start_with]);
189193
}
190194

191195
for (var category in CATEGORIES) {

script.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,21 @@ function initSearchBar() {
132132
}
133133
}*/
134134

135-
for (var i = 0, l = SEARCH.length; i < l; i++) {
135+
/*for (var i = 0, l = SEARCH.length; i < l; i++) {
136136
var item = SEARCH[i],
137-
m = item[2].match(r);
137+
m = item[0].match(r);
138138
139139
if (m) {
140140
results.push(item);
141141
}
142+
}*/
143+
144+
for (var i = 0, l = SEARCH.length; i < l; i++) {
145+
var item = SEARCH[i];
146+
147+
if (item[0].indexOf(this.value) === 0) {
148+
results.push(item);
149+
}
142150
}
143151

144152
results = sort(results, 1);
@@ -148,9 +156,9 @@ function initSearchBar() {
148156
for (var i = 0, l = results.length; i < l; i++) {
149157
var item = document.createElement('div');
150158

151-
item.innerText = results[i][2];
152-
item.dataset.url = results[i][0];
153-
item.style.backgroundImage = 'url(chrome://favicon/' + results[i][0] + ')';
159+
item.innerText = results[i][0];
160+
item.dataset.url = results[i][2] + results[i][0];
161+
item.style.backgroundImage = 'url(chrome://favicon/' + results[i][2] + results[i][0] + ')';
154162

155163
item.addEventListener('click', function() {
156164
search_results_element.style.display = 'none';
@@ -161,7 +169,7 @@ function initSearchBar() {
161169
search_results_element.appendChild(item);
162170
}
163171

164-
first = results[0][2];
172+
first = results[0][0];
165173

166174
if (first) {
167175
search_results_element.children[0].className = 'selected';

0 commit comments

Comments
 (0)