Single left click tab opener

By Jasper de Vries Last update Mar 8, 2006 — Installed 21,974 times.
// ==UserScript==
// @name           Single left click tab opener
// @namespace      http://browservulsel.blogspot.com
// @description    v0.1.0.2 - Open links in new tab by keeping the left mouse button down for half a second
// @include        *
// ==/UserScript==

/*

	Author: Jasper de Vries, jepsar@gmail.com
	Date:   2006-03-08

*/

var timeOut = 500; // msec to wait

var as = document.getElementsByTagName('a');
for (var i = 0, a; a = as[i]; i++) {
	if (a.hasAttribute('href') && ! a.href.match(/^javascript:/i)) {
		new TabOpener(a);
	}
}

function TabOpener(a) {
	var timer = null;
	var opened = false;

	var openLinkInTab = function() {
		GM_openInTab(a.href);
		opened = true;
	}

	var mousedownHandler = function(e) {
		if (e.button == 0) {
			timer = setTimeout(openLinkInTab, timeOut);
		}
	}

	var clickHandler = function(e) {
		clearTimeout(timer);
		if (opened) {
			e.preventDefault();
			opened = false;
		}
	}

	a.addEventListener('mousedown', mousedownHandler, false);
	a.addEventListener('click', clickHandler, false);
}