Hacking Gmail

(Grace) #1

Chapter 6 — Gmail and Greasemonkey 109


It is ridiculously simple, consisting simply of only one line of actual code (the rest, to


the chagrin of those of us who print on dead trees, is simply the license under which
the code is released, which has to be included). Here’s the line. Brace yourself:


location.href = location.href.replace(/^http:/, ‘https:’);


Because Gmail works via either HTTP or HTTPS, all the userscript needs to do
is make sure that every time a hyperlink starts with http:that part of the URL is


replaced with https:.


Greasemonkey does this by invoking the location.href.replacefunction.


Listing 6-3:The Ludicrously Simple GmailSecure

// GMailSecure
// version 0.3 BETA!
// 2005-06-28
// Copyright (c) 2005, Mark Pilgrim
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// -----------------------------------------------------------


//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey:
http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to “Install User
Script”.
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select “GMailSecure”, and click Uninstall.
//
// -----------------------------------------------------------


//
// ==UserScript==
// @name GMailSecure
// @namespace
http://diveintomark.org/projects/greasemonkey/
// @description force GMail to use secure connection
// @include http://mail.google.com/*
// ==/UserScript==


/* BEGIN LICENSE BLOCK


Continued
http://www.gnu.org/copyleft/gpl.html // // ----------------------------------------------------------- - Hacking Gmail - free download pdf - issuhub">
Free download pdf