2005-09-15 09:58:31 -04:00
|
|
|
# = hooks.rb - ELinks/Ruby hooks
|
|
|
|
#
|
|
|
|
# == Module Constants
|
|
|
|
#
|
|
|
|
# The following global module constants are defined
|
|
|
|
#
|
|
|
|
# * ELinks::VERSION - The ELinks version. :-P
|
|
|
|
#
|
|
|
|
# * ELinks::HOME - The path to ELinks configuration files
|
|
|
|
#
|
|
|
|
# == Debugging Scripts
|
|
|
|
#
|
|
|
|
# When debugging you can use either
|
|
|
|
#
|
|
|
|
# p(obj, ...)
|
|
|
|
#
|
|
|
|
# or
|
|
|
|
#
|
|
|
|
# message(string)
|
|
|
|
#
|
|
|
|
# to print message strings. The printed strings will be shown in a message
|
|
|
|
# box.
|
|
|
|
|
|
|
|
|
|
|
|
# Called when the user enters something into the goto URL dialog.
|
2005-11-25 19:14:08 -05:00
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# @url the URL entered in the goto URL dialog.
|
|
|
|
# @current_url the URL currently being viewed in ELinks.
|
|
|
|
#
|
|
|
|
# Returns the URL to go to. Return nil to use the @url argument as is
|
|
|
|
# (leave it untouched).
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
def ELinks::goto_url_hook(url, current_url)
|
|
|
|
case url
|
|
|
|
when /^localhost$/
|
|
|
|
return "http://localhost/"
|
|
|
|
|
|
|
|
when /test-ruby/
|
|
|
|
# Dump the exported variables.
|
|
|
|
message(ELinks::VERSION + " - " + ELinks::HOME);
|
|
|
|
return current_url
|
|
|
|
end
|
|
|
|
|
|
|
|
return url
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Called when the user decides to load some document by following a link,
|
2008-01-26 23:09:18 -05:00
|
|
|
# entering a URL in the goto URL dialog, loading frames from a frameset (?)
|
2005-09-15 09:58:31 -04:00
|
|
|
# etc.
|
2005-11-25 19:14:08 -05:00
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# @url the URL being followed.
|
|
|
|
#
|
|
|
|
# Returns the URL to be followed. Return nil to use the @url argument as is.
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
def ELinks::follow_url_hook(url)
|
|
|
|
return url
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-01-26 23:09:18 -05:00
|
|
|
# Called when an HTML document has been loaded - before the document rendering
|
2005-09-15 09:58:31 -04:00
|
|
|
# begins. Makes it possible to fix up bad HTML code, remove tags etc.
|
2005-11-25 19:14:08 -05:00
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# @url the URL of the document being loaded.
|
|
|
|
# @html the source of the document being loaded.
|
2005-11-25 19:22:14 -05:00
|
|
|
#
|
|
|
|
# Returns the preformatted source of the document. Return nil to leave the
|
|
|
|
# document source untouched.
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
def ELinks::pre_format_html_hook(url, html)
|
2005-11-25 19:14:08 -05:00
|
|
|
if url.grep("fvwm.lair.be\/(index|viewforum)*.\.php")
|
|
|
|
# I don't like the fact that the <img> tags provide labels as
|
|
|
|
# well as span classes. So we'll remove them.
|
|
|
|
html.gsub!(/(<img src.*\"No new posts\".*\>)/,"<font color=\"green\">No New Posts</font></td>")
|
|
|
|
html.gsub!(/(<img src.*\"New posts\".*\>)/,"<font color=\"red\">New Posts</font></td>")
|
|
|
|
html.gsub!(/<td><span class=\"gensmall\">([nN]o)|[Nn]ew posts\<\/span\>\<\/td\>/,"<td></td>")
|
|
|
|
end
|
2005-09-15 09:58:31 -04:00
|
|
|
return html
|
|
|
|
end
|
2005-11-25 19:14:08 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
# Determining what proxy, if any, should be used to load a requested URL.
|
|
|
|
#
|
2005-11-25 19:14:08 -05:00
|
|
|
# Arguments:
|
|
|
|
# @url the URL to be proxied.
|
|
|
|
#
|
|
|
|
# The hook should return one of the following:
|
|
|
|
# 1. "<host>:<port>" - to use the specified host and port
|
|
|
|
# 2. "" - to not use any proxy
|
|
|
|
# 3. nil - to use the default proxies
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
def ELinks::proxy_hook(url)
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2005-11-25 19:14:08 -05:00
|
|
|
# Called when ELinks quits and can be used to do required clean-ups like
|
|
|
|
# removing any temporary files created by the hooks.
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
def ELinks::quit_hook
|
|
|
|
end
|