Skip to content

Commit

Permalink
Fix autocomplete logic
Browse files Browse the repository at this point in the history
  • Loading branch information
0kzh committed Apr 24, 2020
1 parent ff58605 commit 36c5380
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions css/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ webview.hidden {
position: absolute;
width: 100%;
z-index: 1000;
user-select: none;
display: flex;
flex-direction: column;
overflow: hidden;
Expand Down
13 changes: 9 additions & 4 deletions js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ function setColor (color, animate=true) {
.ac-entry {
background: ${evenDarker};
color: ${contrast};
transition: background ${animate ? '0.25s' : '0'} ease;
}
Expand Down Expand Up @@ -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]
}
Expand All @@ -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')
Expand All @@ -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

Expand Down
7 changes: 4 additions & 3 deletions js/searchbar/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion js/util/history-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 36c5380

Please sign in to comment.