_blank Must Die For Google Apps

By cl3m Last update May 15, 2009 — Installed 475 times.

Not fully working - partial fix included

in
Subscribe to Not fully working - partial fix included 1 post, 1 voice

Archon810 User

Hey, there cl3m, thanks for initiating this. I've been annoyed at the _blank at google docs for a really long time and was meaning to make a GM script for it.

Your idea is great but it has 2 problems:
1. If you have folders that you are currently sitting in and you refresh the page, it loads in a 2-stage way, and the script only strips _blank from the first one. I've modified it to keep trying until there's no more change in the number of removed _blanks.

function kill_blank(killed) {
	var prev_killed = killed;
	var a = window.document.getElementsByTagName("a");
	var regTarget = /^(_blank|blank|_new|new|_neu|neu|_newwin|newwin)$/i;
	for (i=0;i<a.length;i++) {
		if (a[i].target.match(regTarget)) {
			killed++;
			a[i].removeAttribute("target"); 
		}
	}
	if (killed != prev_killed)
    setTimeout (function(){kill_blank(killed)}, 2000);
}
  
(function (){
	kill_blank(0);
}());

2. If you now click around other folders, without reloading the page, the script doesn't fire off because the data for the new folder is retrieved via Ajax but returns JSON, which is then parsed by Javascript locally. I can think of 2 ways of fighting this:
- jQuery with its .live() event that would monitor newly created elements in real time or
- keep the setTimeout loop going, which would burn CPU cycles.

Nevertheless, we're off to a great start here. :)

Artem
http://beerpla.net
http://twitter.com/ArtemR

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel