diff --git a/contrib/ruby/hooks.rb b/contrib/ruby/hooks.rb index 6e0ac0bb3..6f68a122c 100644 --- a/contrib/ruby/hooks.rb +++ b/contrib/ruby/hooks.rb @@ -21,6 +21,9 @@ # 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. # @@ -37,7 +40,7 @@ def ELinks::goto_url_hook(url, current_url) return "http://localhost/" when /test-ruby/ - # Dump the exported variables. + # Currently used for debugging the exported variables. message(ELinks::VERSION + " - " + ELinks::HOME); return current_url end @@ -71,17 +74,139 @@ end # document source untouched. def ELinks::pre_format_html_hook(url, html) - if url.grep("fvwm.lair.be\/(index|viewforum)*.\.php") - # I don't like the fact that the tags provide labels as - # well as span classes. So we'll remove them. - html.gsub!(/()/,"No New Posts") - html.gsub!(/()/,"New Posts") - html.gsub!(/([nN]o)|[Nn]ew posts\<\/span\>\<\/td\>/,"") - end + # 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>)/, '

\2

') return html + end + + if url.match(r) + + # Handle viewtopic.php -- this has some very slightly different + # code to the other pages found on phpBB sites. Again, the match + # alternations are important here -- I ought to define a Regexp + # object to handle this eventually, which would save code + # duplication, at any rate. + if url.match(s) + + # Start with the menubar at the top, and remove the image + # links. We still have to add the description back in so that + # we know what the link references. :) + html.gsub!(/<(img.*?)>(faq|search|memberlist|usergroups|register|profile|you have no new messages|log out \[.*?\]|chat room<\/a>)/i,'\2') + + # Remove the long list of relative links (I don't like them). + html.gsub!(//,'') + + # Turn on borders for the "main" table. + html.gsub!(/()/,'\11\3') + + # In the LHS of the table for each postee, remove their image + # link, and just display their status instead. + html.gsub!(/(.*?)()/i,'\1') + + # Handle the options for each post. Depending on the status + # of the person viewing this site, they could have none or all + # of these -- either way they've been shortened. + html.gsub!(/()/i, '\1\2Q \4') + html.gsub!(/()/i, '\1\2E/D \4') + html.gsub!(/()/i, '\1\2D \4') + html.gsub!(/()/i, '\1\2--> \4') + html.gsub!(/()/i, '\1\2--> \4') + html.gsub!(/()/i, '\1\2--> \4') + html.gsub!(/()/i, '\1\2<-- \4') + + + # See above. + html.gsub!(/()/i, '\1\2IP />') + html.gsub!(/
/, '
') + html.gsub!(/()/i, '\1\2Profile />') + html.gsub!(/()/i, '\1\2PM />') + html.gsub!(/()/i, '\1\2email />') + html.gsub!(/()/i, '\1\2Web /> ') + html.gsub!(/()/i, '\1\2Yahoo />') + html.gsub!(/()/i, '\1\2MSN />') + end + + # PhpBB's index page defines its layout as a series of tables. + # The main table has a class of 'forumline' -- hence setting its + # border property to 1 helps readability and to proide distinct + # lines between the table sections. + html.gsub!(/()/,'\11\3') + + # Change the background colour of the forum pages to white -- the + # default is grey. + html.gsub!(/(body \{\n\tbackground-color: )(\#E5E5E5\;)/,'\1white;') + + # Assuming you've told ELinks to remember your login details (not + # that it matters), the "New posts" and "No New Post" indicators + # were typically just defined in words. This looked ugly. Hence + # in this case, I've changed the table structure to change the + # background colour of these cells. A red colour indicates "No new + # posts", whereas a green colour indicates "New Posts". + html.gsub!(/(') + html.gsub!(/(') + + # 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!(/") + + # 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!(/(') + + # Orange indicates that the selected thread has moved. + html.gsub!(/(') + + # 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!(/(
()/, '\1 bgcolor="red"> ()/i, '\1 bgcolor="green"> ([nN]o)|[Nn]ew posts\<\/span\>\<\/td\>/,"()/i, '\1 bgcolor="blue"> ()/i, '\1 bgcolor="orange"> (.*?<\/td>|<\/td>))/,'') + html.gsub!(/()(<\/td>)/i, '') + html.gsub!(/()(<\/td>)/,'') + + # At the very top of the pages, remove the images, but retain the + # links by way of their alt attributes. (For things like FAQ, + # MemeberList, etc.) + # + # DON'T do this for the pages matched by regexp 's' -- to do so + # would remove many other images those pages rely on (and that + # have been munged in the 's' section above, anyway.) + html.gsub!(/<(img.*?)>(.*?<\/a>)/i, '\2') if not url.match(s) + + # OK -- "View Latest Post" becomes "[<--]" which hopefully points + # to the person's name. + html.gsub!(/()/i, '\1\2<-- \4') if not url.match(s) + + # And in a similar fashion, remove the "Goto Page" links. + html.gsub!(/()/i,'') + + # No need to have this in the table at the bottom. + html.gsub!(/(<\/td>)/i,'') + + # Remove all the Link: rel references + html.gsub!(//,'') + + # Some phpBB sites use frames. Ugh + html.gsub!(/(/,'\10>') + html.gsub!(/()/i,'\1\2"0"\3\4"no"\6') + end + + return html end - - + # Determining what proxy, if any, should be used to load a requested URL. # # Arguments: