1 # = hooks.rb - ELinks/Ruby hooks
5 # The following global module constants are defined
7 # * ELinks::VERSION - The ELinks version. :-P
9 # * ELinks::HOME - The path to ELinks configuration files
11 # == Debugging Scripts
13 # When debugging you can use either
21 # to print message strings. The printed strings will be shown in a message
25 # Called when the user enters something into the goto URL dialog.
28 # @url the URL entered in the goto URL dialog.
29 # @current_url the URL currently being viewed in ELinks.
31 # Returns the URL to go to. Return nil to use the @url argument as is
32 # (leave it untouched).
34 def ELinks::goto_url_hook(url, current_url)
37 return "http://localhost/"
40 # Dump the exported variables.
41 message(ELinks::VERSION + " - " + ELinks::HOME);
49 # Called when the user decides to load some document by following a link,
50 # entering an URL in the goto URL dialog, loading frames from a frameset (?)
54 # @url the URL being followed.
56 # Returns the URL to be followed. Return nil to use the @url argument as is.
58 def ELinks::follow_url_hook(url)
63 # Called when a HTML document has been loaded - before the document rendering
64 # begins. Makes it possible to fix up bad HTML code, remove tags etc.
67 # @url the URL of the document being loaded.
68 # @html the source of the document being loaded.
70 # Returns the preformatted source of the document. Return nil to leave the
71 # document source untouched.
73 def ELinks::pre_format_html_hook(url, html)
74 if url.grep("fvwm.lair.be\/(index|viewforum)*.\.php")
75 # I don't like the fact that the <img> tags provide labels as
76 # well as span classes. So we'll remove them.
77 html.gsub!(/(<img src.*\"No new posts\".*\>)/,"<font color=\"green\">No New Posts</font></td>")
78 html.gsub!(/(<img src.*\"New posts\".*\>)/,"<font color=\"red\">New Posts</font></td>")
79 html.gsub!(/<td><span class=\"gensmall\">([nN]o)|[Nn]ew posts\<\/span\>\<\/td\>/,"<td></td>")
85 # Determining what proxy, if any, should be used to load a requested URL.
88 # @url the URL to be proxied.
90 # The hook should return one of the following:
91 # 1. "<host>:<port>" - to use the specified host and port
92 # 2. "" - to not use any proxy
93 # 3. nil - to use the default proxies
95 def ELinks::proxy_hook(url)
100 # Called when ELinks quits and can be used to do required clean-ups like
101 # removing any temporary files created by the hooks.
103 def ELinks::quit_hook