1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-17 07:13:33 +01:00

Clean up funky stolen firefox code.

This commit is contained in:
Kris Maglione
2009-10-09 00:53:32 -04:00
parent 8b7b290e65
commit cf2fdf8300

View File

@@ -703,7 +703,6 @@ function Bookmarks() //{{{
getSearchURL: function getSearchURL(text, useDefsearch) getSearchURL: function getSearchURL(text, useDefsearch)
{ {
let url = null; let url = null;
let postData = {};
let searchString = (useDefsearch ? options["defsearch"] + " " : "") + text; let searchString = (useDefsearch ? options["defsearch"] + " " : "") + text;
// we need to make sure our custom alias have been set, even if the user // we need to make sure our custom alias have been set, even if the user
@@ -711,73 +710,65 @@ function Bookmarks() //{{{
this.getSearchEngines(); this.getSearchEngines();
// ripped from Firefox // ripped from Firefox
if (!window.getShortcutOrURI) function getShortcutOrURI(url) {
window.getShortcutOrURI = function (aURL, aPostDataRef) {
var shortcutURL = null; var shortcutURL = null;
var keyword = aURL; var keyword = url;
var param = ""; var param = "";
var searchService = Cc['@mozilla.org/browser/search-service;1'].getService(Ci.nsIBrowserSearchService); var offset = url.indexOf(" ");
var offset = aURL.indexOf(" ");
if (offset > 0) if (offset > 0)
{ {
keyword = aURL.substr(0, offset); keyword = url.substr(0, offset);
param = aURL.substr(offset + 1); param = url.substr(offset + 1);
} }
if (!aPostDataRef)
aPostDataRef = {}; var engine = services.get("browserSearch").getEngineByAlias(keyword);
var engine = searchService.getEngineByAlias(keyword);
if (engine) if (engine)
{ {
var submission = engine.getSubmission(param, null); var submission = engine.getSubmission(param, null);
aPostDataRef.value = submission.postData; return [submission.uri.spec, submission.postData];
return submission.uri.spec;
} }
[shortcutURL, aPostDataRef.value] = PlacesUtils.getURLAndPostDataForKeyword(keyword);
[shortcutURL, postData] = PlacesUtils.getURLAndPostDataForKeyword(keyword);
if (!shortcutURL) if (!shortcutURL)
return aURL; return [url, null];
var postData = "";
if (aPostDataRef.value) let data = unescape(postData || "");
postData = unescape(aPostDataRef.value); if (/%s/i.test(shortcutURL) || /%s/i.test(pdata))
if (/%s/i.test(shortcutURL) || /%s/i.test(postData))
{ {
var charset = ""; var charset = "";
const re = /^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/; var matches = shortcutURL.match(/^(.*)\&mozcharset=([a-zA-Z][_\-a-zA-Z0-9]+)\s*$/);
var matches = shortcutURL.match(re);
if (matches) if (matches)
[, shortcutURL, charset] = matches; [, shortcutURL, charset] = matches;
else else
{ {
try try
{ {
charset = PlacesUtils.history.getCharsetForURI(makeURI(shortcutURL)); charset = PlacesUtils.history.getCharsetForURI(window.makeURI(shortcutURL));
} }
catch (e) {} catch (e) {}
} }
var encodedParam = ""; var encodedParam;
if (charset) if (charset)
encodedParam = escape(convertFromUnicode(charset, param)); encodedParam = escape(window.convertFromUnicode(charset, param));
else else
encodedParam = encodeURIComponent(param); encodedParam = encodeURIComponent(param);
shortcutURL = shortcutURL.replace(/%s/g, encodedParam).replace(/%S/g, param); shortcutURL = shortcutURL.replace(/%s/g, encodedParam).replace(/%S/g, param);
if (/%s/i.test(postData)) if (/%s/i.test(data))
aPostDataRef.value = getPostDataStream(postData, param, encodedParam, "application/x-www-form-urlencoded"); postData = window.getPostDataStream(data, param, encodedParam, "application/x-www-form-urlencoded");
} }
else if (param) else if (param)
{ {
aPostDataRef.value = null; return [url, null];
return aURL;
} }
return shortcutURL; return [shortcutURL, postData];
} }
url = window.getShortcutOrURI(searchString, postData); let [url, postData] = getShortcutOrURI(searchString);
if (url == searchString) if (url == searchString)
url = null; return null;
if (postData)
if (postData && postData.value) return [url, postData];
return [url, postData.value];
else
return url; // can be null return url; // can be null
}, },