Development :  K-Meleon Forum
K-Meleon development related discussions. 
macro: search switches
Posted by: po
Date: September 26, 2002 04:22PM

one of the problems with a browser this configurable is that you start to run out of useful keycombos for accelerators after a while... with recent additions to the macro plugin (namely, the prompt() and substr() functions) it's possible to set up something like IE's quicksearch, where you can prefix a certain string to your search terms to change the search engine used, etc... in this example you can use

i <searchterms>
g <searchterms>
n <searchterms>

which will search google's image, groups, and news databases, respectively (note that the news feature of google is new, and seems to be unavailable sometimes as of this posting). if none of these prefixes exist, a normal google search is performed. this macro will only work in recent beta versions, and even then only if you update the macros.dll file with the one from Ulf's site, since the one included with the last developer's build didn't include support for the prompt() function.
-----------------------------------
google {
$terms = prompt("search terms:","SEARCH GOOGLE...");
$modeswitch = substr($terms, 0, 2);
$modeswitch == "" ? statusbar("search canceled") : $modeswitch == "g " ? open("groups.google.com/groups?q=" . substr($terms, 2)) : $modeswitch == "n " ? open("news.google.com/news?q=" . substr($terms, 2)) : $modeswitch == "i " ? open("images.google.com/images?q=" . substr($terms, 2)) : open("google.com/search?q=" . $terms);
}
-----------------------------------

keeping in mind that there should only be three lines, all ending with ';' (these forums don't seem to have any equivalent to <pre> tags).

i bind this to CTRL+G in the accel.cfg file, and it works very nicely so far... maybe somebody can improve on it. smiling smiley

Options: ReplyQuote
Re: macro: search switches
Posted by: SlideRule
Date: September 27, 2002 01:29AM

Po:

I really like the macro you defined for search switches.

I made a few modifications, for my own implementation. Perhaps, you could incorporate them (or some of them) into yours.

1. Included in the switches, is a 'dictionary' search, that is dependent on the macro variable you once defined "$dictionary" so can easily change the dictionary search URL.
2. Adjusted the number of results to return for, news, groups, and web search with: num=100
3. Changed the prompt words to display the possible search switches . . . as a reminder for user.
4. NOTE: as defined, the "search switches" MUST be in lower case, or the macro will not work correctly. Should the switches also work with upper case characters? ? ?


google {
$terms = prompt("Enter Search Terms: (d = dictionary; g = groups; i = images; n = news;)","Google Search ...");
$modeswitch = substr($terms, 0, 2);
$modeswitch == "" ? statusbar("Search Canceled") : $modeswitch == "d " ? open($dictionary . substr($terms, 2)) : $modeswitch == "g " ? open("groups.google.com/groups?num=100&q=" . substr($terms, 2)) : $modeswitch == "n " ? open("news.google.com/news?num=100&q=" . substr($terms, 2)) : $modeswitch == "i " ? open("images.google.com/images?&q=" . substr($terms, 2)) : open("google.com/search?num=100&q=" . $terms);
}

keep in mind that there should be only three lines, all ending with ';'

Options: ReplyQuote
Re: macro: search switches
Posted by: jsnj
Date: January 03, 2003 03:34AM

Do you guys or anyone else know how to make this macro work using more than one letter for the prefix?

Options: ReplyQuote
Re: macro: search switches
Posted by: asmpgmr
Date: January 03, 2003 05:05AM

Use the index function to search for the first blank in the input string and use that value - 1 (unless it's -1 meaning not found) as the third argument to substr to get the prefix.

Options: ReplyQuote
Re: macro: search switches
Posted by: po
Date: January 03, 2003 06:43AM

the thread below is somewhat of a continuation on this one:

http://kmeleon.sourceforge.net/forum/read.php?f=3&i=2844&t=2797

it presents a much expanded search macro, with the ability to use any string for selecting the search, and a more maintainable structure, thanks to Ulf.

Options: ReplyQuote
Re: macro: search switches
Posted by: asmpgmr
Date: January 03, 2003 10:37AM

Here's another search macro, it can be expanded by adding $var == "string" ... lines.

search {
$str = prompt("Enter search query:", "Search");
$str == "" ? $i = -1 : $i = index($str, " ");
$i != -1 ? $var = substr($str, 0, $i) : $var = "";
$srch = "";
$var == "g" ? $srch = "http://groups.google.com/groups?q="; : "";
$var == "i" ? $srch = "http://images.google.com/images?q="; : "";
$var == "n" ? $srch = "http://news.google.com/news?q="; : "";
$var == "gl" ? $srch = "http://labs.google.com/glossary?q="; : "";
$srch == "" ? $srch = "http://www.google.com/search?q="; : $str = substr($str, $i+1);
$str == "" ? "" : open($srch . $str);
}

Options: ReplyQuote
Re: macro: search switches
Posted by: jsnj
Date: January 03, 2003 02:07PM

Thanks guys.

I ended up using the following based on the one referenced in the hyperlinked thread. Seems to work without a problem although I'm not sure it's completely clean with my slight modifications. Since I use the quicksearch feature from the url bar with Ctrl Q and also sometimes from the prompt, it allows me to only have to write new engines into a macro once instead of having to write them into 2 separate macros.

get_engine {
$new_engine = "";
$engine = "http://search.yahoo.com/bin/search?p=";;
$modeswitch == "" ? $new_engine = "http://search.yahoo.com/bin/search?p="; : 0;
$modeswitch == "mw" ? $new_engine = "http://www.m-w.com/cgi-bin/dictionary?"; : 0;
$modeswitch == "d" ? $new_engine = "http://www.dictionary.com/search?q="; : 0;
$modeswitch == "g" ? $new_engine = "http://www.google.com/search?num=64&q="; : 0;
$modeswitch == "gg" ? $new_engine = "http://groups.google.com/groups?num=100&hl=en&q="; : 0;
$modeswitch == "i" ? $new_engine = "http://images.google.com/images?q="; : 0;
$modeswitch == "n" ? $new_engine = "http://news.google.com/news?q="; : 0;
$modeswitch == "u" ? $new_engine = "http://wwwapps.ups.com/WebTracking/processInputRequest?HTMLVersion=5.0&sort_by=status&term_warn=yes&button_index=201&tracknums_displayed=5&TypeOfInquiryNumber=T&loc=en_US&AgreeToTermsAndConditions=yes&track.x=24&track.y=10&InquiryNumber1="; : 0;
$modeswitch == "m" ? $new_engine = "http://search.movies.yahoo.com/moviesintgsearch?search=all&p="; : 0;
$modeswitch == "p" ? $new_engine = "http://profiles.yahoo.com/"; : 0;
$modeswitch == "yg" ? $new_engine = "http://groups.yahoo.com/group/"; : 0;
}

parse_terms {
$i = index($terms, " ");
$modeswitch = ($i != -1 ? substr($terms, 0, $i) : "");
macros(get_engine);
$word = ($new_engine == "" ? $terms : substr($terms, $i+1));
$engine = ($new_engine == "" ? $engine : $new_engine);
}

Search {
$terms = prompt("Quicksearch = letter(s)+space+word... as defined in macros","Yahoo Search or Quicksearch");
$terms == "" ? ($word = "") : macros(parse_terms);
$word == "" ? "" : pluginmsg("layers", "OpenURL", $engine . $word );
}

Quicksearch {
$oldclip = getclipboard();
id(ID_SELECT_URL);
id(ID_EDIT_COPY);
$terms = getclipboard();
setclipboard($oldclip);
$terms == "" ? ($word = "") : macros(parse_terms);
$word == "" ? "" : pluginmsg("layers", "OpenURL", $engine . $word );
}

Options: ReplyQuote
Re: macro: search switches
Posted by: jsnj
Date: January 03, 2003 02:10PM

Damn, sorry for widening the page.

Options: ReplyQuote
Re: macro: search switches
Posted by: asmpgmr
Date: January 03, 2003 10:35PM

I enhanced my search macro to preload the previous search string in the prompt. The global variable is used to avoid the undefined variable error the first time the search macro is called.

$qry = "";
search {
$qry = prompt("Enter search query:", "Search", $qry);
$qry == "" ? $i = -1 : $i = index($qry, " ");
$i != -1 ? $var = substr($qry, 0, $i) : $var = "";
$str = $qry;
$srch = "";
$var == "g" ? $srch = "http://groups.google.com/groups?q="; : "";
$var == "i" ? $srch = "http://images.google.com/images?q="; : "";
$var == "n" ? $srch = "http://news.google.com/news?q="; : "";
$var == "gl" ? $srch = "http://labs.google.com/glossary?q="; : "";
$srch == "" ? $srch = "http://www.google.com/search?q="; : $str = substr($str, $i+1);
$str == "" ? "" : open($srch . $str);
}

Options: ReplyQuote
Re: macro: search switches
Posted by: asmpgmr
Date: January 05, 2003 09:05AM

Added a couple more search entries:

$qry = "";
search {
$qry = prompt("Enter search query:", "Search", $qry);
$qry == "" ? $i = -1 : $i = index($qry, " ");
$i != -1 ? $var = substr($qry, 0, $i) : $var = "";
$str = $qry;
$srch = "";
$var == "g" ? $srch = "http://groups.google.com/groups?q="; : "";
$var == "gd" ? $srch = "http://groups.google.com/groups?scoring=d&q="; : "";
$var == "i" ? $srch = "http://images.google.com/images?q="; : "";
$var == "n" ? $srch = "http://news.google.com/news?q="; : "";
$var == "f" ? $srch = "http://froogle.google.com/froogle?q="; : "";
$var == "gl" ? $srch = "http://labs.google.com/glossary?q="; : "";
$srch == "" ? $srch = "http://www.google.com/search?q="; : $str = substr($str, $i+1);
$str == "" ? "" : open($srch . $str);
}

Options: ReplyQuote
Re: macro: search switches
Posted by: Brian Bruns
Date: January 07, 2003 02:28PM

Made a slight modification to your search - this one includes message id searching for usenet:


google {
$terms = prompt("Enter Search Terms: (d = dictionary; g = groups; m = message-id; i = images; n = news;)","Google Search ...");
$modeswitch = substr($terms, 0, 2);
$modeswitch == "" ? statusbar("Search Canceled") : $modeswitch == "d " ? open($dictionary . substr($terms, 2)) : $modeswitch == "g " ? open("groups.google.com/groups?num=100&q=" . substr($terms, 2)) : $modeswitch == "n " ? open("news.google.com/news?num=100&q=" . substr($terms, 2)) : $modeswitch == "i " ? open("images.google.com/images?&q=" . substr($terms, 2)) : $modeswitch == "m " ? open("groups.google.com/groups?ic=1&selm=" . substr($terms, 2)) : open("google.com/search?num=100&q=" . $terms);
}



bruns@2mbit.com

Options: ReplyQuote
Thank you very much for such a good work
Posted by: Moisha Breit
Date: July 22, 2006 12:40PM

Congratulations on a great web site. I am a new computer user and finding you was like coming home. Continued success. Moisha Breit.

Options: ReplyQuote


K-Meleon forum is powered by Phorum.