Monday, May 04, 2009

Create a popup bookmarklet

#buildbookmarklet.py
#
#Create a popup bookmarklet from some html content.
#
#eg.
#echo "<h1>Hello World</h1>" | python bookmarklet.py > out.html
#

import sys
import urllib
import optparse

usage = "python buildbookmarklet.py [options]"
parser = optparse.OptionParser(usage=usage)

parser.add_option("-l""--length", type="int", dest="height",
                  default=150, help="The height of the popup window.")
parser.add_option("-w""--width", type="int", dest="width",
                  default=350, help="The width of the popup window.")
parser.add_option("-t""--title", type="string", dest="title",
                  default='Bookmarklet',
                  help="The title of the bookmarklet.")
(options, args) = parser.parse_args()


s = ('my_window= window.open ("","win","status=1,width=%i,height=%i");'
    'my_window.document.write(%s);'
     (options.width, options.height, repr(sys.stdin.read())))


print """
<html>
<a href="
javascript:%s">%s</a>
</html>
"
"" % (urllib.quote(s), options.title)

0 Comments:

Post a Comment

<< Home