# = 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. # ----- # LAST UPDATE: 2006/06/21 -- Thomas Adam # ----- # Called when the user enters something into the goto URL dialog. def ELinks::goto_url_hook(url, current_url) case url #when /localhost/ # return "https://localhost/" when /test-ruby/ # Currently used for debugging the exported variables. message(ELinks::VERSION + " - " + ELinks::HOME); return current_url #when /n6tadam/ # return "http://edulinux.homeunix.org/~n6tadam/" end return url end # Called when the user decides to load some document by following a link, # entering an URL in the goto URL dialog, loading frames from a frameset (?) # etc. def ELinks::follow_url_hook(url) #message (url.to_s()) return url end # Called when a HTML document has been loaded - before the document rendering # begins. Makes it possible to fix up bad HTML code, remove tags etc. def ELinks::pre_format_html_hook(url, html) # Things start here. Note the match alternation to define those sites # which you want to rerender. # This regexp object is for matching against specific domains. domains="fvwm.lair.be|troubledlands.com|forums.gentoo.org" r = Regexp.new('http:\/\/'"#{domains}"'\/.*') s = Regexp.new('http:\/\/'"#{domains}"'\/view(forum|topic)|posting.*\.(html|php).*') if url.match(/http:\/\/edulinux.homeunix.org\/elinks-render\.html/) html.gsub!(/(
)(.*?)(<\/p>)/, '
()/, '\1 bgcolor="red"> | ') html.gsub!(/(()/i, '\1 bgcolor="green"> | ') # These lines appear at the bottom of the pages as a kind of "key" # for the above changes. html.gsub!(/()/,"No New Posts") html.gsub!(/()/,"New Posts") # Remove duplicate lines within the HTML that would otherwise # repeat the same thing. (Damn annoying) html.gsub!(/([nN]o)|[Nn]ew posts\<\/span\>\<\/td\>/," | ") # As with the red/green background colour for (No|New) Posts # above, a blue colour in the table indicates that the selected # thread is locked. html.gsub!(/( | ()/i, '\1 bgcolor="blue"> | ') # Orange indicates that the selected thread has moved. html.gsub!(/(()/i, '\1 bgcolor="orange"> | ') # Remove image repetitions at the bottom of the page entirely (the # only ever serve as a key for the page above -- this is why I am # using colour here.) html.gsub!(/((.*?<\/td>|<\/td>))/,'') html.gsub!(/( | <\/td>)/i,'')
# Remove all the Link: rel references
html.gsub!(//,'')
# Some phpBB sites use frames. Ugh
html.gsub!(/( |