Open links in current tab

Replaces target="_blank" with target="_self" on click

As of 2014-08-22. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name          Open links in current tab
// @author        wOxxOm
// @description   Replaces target="_blank" with target="_self" on click
// @namespace     http://target._blank.is.retarded
// @version       1.0
// @include       *
// ==/UserScript==

window.addEventListener('click', function(e) {
  var a = e.target;

  //search the parent A element if needed, max 10 levels up the hierarchy
  for (i=10; a.localName != 'a'; i--, a = a.parentNode)
    if (i==0 || !a.parentNode)
      return;

  if (a.getAttribute('target') == '_blank') {
    a.setAttribute('target', '_self');
    console.log('Relinked to _self: ' + a.href);
  }
});