1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-10-05 04:24:03 -04:00
elinks/contrib/python/hooks.py

61 lines
1.7 KiB
Python
Raw Normal View History

import re
2006-09-02 06:07:29 -04:00
import sys
dumbprefixes = {
"7th" : "http://7thguard.net/",
2006-09-02 06:07:29 -04:00
"b" : "http://babelfish.altavista.com/babelfish/tr/",
"bz" : "http://bugzilla.elinks.cz/",
"bug" : "http://bugzilla.elinks.cz/",
"d" : "http://www.dict.org/",
"g" : "http://www.google.com/",
"gg" : "http://www.google.com/",
"go" : "http://www.google.com/",
"fm" : "http://www.freshmeat.net/",
"sf" : "http://www.sourceforge.net/",
"dbug" : "http://bugs.debian.org/",
"dpkg" : "http://packages.debian.org/",
"pycur" : "http://www.python.org/doc/current/",
"pydev" : "http://www.python.org/dev/doc/devel/",
"pyhelp" : "http://starship.python.net/crew/theller/pyhelp.cgi",
"pyvault" : "http://www.vex.net/parnassus/",
"e2" : "http://www.everything2.org/",
"sd" : "http://www.slashdot.org/"
}
2006-09-02 06:07:29 -04:00
cygwin = re.compile("cygwin\.com")
cygwin_sub1 = re.compile('<body bgcolor="#000000" color="#000000"')
2006-09-02 06:18:27 -04:00
cygwin_sub2 = '<body bgcolor="#ffffff" color="#000000"'
2006-09-02 06:26:55 -04:00
mbank = re.compile('^https://www\.mbank\.com\.pl/ib_navibar_3\.asp')
2006-09-02 06:07:29 -04:00
mbank_sub1 = re.compile('<td valign="top"><img')
2006-09-02 06:18:27 -04:00
mbank_sub2 = '<tr><td valign="top"><img'
2006-09-02 06:07:29 -04:00
google_redirect = re.compile('^http://www\.google\.com/url\?sa=D&q=(.*)')
def goto_url_hook(url, current_url):
global dumbprefixes
if dumbprefixes.has_key(url):
return dumbprefixes[url];
else:
return None
def follow_url_hook(url):
2006-09-02 06:07:29 -04:00
m = google_redirect.search(url)
if m:
return m.group(1)
return None
def pre_format_html_hook(url, html):
2006-09-02 06:07:29 -04:00
if cygwin.search(url):
2006-09-02 06:18:27 -04:00
html2 = cygwin_sub1.sub(cygwin_sub2, html)
return html2
2006-09-02 06:07:29 -04:00
if mbank.search(url):
2006-09-02 06:18:27 -04:00
html2 = mbank_sub1.sub(mbank_sub2, html)
2006-02-06 10:03:08 -05:00
return html2
return None
def proxy_for_hook(url):
return None
def quit_hook():
return None