mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-27 00:43:32 +01:00
The nth person to 'fix' stringToURLArray.
This commit is contained in:
@@ -468,51 +468,40 @@ const util = { //{{{
|
|||||||
return urls.map(function (url) {
|
return urls.map(function (url) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// Try to find a matching file.
|
||||||
let file = io.getFile(url);
|
let file = io.getFile(url);
|
||||||
if (file.exists() && file.isReadable())
|
if (file.exists() && file.isReadable())
|
||||||
return file.path;
|
return file.path;
|
||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
|
|
||||||
// removes spaces from the string if it starts with http:// or something like that
|
|
||||||
if (/^\w+:\/\//.test(url))
|
|
||||||
url = url.replace(/\s+/g, "");
|
|
||||||
|
|
||||||
// strip each 'URL' - makes things simpler later on
|
// strip each 'URL' - makes things simpler later on
|
||||||
url = url.replace(/^\s+|\s+$/, "");
|
url = url.replace(/^\s+|\s+$/, "");
|
||||||
|
|
||||||
// if the string
|
// Look for a valid protocol
|
||||||
// * contains a space OR
|
|
||||||
// * does NOT have a period in it
|
|
||||||
// AND
|
|
||||||
// * has no valid protocol
|
|
||||||
// then assume that we want to defsearch (or bookmark
|
|
||||||
// keyword) it. Otherwise, let Firefox figure it out
|
|
||||||
let proto = url.match(/^([-\w]+):/);
|
let proto = url.match(/^([-\w]+):/);
|
||||||
if ((/\s/.test(url) || !/\./.test(url)) &&
|
if (proto && Components.classes["@mozilla.org/network/protocol;1?name=" + proto[1]])
|
||||||
!(proto && Components.classes["@mozilla.org/network/protocol;1?name=" + proto[1]]))
|
// Handle as URL, but remove spaces. Useful for copied/'p'asted URLs.
|
||||||
{
|
return url.replace(/\s+/g, "");
|
||||||
// TODO: it would be clearer if the appropriate call to
|
|
||||||
// getSearchURL was made based on whether or not the first word was
|
|
||||||
// indeed an SE alias rather than seeing if getSearchURL can
|
|
||||||
// process the call usefully and trying again if it fails - much
|
|
||||||
// like the comments below ;-)
|
|
||||||
|
|
||||||
// check for a search engine match in the string
|
// Ok, not a valid proto. If it looks like URL-ish (foo.com/bar),
|
||||||
let searchURL = bookmarks.getSearchURL(url, false);
|
// let Gecko figure it out.
|
||||||
if (searchURL)
|
if (/[.]/.test(url) && !/\s/.test(url))
|
||||||
{
|
return url;
|
||||||
return searchURL;
|
|
||||||
}
|
// TODO: it would be clearer if the appropriate call to
|
||||||
else // no search engine match, search for the whole string in the default engine
|
// getSearchURL was made based on whether or not the first word was
|
||||||
{
|
// indeed an SE alias rather than seeing if getSearchURL can
|
||||||
searchURL = bookmarks.getSearchURL(url, true);
|
// process the call usefully and trying again if it fails - much
|
||||||
if (searchURL)
|
// like the comments below ;-)
|
||||||
return searchURL;
|
|
||||||
}
|
// check for a search engine match in the string, then try to
|
||||||
}
|
// search for the whole string in the default engine
|
||||||
// if we are here let Firefox handle the url and hope it does
|
let searchURL = bookmarks.getSearchURL(url, false) || bookmarks.getSearchURL(url, true);
|
||||||
// something useful with it :)
|
if (searchURL)
|
||||||
|
return searchURL;
|
||||||
|
|
||||||
|
// Hmm. No defsearch? Let Firefox deal with it, then.
|
||||||
return url;
|
return url;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user