Skip to content

Commit ba10983

Browse files
committed
Prepare searchbar
1 parent 2ff9c25 commit ba10983

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

background.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,14 @@ function cacheHistory() {
8585
if (url_parts) {
8686
var part = WEBSITES;
8787

88-
SEARCH.push([decoded_url, item.typedCount]);
89-
9088
for (var j = 0, k = url_parts.length; j < k; j++) {
9189
var name = url_parts[j];
9290

9391
if (j === 0) {
9492
var protocol = decoded_url.match(PROTOCOL_REGEX);
9593

9694
if (protocol) {
97-
name = protocol[0] + '/' + name;
95+
name = protocol[0] + '/' + name;
9896
}
9997
}
10098

@@ -187,6 +185,7 @@ function cacheHistory() {
187185
}
188186

189187
BY_DOMAIN.push([key, item.d]);
188+
SEARCH.push([key, item.c || 0, key.match(/\/\/([^/]+)/)[1]]);
190189
}
191190

192191
for (var category in CATEGORIES) {

script.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ function initSearchBar() {
110110
document.querySelector('header > input').addEventListener('input', function(event) {
111111
var results = [],
112112
first = null,
113-
cursor_position = this.selectionStart;
113+
cursor_position = this.selectionStart,
114+
r = new RegExp('[^\w]' + this.value);
114115

115116
search_results_element.innerHTML = '';
116117

@@ -132,9 +133,10 @@ function initSearchBar() {
132133
}*/
133134

134135
for (var i = 0, l = SEARCH.length; i < l; i++) {
135-
var item = SEARCH[i];
136+
var item = SEARCH[i],
137+
m = item[2].match(r);
136138

137-
if (item[0].indexOf(this.value) === 0) {
139+
if (m) {
138140
results.push(item);
139141
}
140142
}
@@ -146,19 +148,20 @@ function initSearchBar() {
146148
for (var i = 0, l = results.length; i < l; i++) {
147149
var item = document.createElement('div');
148150

149-
item.innerText = results[i][0];
150-
item.style.backgroundImage = 'url(https://' + results[i][0].match(/[^/]+/)[0] + '/favicon.ico)';
151+
item.innerText = results[i][2];
152+
item.dataset.url = results[i][0];
153+
item.style.backgroundImage = 'url(chrome://favicon/' + results[i][0] + ')';
151154

152155
item.addEventListener('click', function() {
153156
search_results_element.style.display = 'none';
154157

155-
window.open('https://' + this.innerText, '_self');
158+
window.open(this.innerText, '_self');
156159
});
157160

158161
search_results_element.appendChild(item);
159162
}
160163

161-
first = results[0][0];
164+
first = results[0][2];
162165

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

0 commit comments

Comments
 (0)