Disable Targets For Downloads

By JoeSimmons Last update Oct 19, 2008 — Installed 264 times.

There are 2 previous versions of this script.

// ==UserScript==

// @name Disable Targets For Downloads

// @namespace http://www.rhyley.org/

// @description  Doesn't open a new window on links to binary files

// @include      http://*
// @include      https://*

// ==/UserScript==



// based on code by Jason Rhyley

// and included here with his gracious permission



// Add other file extensions here as needed

var oExp = new RegExp("(\.zip|\.rar|\.exe|\.tar|\.jar|\.xpi|\.gzip|" +

    "\.gz|\.ace|\.bin|\.ico|\.jpg|\.gif|\.pdf)$", "i");

var snapLinks = document.evaluate("//a[@onclick] | //a[@target]",

document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);



for (var i = 0; i < snapLinks.snapshotLength; i++) {

var elmLink = snapLinks.snapshotItem(i);

if (elmLink.href && oExp.exec(elmLink.href)) {

elmLink.target = '';

elmLink.addEventListener('click', function(e) {

    e.stopPropagation();

e.preventDefault();

}, true);

}

}