diff options
| author | Niklas Baumstark | 2012-04-11 02:48:47 +0200 |
|---|---|---|
| committer | Niklas Baumstark | 2012-04-11 02:48:47 +0200 |
| commit | bb37bcc35c2f027242737fcabb17d51c699710a9 (patch) | |
| tree | dfb256190d5507dcb3b1a2b68e289289122e153d /lib | |
| parent | 09aaab6967881b22431d3e4eaafdac14865fdda0 (diff) | |
| download | vimium-bb37bcc35c2f027242737fcabb17d51c699710a9.tar.bz2 | |
fix domain completion
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/completion.js | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/lib/completion.js b/lib/completion.js index 8b63fab0..81ce2f04 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -499,29 +499,43 @@ var completion = (function() { DomainCompletionSource.prototype.withDomains = function(callback) { var self = this; + function buildResult() { + return Object.keys(self.domains).map(function(dom) { + return [dom, self.domains[dom]]; + }); + } if (self.domains !== null) - return callback(Object.keys(self.domains)); + return callback(buildResult()); self.domains = {}; - function processDomain(domain) { - self.domains[domain] = true; + function processDomain(domain, https) { + // non-www version is preferrable, so check if we have it already + if (domain.indexOf('www.') == 0 && self.domains.hasOwnProperty(domain.slice(4))) + domain = domain.slice(4); + + // HTTPS is preferrable + https = https || self.domains[domain] || self.domains['www.' + domain]; + + self.domains[domain] = !!https; delete self.domains['www.' + domain]; } - function extractDomain(url) { return url.split('/')[2]; } + function processUrl(url) { + parts = url.split('/'); + processDomain(parts[2], parts[0] == 'https:'); + } historyCache.use(function(history) { history.forEach(function(item) { - processDomain(extractDomain(item.url)); + processUrl(item.url); }); }); - // delete redundant www. domains - Object.keys(self.domains).forEach(function(domain) { processDomain(domain); }); chrome.history.onVisited.addListener(function(item) { - processDomain(extractDomain(item.url)); + processUrl(item.url); }); - callback(Object.keys(self.domains)); + + callback(buildResult()); } DomainCompletionSource.prototype.refresh = function() { } @@ -529,7 +543,10 @@ var completion = (function() { var best = null; this.withDomains(function(domains) { var bestOffset = 1000; - domains.forEach(function(domain) { + domains.forEach(function(result) { + var domain = result[0]; + var protocol = result[1] ? 'https' : 'http'; + var offset = domain.indexOf(query); if (offset < 0 || offset >= bestOffset) return; @@ -539,7 +556,7 @@ var completion = (function() { best = new LazyCompletion(-1.5, function() { return { html: createCompletionHtml('site', domain), - action: {func: 'completion.createActionOpenUrl', args: [utils.createFullUrl(domain)]}, + action: {func: 'completion.createActionOpenUrl', args: [protocol + '://' + domain]}, }}); }); }); |
