hooks.pl -- Perl hooks for the ELinks text WWW browser
This file contains the Perl hooks for the ELinks text WWW browser.
These hooks change the browser's behavior in various ways. They allow shortcuts to be used in the Goto URL dialog, modifying the source of a page, proxy handling, and other things such as displaying a fortune at exit.
This hooks file reads its configuration from ~/.config/elinks/config.pl. The following is an example of the configuration file:
bork: yep # BORKify Google?
collapse: okay # Collapse all XBEL bookmark folders on exit?
email: # Set to show one's own bugs with the "bug" prefix.
external: wget # Send the current URL to this application.
fortune: elinks # *fortune*, *elinks* tip, or *none* on quit?
googlebeta: hell no # I miss DejaNews...
gotosearch: why not # Anything not a URL in the Goto URL dialog...
ipv6: sure # IPV4 or 6 address blocks with "ip" prefix?
language: english # "bf nl en" still works, but now "bf nl" does too
news: msnbc # Agency to use for "news" and "n" prefixes
search: elgoog # Engine for (search|find|www|web|s|f|go) prefixes
usenet: google # *google* or *standard* view for news:// URLs
weather: cnn # Server for "weather" and "w" prefixes
# news: bbc, msnbc, cnn, fox, google, yahoo, reuters, eff, wired,
# slashdot, newsforge, usnews, newsci, discover, sciam
# search: elgoog, google, yahoo, ask jeeves, a9, altavista, msn, dmoz,
# dogpile, mamma, webcrawler, netscape, lycos, hotbot, excite
# weather: weather underground, google, yahoo, cnn, accuweather,
# ask jeeves
Developer's usage: The function loadrc() takes a preference name as its single argument and returns either an empty string if it is not specified, yes for a true value (even if specified like sure or why not), no for a false value (even if like nah, off or 0), or the lowercased preference value (like cnn for weather: CNN
).
This is a summary of the shortcuts defined in this file for use in the Goto URL dialog. They are similar to the builtin URL prefixes, but more flexible and powerful.
These routines do a name->URL mapping - for example, the goto_url_hook() described above maps a certain prefix to google
and then asks the search() mapping routine described below to map the google
string to an appropriate URL.
There are generally two URLs for each name. One to go to the particular URL's main page, and another for a search on the given site (if any string is specified after the prefix). A few of these prefixes will change their behavior depending on the URL currently beung displayed in the browser.
bugmenot or bn
default engine: search, find, www, web, s, f, go
The %search_engines hash maps each engine name to two URLs, home and search. With search, the query is appended to the URL.
The search engines mapping is done by the search() function, taking the search engine name as its first parameter and optional search string as its second parameter. It returns the mapped target URL.
default agency: n, news
The %news_servers hash maps each engine name to two URLs, home and search. With search, the query is appended to the mapped URL.
The news servers mapping is done by the news() function, taking the search engine name as its first parameter and optional search string as its second parameter. It returns the mapped target URL.
The %locators hash maps each engine name to two URLs, home and search.
!current! string in the URL is substitued for the URL of the current document.
!query! string in the search URL is substitued for the search string. If no !query! string is found in the URL, the query is appended to the mapped URL.
The locators mapping is done by the location() function, taking the search engine name as its first parameter, optional search string as its second parameter and the current document's URL as its third parameter. It returns the mapped target URL.
deja, gg, groups, gr, nntp, usenet, nn
md or mirrordot <URL>
cc, coral, or nyud <URL>
babelfish, babel, bf, translate, trans, or b <from> <to>
"babelfish german english" or "bf de en"
vhtml or vcss <URL> (or current url)
There's no place like home...
dia <dialect> <URL> (or current url)
Dialects: redneck, jive, cockney, fudd, bork, moron, piglatin, or hacker
send
Send the current URL to the application specified by the configuration variable 'external'. Optionally, override this by specifying the application as in 'send <application>'.
dict, d, def, or define <word>
ss <domain> <string>
Use Google to search the current site or a specified site. If a domain is not given, use the current one.
These hooks effect a URL before ELinks has a chance to load it.
Rewrites many google.com URLs.
Translates any nntp: or news: URLs to Google Groups HTTP URLs.
When an HTML document is downloaded and is about to undergo the final rendering, this hook is called. This is frequently used to get rid of ads, but also various ELinks-unfriendly HTML code and HTML snippets which are irrelevant to ELinks but can obfuscate the rendered document.
Note that these hooks are applied only before the final rendering, not before the gradual re-renderings which happen when only part of the document is available.
Kills Slashdot's Advertisements. (This one is disabled due to weird behavior with fragments.)
Kills some irritating Google tips.
Wipes out SourceForge's Ads.
Gmail has obviously never met ELinks...
Rewrites some evil characters to entities and vice versa. These will be disabled until such time as pre_format_html_hook only gets called for content-type:text/html.
The Perl hooks are asked whether to use a proxy for a given URL (or what proxy to actually use). You can use it if you don't want to use a proxy for certain Intranet servers but you need to use it in order to get to the Internet, or if you want to use some anonymizer for access to certain sites.
Prevents proxy usage for local files and http://localhost
.
The Perl hooks can also perform various actions when ELinks quits. These can be things like retouching the just saved "information files", or doing some fun stuff.
Collapses XBEL bookmark folders. This is obsoleted by bookmarks.folder_state.
A few words of wisdom from ELinks the Sage.
elinks(1), perl(1)
Russ Rowan, Petr Baudis