From 36c53803d65c724a0da461360ea53b72e49fc1cd Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Thu, 23 Apr 2020 19:03:14 -0700 Subject: [PATCH] Fix autocomplete logic --- css/browser.css | 1 + js/browser.js | 13 +++++++++---- js/searchbar/autocomplete.js | 7 ++++--- js/util/history-db.js | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/css/browser.css b/css/browser.css index 37ede27..bdb1dbc 100644 --- a/css/browser.css +++ b/css/browser.css @@ -355,6 +355,7 @@ webview.hidden { position: absolute; width: 100%; z-index: 1000; + user-select: none; display: flex; flex-direction: column; overflow: hidden; diff --git a/js/browser.js b/js/browser.js index c4459af..3f77141 100644 --- a/js/browser.js +++ b/js/browser.js @@ -1235,6 +1235,7 @@ function setColor (color, animate=true) { .ac-entry { background: ${evenDarker}; + color: ${contrast}; transition: background ${animate ? '0.25s' : '0'} ease; } @@ -1528,12 +1529,16 @@ function setFavicon (webview, title, url) { chromeTabs.updateTab(el.querySelector('.chrome-tab[tab-id="' + id + '"]'), tabProperties) } -function extractHostname (url) { +function extractHostname (url, keepPaths=true) { var hostname // find & remove protocol (http, ftp, etc.) and get hostname if (url.indexOf('://') > -1) { - hostname = url.split('/')[2] + if (keepPaths) { + hostname = url.replace(/^https?\:\/\/(www.)?/, '') + } else { + hostname = url.split('/')[2] + } } else { hostname = url.split('/')[0] } @@ -1546,7 +1551,7 @@ function extractHostname (url) { return hostname } -function stripURL (url) { +function stripURL (url, keepPaths=true) { if (url.startsWith('about:blank') || url.startsWith('file://') && url.includes(app.getAppPath()) && url.includes("home")) { // filter homepage urls document.documentElement.classList.add('home') @@ -1569,7 +1574,7 @@ function stripURL (url) { // if search, leave search term - var domain = extractHostname(url) + var domain = extractHostname(url, keepPaths) var splitArr = domain.split('.') var arrLen = splitArr.length diff --git a/js/searchbar/autocomplete.js b/js/searchbar/autocomplete.js index cc082e4..6ac0513 100644 --- a/js/searchbar/autocomplete.js +++ b/js/searchbar/autocomplete.js @@ -28,14 +28,15 @@ $("#location").on('input propertychange paste', () => { // push first website result first searchResults = res[0] historyResults = res[1] + console.log(historyResults) if (history != undefined && historyResults[0] != undefined) { list.push(historyResults[0]); } const searchResultCount = historyResults.length == 0 ? 8 : 3; - const truncated = searchResults.slice(0, searchResultCount); + const truncated = searchResults[1].slice(0, searchResultCount); - for (var entry of truncated[1]) { + for (var entry of truncated) { o = { url: "https://google.com/search?q=" + entry, favicon: "https://api.faviconkit.com/google.com/24", @@ -46,7 +47,7 @@ $("#location").on('input propertychange paste', () => { } list.push(o) } - list.concat(historyResults.slice(0, 4)); + list = list.concat(historyResults.slice(0, 4)); displaySites(list); }) } else { diff --git a/js/util/history-db.js b/js/util/history-db.js index 61300ee..bfaa5f9 100644 --- a/js/util/history-db.js +++ b/js/util/history-db.js @@ -35,7 +35,8 @@ var historyWrapper = { }, search: function(key) { return db.sites.orderBy('numVisits').reverse().filter(site => { - return site.title.includes(key) || site.url.includes(key) + console.log(stripURL(site.url)) + return site.title.startsWith(key) || stripURL(site.url).startsWith(key) && !site.title.startsWith('http') }).toArray() }, load: function () {