diff --git a/js/default.js b/js/default.js index acacba620..af10bae8f 100644 --- a/js/default.js +++ b/js/default.js @@ -171,6 +171,7 @@ require('macHandoff.js').initialize() // default searchbar plugins require('searchbar/placesPlugin.js').initialize() +require('searchbar/domainGuessPlugin.js').initialize() require('searchbar/instantAnswerPlugin.js').initialize() require('searchbar/bangsPlugin.js').initialize() require('searchbar/customBangs.js').initialize() diff --git a/js/searchbar/domainGuessPlugin.js b/js/searchbar/domainGuessPlugin.js new file mode 100644 index 000000000..840507fae --- /dev/null +++ b/js/searchbar/domainGuessPlugin.js @@ -0,0 +1,38 @@ +var searchbarPlugins = require('searchbar/searchbarPlugins.js') + +var urlParser = require('util/urlParser.js') + +function showDomainGuess (text) { + searchbarPlugins.reset('domainGuess') + + if (!text || text.indexOf(' ') !== -1 || text.indexOf('!') === 0 || urlParser.isPossibleURL(text)) { + return + } + + var url + + if (urlParser.isHTTPSUpgreadable(text)) { + url = 'https://' + text + } else { + url = 'http://' + text + } + + searchbarPlugins.addResult('domainGuess', { + icon: 'carbon:earth-filled', + title: text, + secondaryText: l('visitSite'), + url: url + }, { allowDuplicates: true }) +} + +function initialize () { + searchbarPlugins.register('domainGuess', { + index: 3, + trigger: function (text) { + return !!text + }, + showResults: showDomainGuess + }) +} + +module.exports = { initialize } diff --git a/localization/languages/en-US.json b/localization/languages/en-US.json index 6fc6a6c53..286f5b8da 100644 --- a/localization/languages/en-US.json +++ b/localization/languages/en-US.json @@ -35,6 +35,7 @@ "pasteAndGo": "Paste and Go", //context menu item "DDGAnswerSubtitle": "Answer", //this is a noun - it is used as a subtitle when displaying Instant Answers from DuckDuckGo in the searchbar "suggestedSite": "Suggested site", //this is used to label suggested websites from the DuckDuckGo API, + "visitSite": "Visit site", "resultsFromDDG": "Results from DuckDuckGo", //this is used as a label to indicate which results come from DuckDuckGo's API "taskN": "Task %n", //this is used as a way to identify which tab a task is in "task 1", "task 2", ... /* custom commands