[Conkeror] [PATCH 2/2] search-engine: provide alternative urls for search engine webjumps
David Kettler
kettler at internode.on.net
Fri Feb 6 20:49:36 PST 2009
The alternative url is visited when the user provides no arguments to
the webjump; thus the webjump can function both as a way to invoke a
search and as a bookmark.
The alternative may be specified to define_search_engine_webjump().
If no alternative is supplied, conkeror will try to guess an
appropriate url. The guess uses the text/html url for the search
engine and trims off the path and any "search." prefix on the domain.
This works for all the supplied search engines.
---
Maybe it would be better to attach the alternative to the webjump
object and to have the alternative logic in getWebJump(). Then it
need not be in the handlers specified in define_webjump() and
define_search_engine_webjump().
---
modules/search-engine.js | 24 +++++++++++++++++++++++-
1 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/modules/search-engine.js b/modules/search-engine.js
index 010ec57..73c3c92 100644
--- a/modules/search-engine.js
+++ b/modules/search-engine.js
@@ -292,6 +292,19 @@ search_engine.prototype.__defineGetter__("completer", function () {
}
});
+/**
+ * Take a guess at a home page to correspond with the search engine.
+ * This works for all the provided search engines.
+ */
+search_engine.prototype.intuit_home_page = function() {
+ var url = this.urls.get("text/html");
+ if (!url)
+ return null;
+ url = url_path_trim(url.template);
+ url = url.replace("//search.", "//");
+ return url;
+}
+
// Load search engines from default directories
{
let dir = file_locator.get("CurProcD", Ci.nsIFile);
@@ -305,16 +318,25 @@ search_engine.prototype.__defineGetter__("completer", function () {
load_search_engines_in_directory(dir);
}
+define_keywords("$alternative");
function define_search_engine_webjump(search_engine_name, key) {
+ keywords(arguments);
var eng = search_engines.get(search_engine_name);
+ let alternative = arguments.$alternative;
if (key == null)
key = search_engine_name;
+ if (alternative == null)
+ alternative = eng.intuit_home_page();
define_webjump(key,
function (arg) {
- return eng.get_query_load_spec(arg);
+ if (arg == null && alternative)
+ return alternative
+ else
+ return eng.get_query_load_spec(arg);
},
+ $alternative = alternative,
$description = eng.description,
$completer = eng.completer);
}
--
1.5.6.5
More information about the Conkeror
mailing list