Skip to content

Commit

Permalink
Prepare searchbar
Browse files Browse the repository at this point in the history
  • Loading branch information
adokseo committed Apr 21, 2021
1 parent 2ff9c25 commit ba10983
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,14 @@ function cacheHistory() {
if (url_parts) {
var part = WEBSITES;

SEARCH.push([decoded_url, item.typedCount]);

for (var j = 0, k = url_parts.length; j < k; j++) {
var name = url_parts[j];

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

if (protocol) {
name = protocol[0] + '/' + name;
name = protocol[0] + '/' + name;
}
}

Expand Down Expand Up @@ -187,6 +185,7 @@ function cacheHistory() {
}

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

for (var category in CATEGORIES) {
Expand Down
17 changes: 10 additions & 7 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ function initSearchBar() {
document.querySelector('header > input').addEventListener('input', function(event) {
var results = [],
first = null,
cursor_position = this.selectionStart;
cursor_position = this.selectionStart,
r = new RegExp('[^\w]' + this.value);

search_results_element.innerHTML = '';

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

for (var i = 0, l = SEARCH.length; i < l; i++) {
var item = SEARCH[i];
var item = SEARCH[i],
m = item[2].match(r);

if (item[0].indexOf(this.value) === 0) {
if (m) {
results.push(item);
}
}
Expand All @@ -146,19 +148,20 @@ function initSearchBar() {
for (var i = 0, l = results.length; i < l; i++) {
var item = document.createElement('div');

item.innerText = results[i][0];
item.style.backgroundImage = 'url(https://' + results[i][0].match(/[^/]+/)[0] + '/favicon.ico)';
item.innerText = results[i][2];
item.dataset.url = results[i][0];
item.style.backgroundImage = 'url(chrome://favicon/' + results[i][0] + ')';

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

window.open('https://' + this.innerText, '_self');
window.open(this.innerText, '_self');
});

search_results_element.appendChild(item);
}

first = results[0][0];
first = results[0][2];

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

0 comments on commit ba10983

Please sign in to comment.