mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 20:07:59 +01:00
- use default firefox engines
:qsadd, :qsdel commands not yet done
This commit is contained in:
@@ -151,32 +151,28 @@ function parseBookmarkString(str, res)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* also ensures that each search engine has a vimperator-friendly alias */
|
||||
function getSearchEngines()
|
||||
{
|
||||
var search_engines = [];
|
||||
const nsSS = Components.classes["@mozilla.org/browser/search-service;1"].
|
||||
getService(Components.interfaces.nsIBrowserSearchService);
|
||||
var engines = nsSS.getVisibleEngines({ });
|
||||
for(var i in engines)
|
||||
var firefox_engines = nsSS.getVisibleEngines({ });
|
||||
for(var i in firefox_engines)
|
||||
{
|
||||
alert(engines[i].alias);
|
||||
if (!engines[i].alias || !engines[i].alias.match(/^\w+$/))
|
||||
if (!firefox_engines[i].alias || !firefox_engines[i].alias.match(/^\w+$/))
|
||||
{
|
||||
alias = engines[i].name.replace(/^\W*(\w+).*/, "$1").toLowerCase();
|
||||
engines[i].alias = alias;
|
||||
var alias = firefox_engines[i].name.replace(/^\W*(\w+).*/, "$1").toLowerCase();
|
||||
firefox_engines[i].alias = alias;
|
||||
}
|
||||
search_engines.push([firefox_engines[i].alias, firefox_engines[i].description]);
|
||||
|
||||
// alert(engines[i].alias);
|
||||
// alert(engines[i].name);
|
||||
// alert(engines[i].description);
|
||||
}
|
||||
// var def = nsSS.getDefaultEngine();
|
||||
// if(def)
|
||||
// {
|
||||
// alert('DEFAULT'):
|
||||
// alert(def.alias);
|
||||
// }
|
||||
// alert(def.name);
|
||||
// alert(def.description);
|
||||
|
||||
return search_engines;
|
||||
}
|
||||
|
||||
// vim: set fdm=marker sw=4 ts=4 et:
|
||||
|
||||
@@ -1020,19 +1020,19 @@ var g_hint_mappings = [ /*{{{*/
|
||||
["<Esc>", "", true, true]
|
||||
]; /*}}}*/
|
||||
|
||||
var g_searchengines = [ /*{{{*/
|
||||
["google", "http://www.google.com/search?num=100&q=%s"],
|
||||
["lucky", "http://www.google.com/search?num=100&q=%s&btnI=I'm%20Feeling%20Lucky"],
|
||||
["chefkoch", "http://www.chefkoch.de/rezept-suche.php?Suchbegriff=%s"],
|
||||
["dewiki", "http://de.wikipedia.org/wiki/%s"],
|
||||
["discogs", "http://www.discogs.com/search?type=all&q=%s&btn=Search"],
|
||||
["geizhals", "http://geizhals.at/?fs=%s"],
|
||||
["imdb", "http://www.imdb.com/find?s=all&q=%s"],
|
||||
["leo", "http://dict.leo.org/ende?search=%s"],
|
||||
["wien", "http://members.aon.at/flole/vienna.html?UserQuery=%s&ResUser=1024&WidthUser=2000"],
|
||||
["wiki", "http://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go"],
|
||||
["vim", "http://www.google.com/custom?q=%s&sa=Google+Search&cof=LW%3A125%3BL%3Ahttp%3A%2F%2Fvim.sf.net%2Fimages%2Fvim.gif%3BLH%3A60%3BAH%3Acenter%3BGL%3A0%3BS%3Ahttp%3A%2F%2Fwww.vim.org%3BAWFID%3A057fa53529d52655%3B&domains=vim.sourceforge.net%3Bwww.vim.org%3Bvimdoc.sourceforge.net&sitesearch=vim.sourceforge.net"]
|
||||
];/*}}}*/
|
||||
//var g_searchengines = [ /*{{{*/
|
||||
// ["google", "http://www.google.com/search?num=100&q=%s"],
|
||||
// ["lucky", "http://www.google.com/search?num=100&q=%s&btnI=I'm%20Feeling%20Lucky"],
|
||||
// ["chefkoch", "http://www.chefkoch.de/rezept-suche.php?Suchbegriff=%s"],
|
||||
// ["dewiki", "http://de.wikipedia.org/wiki/%s"],
|
||||
// ["discogs", "http://www.discogs.com/search?type=all&q=%s&btn=Search"],
|
||||
// ["geizhals", "http://geizhals.at/?fs=%s"],
|
||||
// ["imdb", "http://www.imdb.com/find?s=all&q=%s"],
|
||||
// ["leo", "http://dict.leo.org/ende?search=%s"],
|
||||
// ["wien", "http://members.aon.at/flole/vienna.html?UserQuery=%s&ResUser=1024&WidthUser=2000"],
|
||||
// ["wiki", "http://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go"],
|
||||
// ["vim", "http://www.google.com/custom?q=%s&sa=Google+Search&cof=LW%3A125%3BL%3Ahttp%3A%2F%2Fvim.sf.net%2Fimages%2Fvim.gif%3BLH%3A60%3BAH%3Acenter%3BGL%3A0%3BS%3Ahttp%3A%2F%2Fwww.vim.org%3BAWFID%3A057fa53529d52655%3B&domains=vim.sourceforge.net%3Bwww.vim.org%3Bvimdoc.sourceforge.net&sitesearch=vim.sourceforge.net"]
|
||||
//];/*}}}*/
|
||||
|
||||
var g_modemessages = {};
|
||||
g_modemessages[MODE_NORMAL | MODE_ESCAPE_ALL_KEYS] = "ESCAPE ALL KEYS";
|
||||
@@ -1294,10 +1294,13 @@ function openURLsInNewTab(str, activate)
|
||||
*/
|
||||
function stringToURLs(str)
|
||||
{
|
||||
const search_service = Components.classes["@mozilla.org/browser/search-service;1"].
|
||||
getService(Components.interfaces.nsIBrowserSearchService);
|
||||
|
||||
var urls = str.split(/\s*\|\s*/);
|
||||
begin: for(var url=0; url < urls.length; url++)
|
||||
{
|
||||
for(var i=0; i < g_searchengines.length; i++)
|
||||
/*for(var i=0; i < g_searchengines.length; i++)
|
||||
{
|
||||
var regex = new RegExp("^" + g_searchengines[i][0] + "\\s+" + "(.+)");
|
||||
matches = urls[url].match(regex);
|
||||
@@ -1306,7 +1309,32 @@ function stringToURLs(str)
|
||||
urls[url] = g_searchengines[i][1].replace(/%s/, encodeURIComponent(matches[1]));
|
||||
break begin;
|
||||
}
|
||||
}*/
|
||||
|
||||
// first check if the first word is a search engine
|
||||
var matches = urls[url].match(/^\s*(\w+)\s*(.*)/);
|
||||
var alias = matches[1] || null;
|
||||
var text = matches[2] || null;
|
||||
if (alias)
|
||||
{
|
||||
var engine = search_service.getEngineByAlias(alias);
|
||||
if (engine)
|
||||
{
|
||||
if(text)
|
||||
urls[url] = engine.getSubmission(text, null).uri.spec;
|
||||
else
|
||||
urls[url] = engine.searchForm;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* if the string contains a space or does not contain any of: .:/
|
||||
* open it with default search engine */
|
||||
var default_engine = search_service.defaultEngine;
|
||||
if (default_engine)
|
||||
urls[url] = default_engine.getSubmission(urls[url], null).uri.spec;
|
||||
|
||||
|
||||
// check for ./ and ../ (or even .../) to go to a file in the upper directory
|
||||
if (urls[url].match(/^(\.$|\.\/\S*)/))
|
||||
@@ -1337,10 +1365,6 @@ function stringToURLs(str)
|
||||
urls[url] = newLocation;
|
||||
}
|
||||
|
||||
/* if the string contains a space or does not contain any of: .:/
|
||||
* open it with default searchengine */
|
||||
if (urls[url].match(/\s+/) || urls[url].match(/\.|:|\//) == null)
|
||||
urls[url] = g_searchengines[0][1].replace(/%s/, encodeURIComponent(urls[url]));
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
@@ -217,32 +217,39 @@ function get_longest_substring()/*{{{*/
|
||||
if (g_substrings[i].length > longest.length)
|
||||
longest = g_substrings[i];
|
||||
}
|
||||
//alert(longest);
|
||||
return longest;
|
||||
}/*}}}*/
|
||||
|
||||
// function is case insensitive
|
||||
// list = [ [['com1', 'com2'], 'text'], [['com3', 'com4'], 'text'] ]
|
||||
function build_longest_common_substring(list, filter)/*{{{*/
|
||||
{
|
||||
var filtered = [];
|
||||
var filter_length = filter.length;
|
||||
//var filter_length = filter.length;
|
||||
//filter = filter.toLowerCase();
|
||||
|
||||
for (var i = 0; i < list.length; i++)
|
||||
{
|
||||
for (var j = 0; j < list[i][0].length; j++)
|
||||
{
|
||||
if (list[i][0][j].indexOf(filter) == -1)
|
||||
var item = list[i][0][j].toLowerCase();
|
||||
if (item.indexOf(filter) == -1)
|
||||
continue;
|
||||
if (g_substrings.length == 0)
|
||||
{
|
||||
var last_index = list[i][0][j].lastIndexOf(filter);
|
||||
var length = list[i][0][j].length;
|
||||
for (var k = list[i][0][j].indexOf(filter); k != -1 && k <= last_index; k = list[i][0][j].indexOf(filter, k + 1))
|
||||
//alert('if: ' + item);
|
||||
var last_index = item.lastIndexOf(filter);
|
||||
var length = item.length;
|
||||
for (var k = item.indexOf(filter); k != -1 && k <= last_index; k = item.indexOf(filter, k + 1))
|
||||
{
|
||||
for (var l = k + filter_length; l <= length; l++)
|
||||
for (var l = k + filter.length; l <= length; l++)
|
||||
g_substrings.push(list[i][0][j].substring(k, l));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//alert('else: ' + item);
|
||||
g_substrings = g_substrings.filter(function($_) {
|
||||
return list[i][0][j].indexOf($_) >= 0;
|
||||
});
|
||||
@@ -254,10 +261,11 @@ function build_longest_common_substring(list, filter)/*{{{*/
|
||||
return filtered;
|
||||
}/*}}}*/
|
||||
|
||||
/* this function is case senstitive */
|
||||
function build_longest_starting_substring(list, filter)/*{{{*/
|
||||
{
|
||||
var filtered = [];
|
||||
var filter_length = filter.length;
|
||||
//var filter_length = filter.length;
|
||||
for (var i = 0; i < list.length; i++)
|
||||
{
|
||||
for (var j = 0; j < list[i][COMMANDS].length; j++)
|
||||
@@ -267,7 +275,7 @@ function build_longest_starting_substring(list, filter)/*{{{*/
|
||||
if (g_substrings.length == 0)
|
||||
{
|
||||
var length = list[i][COMMANDS][j].length;
|
||||
for (var k = filter_length; k <= length; k++)
|
||||
for (var k = filter.length; k <= length; k++)
|
||||
g_substrings.push(list[i][COMMANDS][j].substring(0, k));
|
||||
}
|
||||
else
|
||||
@@ -368,10 +376,12 @@ function filter_url_array(urls, filter)/*{{{*/
|
||||
|
||||
function get_search_completions(filter)/*{{{*/
|
||||
{
|
||||
if (!filter) return g_searchengines.map(function($_) {
|
||||
var engines = getSearchEngines();
|
||||
|
||||
if (!filter) return engines.map(function($_) {
|
||||
return [$_[0], $_[1]];
|
||||
});
|
||||
var mapped = g_searchengines.map(function($_) {
|
||||
var mapped = engines.map(function($_) {
|
||||
return [[$_[0]], $_[1]];
|
||||
});
|
||||
return build_longest_common_substring(mapped, filter);
|
||||
@@ -476,7 +486,13 @@ function get_file_completions(filter)/*{{{*/
|
||||
return [];
|
||||
|
||||
var compl = match[2] || '';
|
||||
try {
|
||||
var fd = fopen(dir, "<");
|
||||
} catch(e) {
|
||||
// thrown if file does not exist
|
||||
return [ ];
|
||||
}
|
||||
|
||||
if (!fd)
|
||||
return [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user