Hack #16. Remove URL Redirections

Cut out the middleman and make links point directly to where you want to go.

Many portal sites use redirection links for links that point to other sites. The link first goes to a tracking page on the portal, which logs your click and sends you on your way to the external site. Not only is this an invasion of privacy, but it's also slower, since you need to load the tracking page before you are redirected to the page you actually want to read. This hack detects such redirection links and converts them to direct links that take you straight to the final destination.

The Code

This user script runs on all pages, except for a small list of pages where it is known to cause problems with false positives. It uses the document.links collection to find all the links on the page and checks whether the URL of the link includes another URL within it. If it finds one, it extracts it and unescapes it, and replaces the original URL.

Save the following user script as nomiddleman.user.js:

	// ==UserScript==
	// @name        NoMiddleMan
	// @namespace   http://0x539.blogspot.com/
	// @description Rewrites URLs to remove redirection scripts
	// @include     *
	// @exclude		http://del.icio.us/*
	// @exclude     http://*bloglines.com/*
	// @exclude		http://web.archive.org/*
	// @exclude		http://*wists.com/*
	// ==/UserScript==

	// based on code by Albert Bachand
	// and included here with his gracious permission
	// http://kungfoo.webhop.org/nomiddleman.user.js

	for (var i=0; i<document.links.length; i++) ...

Get Greasemonkey Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.