mirror of
https://github.com/rkd77/elinks.git
synced 2024-10-04 04:14:18 -04:00
Lots of updates to hooks.rb
[jf: Merged from http://starshine.org/xteddy/thomas/elinks/hooks.rb]
This commit is contained in:
parent
685cb8d1a2
commit
1951009a2d
@ -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 <thomas.adam22@gmail.com>
|
||||
# -----
|
||||
|
||||
# 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 <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
|
||||
# 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 class=\"example\">)(.*?)(<\/p>)/, '<h2><font color="red">\2</font></h2>')
|
||||
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!(/<link rel.*? \/>/,'')
|
||||
|
||||
# Turn on borders for the "main" table.
|
||||
html.gsub!(/(<table class=\"forumline\".*border=)(\".*?\")(.*?>)/,'\11\3')
|
||||
|
||||
# In the LHS of the table for each postee, remove their image
|
||||
# link, and just display their status instead.
|
||||
html.gsub!(/(<span class=\"postdetails\">.*?)(<img src.*? \/>)/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!(/(<img src.*?)(alt=)(\"Reply With Quote\")\s*(title=\"reply with quote\")(.*? \/>)/i, '\1\2Q \4')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"edit\/delete this post\")\s*(title=\"edit\/delete this post\")(.*? \/>)/i, '\1\2E/D \4')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"delete this post\")\s*(title=\"delete this post\")(.*? \/>)/i, '\1\2D \4')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"post\")\s*(title=\"post\")(.*? \/>)/i, '\1\2--> \4')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"new post\")\s*(title=\"new post\")(.*? \/>)/i, '\1\2--> \4')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"view newest post\")\s*(title=\"view newest post\")(.*? \/>)/i, '\1\2--> \4')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"view latest post\")\s*(title=\"view latest post\")(.*? \/>)/i, '\1\2<-- \4')
|
||||
|
||||
|
||||
# See above.
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"view ip address of poster\")\s*(title=\"view ip address of poster\")(.*? \/>)/i, '\1\2IP />')
|
||||
html.gsub!(/<table cellspacing=\"0\" cellpadding=\"0\"\s*border=\"0\"\s*height="18"\s*width=\"18\">/, '<table border="0">')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"view user\'s profile\")\s*(title=\"view user\'s profile\")(.*? \/>)/i, '\1\2Profile />')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"send private message\")\s*(title=\"send private message\")(.*? \/>)/i, '\1\2PM />')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"send e-mail\")\s*(title=\"send e-mail\")(.*? \/>)/i, '\1\2email />')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"visit poster\'s website\")\s*(title=\"visit poster\'s website\")(.*? \/>)/i, '\1\2Web /> ')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"Yahoo Messenger\")\s*(title=\"Yahoo Messenger\")(.*? \/>)/i, '\1\2Yahoo />')
|
||||
html.gsub!(/(<img src.*?)(alt=)(\"Msn Messenger\")\s*(title=\"Msn Messenger\")(.*? \/>)/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!(/(<table.*border=)(\".*?\")\s*class=\"forumline\"\s*(.*?>)/,'\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!(/(<td class=\"row1\".*?)>(<img src.*No new posts.*>)/, '\1 bgcolor="red"> </td>')
|
||||
html.gsub!(/(<td class=\"row1\".*?)>(<img src.*new posts.*>)/i, '\1 bgcolor="green"> </td>')
|
||||
|
||||
# These lines appear at the bottom of the pages as a kind of "key"
|
||||
# for the above changes.
|
||||
html.gsub!(/(<img src.*\"No new posts\".*\>)/,"<font color=\"red\">No New Posts</font></td>")
|
||||
html.gsub!(/(<img src.*\"New posts\".*\>)/,"<font color=\"green\">New Posts</font></td>")
|
||||
|
||||
# Remove duplicate lines within the HTML that would otherwise
|
||||
# repeat the same thing. (Damn annoying)
|
||||
html.gsub!(/<td><span class=\"gensmall\">([nN]o)|[Nn]ew posts\<\/span\>\<\/td\>/,"<td></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!(/(<td class=\"row1\".*?)>(<img src.*locked.*>)/i, '\1 bgcolor="blue"> </td>')
|
||||
|
||||
# Orange indicates that the selected thread has moved.
|
||||
html.gsub!(/(<td class=\"row1\".*?)>(<img src.*moved.*>)/i, '\1 bgcolor="orange"> </td>')
|
||||
|
||||
# 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 class=\"gensmall\">(.*?<\/td>|<img src.*?><\/td>))/,'')
|
||||
html.gsub!(/(<td.*?>)(<img src.*alt=\"(Sticky|Announcement|.*Popular.*)\".* \/><\/td>)/i, '')
|
||||
html.gsub!(/(<td.*?>)(<img src.*alt=\"Forum is locked\" \/><\/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!(/(<img src.*?)(alt=)(\"view (newest|latest) post\")\s*(title=\"view (newest|latest) post\")(.*? \/>)/i, '\1\2<-- \4') if not url.match(s)
|
||||
|
||||
# And in a similar fashion, remove the "Goto Page" links.
|
||||
html.gsub!(/(<img src.*?alt=\"goto page\".*? \/>)/i,'')
|
||||
|
||||
# No need to have this in the table at the bottom.
|
||||
html.gsub!(/(<td class=\"row1\".*?><img src.*alt=\"who is online\".* \/><\/td>)/i,'')
|
||||
|
||||
# Remove all the Link: rel references
|
||||
html.gsub!(/<link rel.*? \/>/,'')
|
||||
|
||||
# Some phpBB sites use frames. Ugh
|
||||
html.gsub!(/(<table width=\"100%\" cellpadding=\"4\" cellspacing=\"1\" border=)1>/,'\10>')
|
||||
html.gsub!(/(<frameset.*?)(border=)\"2\"(.*)(frameborder=)\"(.*?)\"(.*>)/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:
|
||||
|
Loading…
Reference in New Issue
Block a user