From 7c2f6c56000b5af5e86d97b535d02e24a7d1b322 Mon Sep 17 00:00:00 2001 From: Lyall Hamilton Date: Wed, 9 Oct 2013 18:12:05 +1300 Subject: Add favicons to vomnibar completions Favicons are displayed as a background-image style next to urls in similar style to chrome's history page. For tabs the icon is fetched from the url specified by chrome tab's favIconUrl property. Unfortunately extensions to not have access to chrome://favicons/ to get bookmark favicons but fortunately most sites serve a favicon from protocol://hostname/favicon.ico (e.g. http://example.com/favicon.ico) so this url is tried for non-tab types. --- background_scripts/completion.coffee | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index fd41cdc8..a03a3006 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -26,6 +26,7 @@ class Suggestion generateHtml: -> return @html if @html + favIconUrl = @tabFavIconUrl or "#{@getUrlRoot(@url)}/favicon.ico" relevancyHtml = if @showRelevancy then "#{@computeRelevancy()}" else "" # NOTE(philc): We're using these vimium-specific class names so we don't collide with the page's CSS. @html = @@ -34,12 +35,19 @@ class Suggestion #{@type} #{@highlightTerms(Utils.escapeHtml(@title))} -
+
#{@shortenUrl(@highlightTerms(@url))} #{relevancyHtml}
""" + # use neat trick to snatch a domain (http://stackoverflow.com/a/8498668) + getUrlRoot: (url) -> + a = document.createElement 'a' + a.href = url + a.protocol + "//" + a.hostname + shortenUrl: (url) -> @stripTrailingSlash(url).replace(/^http:\/\//, "") stripTrailingSlash: (url) -> @@ -241,6 +249,7 @@ class TabCompleter suggestions = results.map (tab) => suggestion = new Suggestion(queryTerms, "tab", tab.url, tab.title, @computeRelevancy) suggestion.tabId = tab.id + suggestion.tabFavIconUrl = tab.favIconUrl suggestion onComplete(suggestions) -- cgit v1.2.3