// ==UserScript==
// @name          	No Blank Download Tab
// @author	  	abc@home
// @description   	Do not open blank tab when download file or open file in other application
// @description0x0804  	在下载文件或在其他程序打开文件时不打开空白标签
// @include       	*
// @injectframes  	1
// @run-at	  	document_start
// ==/UserScript==

(function(){
	document.attachEvent('onmousedown', checkLink);
	function checkLink(){
		var oElem=event.srcElement;
		while(oElem.tagName!='A' && oElem.tagName!='AREA' && oElem.parentElement){
			oElem=oElem.parentElement;
			if(oElem.tagName=='BODY') break;
		}
		if(oElem.tagName=='A'||oElem.tagName=='AREA'){
      			var sDownloadLinks=/\.(zip|rar|7z|cab|gz|lzh|exe|rm|rma|rmv|rmvb|avi|wmv|wma|mp3|mpg|torrent|m2p|m2f|m2s|m2l)$|act=attach|view=att|attachment|addons.maxthon.*?download/i;
			if(oElem.href.search(sDownloadLinks)!=-1) oElem.target='_self';
		}
	}
})();
