
// Offsite Blank 2
// version 0.2 BETA!
// 2005-07-08
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script that forces offsite links to
// open in a new window, where "offsite" is defined as "anything
// not on this domain."
//
// 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 "Offsite Blank 2", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          Offsite Blank 2
// @namespace     http://diveintomark.org/projects/greasemonkey/
// @description   force offsite links to open in a new window (but not links to other subdomains)
// @include       http://*
// @include       https://*
// ==/UserScript==

/* BEGIN LICENSE BLOCK
Copyright (C) 2005 Mark Pilgrim

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You can download a copy of the GNU General Public License at
http://diveintomark.org/projects/greasemonkey/COPYING
or get a free printed copy by writing to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
END LICENSE BLOCK */

var a, thisdomain, parts, aDomain, aParts, links;
thisdomain = location.host;
parts = thisdomain.split('.');
if (parts.length > 2) {
    thisdomain = [parts[parts.length - 2], parts[parts.length - 1]].join('.');
}
links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
    a = links[i];
    aDomain = a.host;
    if (!aDomain) { continue; }
    aParts = aDomain.split('.');
    if (aParts.length > 2) {
	aDomain = [aParts[aParts.length - 2], aParts[aParts.length - 1]].join('.');
    }
    if (aDomain != thisdomain) {
	a.target = "_blank";
    }
}

//
// ChangeLog
// 2005-07-08 - 0.2 - MAP - added license block
// 2005-05-16 - 0.1 - MAP - forked from Offsite Blank
//
