From a57b7ea02d9c40580c3238f240bd9fae7d50d6f7 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 9 Apr 2016 13:16:03 +0100 Subject: Simplify javascript: URLs in vomnibar. Show "javascript:" URLs as "javascript:...". Fixes #961. --- background_scripts/completion.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 47cc2a23..9980fb10 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -66,11 +66,15 @@ class Suggestion
""" + # Simplify "javascript:" URLs; show them as "javascript:..."; see #961. + simplifyJavascriptUrls: (url) -> + if Utils.hasJavascriptPrefix(url) then "javascript:..." else url + # Use neat trick to snatch a domain (http://stackoverflow.com/a/8498668). getUrlRoot: (url) -> a = document.createElement 'a' -- cgit v1.2.3 From 9f91a3fc41a9ad97e1e92337819145e604ac4f34 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 17 Apr 2016 08:46:57 +0100 Subject: For javascript URLs, do not match javascript content. We only match the text "javascript:...". The affects only the bookmark completer. --- background_scripts/completion.coffee | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 9980fb10..db69f15c 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -66,15 +66,11 @@ class Suggestion """ - # Simplify "javascript:" URLs; show them as "javascript:..."; see #961. - simplifyJavascriptUrls: (url) -> - if Utils.hasJavascriptPrefix(url) then "javascript:..." else url - # Use neat trick to snatch a domain (http://stackoverflow.com/a/8498668). getUrlRoot: (url) -> a = document.createElement 'a' @@ -150,6 +146,8 @@ class Suggestion # Simplify a suggestion's URL (by removing those parts which aren't useful for display or comparison). shortenUrl: () -> + # If we already have display URL, then use it. + @shortUrl ?= @displayUrl return @shortUrl if @shortUrl? # We get easier-to-read shortened URLs if we URI-decode them. url = (Utils.decodeURIByParts(@url) || @url).toLowerCase() @@ -208,7 +206,10 @@ class BookmarkCompleter if @currentSearch.queryTerms.length > 0 @bookmarks.filter (bookmark) => suggestionTitle = if usePathAndTitle then bookmark.pathAndTitle else bookmark.title - RankingUtils.matches(@currentSearch.queryTerms, bookmark.url, suggestionTitle) + bookmark.hasJavascriptPrefix ?= Utils.hasJavascriptPrefix bookmark.url + bookmark.displayUrl ?= "javascript:..." if bookmark.hasJavascriptPrefix + suggestionUrl = bookmark.displayUrl ? bookmark.url + RankingUtils.matches(@currentSearch.queryTerms, suggestionUrl, suggestionTitle) else [] suggestions = results.map (bookmark) => @@ -216,6 +217,7 @@ class BookmarkCompleter queryTerms: @currentSearch.queryTerms type: "bookmark" url: bookmark.url + displayUrl: bookmark.displayUrl title: if usePathAndTitle then bookmark.pathAndTitle else bookmark.title relevancyFunction: @computeRelevancy onComplete = @currentSearch.onComplete @@ -252,7 +254,7 @@ class BookmarkCompleter bookmark.children.forEach((child) => @traverseBookmarksRecursive child, results, bookmark) if bookmark.children computeRelevancy: (suggestion) -> - RankingUtils.wordRelevancy(suggestion.queryTerms, suggestion.url, suggestion.title) + RankingUtils.wordRelevancy(suggestion.queryTerms, suggestion.displayUrl ? suggestion.url, suggestion.title) class HistoryCompleter filter: ({ queryTerms, seenTabToOpenCompletionList }, onComplete) -> -- cgit v1.2.3 From 7e5b2dc0ca85f28c5aebce8686f6e7900ddf94f6 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 17 Apr 2016 09:32:51 +0100 Subject: Do not deduplicate javascript: URLs. --- background_scripts/completion.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index db69f15c..5ceb515f 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -217,9 +217,10 @@ class BookmarkCompleter queryTerms: @currentSearch.queryTerms type: "bookmark" url: bookmark.url - displayUrl: bookmark.displayUrl title: if usePathAndTitle then bookmark.pathAndTitle else bookmark.title relevancyFunction: @computeRelevancy + displayUrl: bookmark.displayUrl + deDuplicate: not bookmark.displayUrl? onComplete = @currentSearch.onComplete @currentSearch = null onComplete suggestions -- cgit v1.2.3 From c4850e7bfa5b894f448d06919f902b7e888b2cc0 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 17 Apr 2016 09:35:47 +0100 Subject: There's no need for a new suggestion property... We do not need "displayUrl", we can re-use "shortUrl" instead. It does what we need already. --- background_scripts/completion.coffee | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 5ceb515f..7cd47a00 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -146,8 +146,6 @@ class Suggestion # Simplify a suggestion's URL (by removing those parts which aren't useful for display or comparison). shortenUrl: () -> - # If we already have display URL, then use it. - @shortUrl ?= @displayUrl return @shortUrl if @shortUrl? # We get easier-to-read shortened URLs if we URI-decode them. url = (Utils.decodeURIByParts(@url) || @url).toLowerCase() @@ -207,8 +205,8 @@ class BookmarkCompleter @bookmarks.filter (bookmark) => suggestionTitle = if usePathAndTitle then bookmark.pathAndTitle else bookmark.title bookmark.hasJavascriptPrefix ?= Utils.hasJavascriptPrefix bookmark.url - bookmark.displayUrl ?= "javascript:..." if bookmark.hasJavascriptPrefix - suggestionUrl = bookmark.displayUrl ? bookmark.url + bookmark.shortUrl ?= "javascript:..." if bookmark.hasJavascriptPrefix + suggestionUrl = bookmark.shortUrl ? bookmark.url RankingUtils.matches(@currentSearch.queryTerms, suggestionUrl, suggestionTitle) else [] @@ -219,8 +217,8 @@ class BookmarkCompleter url: bookmark.url title: if usePathAndTitle then bookmark.pathAndTitle else bookmark.title relevancyFunction: @computeRelevancy - displayUrl: bookmark.displayUrl - deDuplicate: not bookmark.displayUrl? + shortUrl: bookmark.shortUrl + deDuplicate: not bookmark.shortUrl? onComplete = @currentSearch.onComplete @currentSearch = null onComplete suggestions @@ -255,7 +253,7 @@ class BookmarkCompleter bookmark.children.forEach((child) => @traverseBookmarksRecursive child, results, bookmark) if bookmark.children computeRelevancy: (suggestion) -> - RankingUtils.wordRelevancy(suggestion.queryTerms, suggestion.displayUrl ? suggestion.url, suggestion.title) + RankingUtils.wordRelevancy(suggestion.queryTerms, suggestion.shortUrl ? suggestion.url, suggestion.title) class HistoryCompleter filter: ({ queryTerms, seenTabToOpenCompletionList }, onComplete) -> -- cgit v1.2.3