Last active
September 7, 2016 09:09
-
-
Save roobie/545dd423e47bf57eaa31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==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