Skip to content

Instantly share code, notes, and snippets.

@roobie
Last active September 7, 2016 09:09
Show Gist options
  • Select an option

  • Save roobie/545dd423e47bf57eaa31 to your computer and use it in GitHub Desktop.

Select an option

Save roobie/545dd423e47bf57eaa31 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name NeverNewTab
// @description Never open a new tab if you don't want it
// @namespace http//roberg.nu/NeverNewTab
// @license WTFPL
// @include http*
// @grant none
// @version 0.0.1
// @encoding utf-8
//
// @run-at document-start
// ==/UserScript==
;(function nnt_init() {
function fix() {
var as = document.querySelectorAll('a');
[].forEach.call(as, function (a) {
if (a.target !== '') {
a.target = '';
console.debug('Anchor with href', a.href, 'wanted to open in a new tab.');
}
});
setTimeout(fix, 1000);
}
try {
var readyState = document.readyState;
if (readyState === "complete" || readyState === "loaded") {
fix();
} else {
document.addEventListener('DOMContentLoaded', fix);
}
} catch (e) {
setTimeout(nnt_init, 100);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment