wiki:KeywordExpansion

Keyword expansion

GlimmerBlocker supports 2 forms of keyword expansion:

  1. Simple macro-based expansion just like Firefox.
  2. Javascript based expansion.

Macro based expansion

'%s' is replaced by the URI-encoded search term, and '%S' (capital-S) is replaced by the non-encoded search term.

GlimmerBlocker 1.5.0b4 and later: '%t' is replaced by latin-1 encoded search term (%s uses utf-8 encoding).

Example

The template for the 'trailer' keyword is:

http://www.google.com/search?q=site:www.apple.com/trailers/%20%s&btnI=1

When user enters "trailer right one", the template is expanded to:

http://www.google.com/search?q=site:www.apple.com/trailers/%20right%20one&btnI=1

which performs a "I'm Feeling Lucky" search on Google which automatically redirects you to the Apple site. try it

Javascript based expansion

The javascript runtime is very much like that for the Javascript based transformations.

The differences are:

  1. None of the request related variables are defined: gb.contentType, gb.referer, gb.method,
  2. The gb.url and t variables are initialized to null.
  3. The search terms are stored in the gb.term global. An URI encoded form is stored in gb.encodedTerm
  4. The keyword is stored in gb.keyword. This is useful when the rule uses regexp to match multiple keywords.

Your script should either:

  1. Set the gb.url variable. GlimmerBlocker uses the url for a redirect response to Safari.
  2. Or set global variable t. GlimmerBlocker sends its content as html to Safari.

If neither variables are set, GlimmerBlocker proceeds to use the other rules which matches the keyword. The gb.url variable takes precedence over t.

  1. The object reference
  2. The request/response flow.
  3. Proxies overview.

Example

The 'stock' keyword expansion have been implemented using Javascript. The code is:

gb.url = "http://host.businessweek.com/businessweek/Corporate_Snapshot.html" +
         "?Symbol=" + gb.urlEncode(gb.term.toUpperCase());

Regexp example

Keyword: java regexp "gg?" using Javascript expansion:

if (gb.keyword == "gg") {
  gb.url = "http://www.google.com/search?q=" + gb.encodedTerm + "&btnI=1";
} else {
  gb.url = "http://www.google.com/search?q=" + gb.encodedTerm;
}

The regexp matches either "g" or "gg". The javascript redirects to a "I'm Feeling Lucky" search when the keyword is "gg" and to a normal Google search when the keyword is "g".

Last modified 3 years ago Last modified on 09/09/11 11:35:18