yahavatar / Yah's GM Linkchecker

// ==UserScript==
// @name			Yahs GM Linkchecker
// @namespace		yahs.gmlinkchecker
// @description		yahs GM Link Checker
// @include			http://yahavatar.com/*
// @include			http://*thecavernforum.com/*
// @grant			GM_addStyle
// @grant			GM_getValue
// @grant			GM_xmlhttpRequest
 
// @downloadURL		https://openuserjs.org/install/yahavatar/Yahs_GM_Linkchecker.user.js
// @updateURL		https://openuserjs.org/install/yahavatar/Yahs_GM_Linkchecker.user.js
// @version			0.2.5
// ==/UserScript==

if (window.top != window.self){  return; }	//don't run on frames or iframes
console.log("yah's Link Checker - Version 0.2.5");

//  2014.01.11 - 0.1.3 - Zippyfile live_file match string needed changed.
//  2017.01.16 - 0.2.0 - Made a bunch of changes. Cleaned up some code. For Cavern per Brian.
//  2017.01.17 - 0.2.1 - Change filescdn.com rule per Brian.
//  2017.01.17 - 0.2.3 - Change filefactory.com rule per Brian. Showing every link green!
//  2016.01.24 - 0.2.4 - mod to facilitate yellow maybe condition for filefactory.com Server Load Too high + addition file hosts added.
//  2016.01.25 - 0.2.5 - added hosts 1ficher and share108, revised solidfiles yellow to green, rg yellow to pink, unlimitedzone yellow to pink, bigfile yellow to pink 


//	Hosts
//	[0] name to categorize links
//	[1] search string to hit on
//	[2] file_is_alive search string
//	[3] file_is_dead search string -- Sometimes it's easier to match on these
//	[4] file_is_maybe search string -- Represents different statuses [converting, folder, etc]
var hosts = new Array();

hosts.push(["rapidgator.net",	    "https?:\/\/(www\.)*rapidgator\.net",		 "Downloading:","",""]);
hosts.push(["rarefile.net",		    "https?:\/\/(www\.)*rarefile\.net",			 "Download File","",""]);
hosts.push(["rapidfileshare.net",	"https?:\/\/(www\.)*rapidfileshare\.net",	 "Download File","",""]);
hosts.push(["unlimitzone.com",	    "https?:\/\/(www\.)*unlimitzone\.com",	     "Filename.","File Not Found",""]);
hosts.push(["tusfiles.net",		    "https?:\/\/(www\.)*tusfiles\.net",		     "btn_download","",""]);
hosts.push(["uploaded.net",		    "https?:\/\/(www\.)*(uploaded\.net|ul\.to)", "Download file:","Error: 404",""]);
hosts.push(["uploaded.to",		    "https?:\/\/(www\.)*uploaded\.to",           "Download file:","",""]);
hosts.push(["uploadable.ch",	    "https?:\/\/(www\.)*uploadable\.ch",	     "","no longer available",""]);
hosts.push(["zippyshare.com",	    "https?:\/\/(www[\\d]*\.)*zippyshare\.com",  "You have requested the file:","does not exist","Try Again"]);
hosts.push(["workupload.com",       "https?:\/\/(www\.)*(workupload\.com)",      "btn", "File Not Found",""]);
hosts.push(["nitroflare.com",       "https?:\/\/(www\.)*(nitroflare\.com)",      "Report this file", "File doesn't exist",""]);
hosts.push(["mediafire.com",        "https?:\/\/(www\.)*(mediafire\.com)",       "", "Invalid or Deleted File",""]);
hosts.push(["filescdn.com",         "https?:\/\/(filescdn\.com)",                "btn_download",""]);
hosts.push(["solidfiles.com",       "https?:\/\/(www\.)*(solidfiles\.com)",      "Download", "The page you were looking for appears to no longer be there",""]);
hosts.push(["userscloud.com",	    "https?:\/\/(userscloud\.com)",              "Download at", "",""]);
hosts.push(["rg.to",                "https?:\/\/(rg\.to)",                       "Downloading:", "File not found</",""]);
hosts.push(["alfafile.net",         "https?:\/\/alfafile\.net",                  "", "this page does not exist",""]);
hosts.push(["bigfile.to",           "https:\/\/(www\.)*bigfile\.to",             "file_name","This file is no longer available.","",]);
hosts.push(["mega.co.nz",           "https:\/\/(mega\.co\.nz)",                  "download-button","","",]);
hosts.push(["mega.nz",              "https:\/\/(mega\.nz)",                      "download","","",]);
hosts.push(["turbobit.net",         "https?:\/\/(www\.)*(turbobit\.net)",        "Download file", "Searching for the file",""]);
hosts.push(["cloudshares.net",      "https?:\/\/cloudshares\.net",               "", "File Not Found",""]);
hosts.push(["rockfile.eu",          "https?:\/\/rockfile\.eu",                   "", "File Not Found",""]);
hosts.push(["depositfiles.com",     "https?:\/\/depositfiles\.com",              "", "This file does not exist",""]);
hosts.push(["uploadrocket.net",     "https?:\/\/uploadrocket\.net",              "", "The file was removed by administrator",""]);
hosts.push(["datafile.com",         "https?:\/\/(www\.)*(datafile\.com)",        "", "error-msg",""]);
hosts.push(["unibytes.com",         "https?:\/\/(www\.)*(unibytes\.com)",        "", "File not found",""]);
hosts.push(["hugefiles.net",        "https?:\/\/hugefiles\.net",                 "btn", "",""]);
hosts.push(["1fichier.com",         "https?:\/\/(www\.)*1fichier\.com",          "Access to Download", "File Not Found",""]);
hosts.push(["share108.com",         "https?:\/\/(www\.)*share108\.com",          "File:", "", ""]);
//console.log("Hosts added");

//Build a concatenated string of all hosts
var allHostsMatch = "";
for (var i = 0; i < hosts.length; i++){
    //console.log(i);
	allHostsMatch = allHostsMatch + hosts[i][1];
	if (i < hosts.length - 1){allHostsMatch = allHostsMatch + "|";}
}
//console.log(allHostsMatch);
allHostsMatch = new RegExp(allHostsMatch, "gi");		//Turn the concatenated string into a RegExp
//console.log("Here!");
//console.log("AllHostsMatch: " + allHostsMatch);

////////////////////////////////////////////////////////////////////////////////////////////////////////
//    Read Preferences
////////////////////////////////////////////////////////////////////////////////////////////////////////
var pref_link_color_dead = GM_getValue("link_color_dead", "lightPink"); if(pref_link_color_dead == ""){pref_link_color_dead = "lightPink"};
var pref_link_color_live = GM_getValue("link_color_alive", "paleGreen"); if(pref_link_color_live == ""){pref_link_color_live = "paleGreen"};
var pref_link_color_maybe = GM_getValue("link_color_maybe", "yellow"); if(pref_link_color_maybe == ""){pref_link_color_maybe = "yellow"};
var pref_linkify = GM_getValue("linkify", true);

//Old Prefs
var pref2 = GM_getValue("highlight_full_link", true);
var pref5 = GM_getValue("flag_bad_image_hosts", true);
var pref6 = GM_getValue("flag_redirectors", true);
var pref8 = GM_getValue("flag_mouseover_mode", false);

////////////////////////////////////////////////////////////////////////////////////////////////////////
//    Inline Images + GM Styles
////////////////////////////////////////////////////////////////////////////////////////////////////////
var png_dead = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBI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AWhh+U1fLO4tbKztdJIvHsw/1NR7/97pJBOR9tDXc+6rMGsg4vkd3AhkMdVJgLounkdKLHdL1S13ZpdyMzbK5pnNF0I0mNn4r3Ze3AJrZvo0zL8KkPyil6rTOgipFzrRezLXVt4zWKtBbwWjIeTgyEQlHiUhepcBpNkSaYehxX20Yw2HYd3VYP6iNRYhrpAeojGfJqvs7rRIyKGpSUGOm4iYgWwX7wB72ps/hWXMZCbgaNkUYQrseUr3SNB0JQRj0DBnSlYWN/DcfNEzifuYzVvS94vf4cVeoiBB2ScY8IiBBnytk7KM5XG8qj9SRClrbnUKNVZKLNWMjPwKkWkYk146BSUbZrz0PC0ZuHzaBYLokq9S90p3pMJRnJl35gtfgZQnAko0lY4WY1+2lu63s+N0EE+agXXrkydc3czjtF7noHXccSx82mWIY0hBpgRVMIalK9WX67tfJzfZJo5EVuouAdieh4kk3KQA21J1rGmuoy/UToMSG5t+vaC5u/7Smikenc04LzHyMAaH+cNcBVGgyWClSIgHAA+2DYy00Wjuz9Bce5MucW9xnuAAAAAElFTkSuQmCC';
var png_maybe = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAOxJREFUeNqMkk8OwVAQxr+276kdCfuegGOIBTfgBhYsxAlIRMQJxAXEQl2EG5QLdFlSHTO0/raYZPLevPl+ne+lzwBgxEmyHsPcGW9hq5PNS8S9kPem4sKKDyIRuGvCxgU87wY0mgD3jk9wqGLg/nUBKlWg1QZ8HxgNCYc9MJ4YV5jBnOgsLigrlytNSql7LQNN8YkfUSg+9qwPzG9iudegT+h0jNdGlq3pTFOprKjb0x+9TEjuMV/o1N5Xe46Tfi5mNdMn/Bnyr8z4JXxEvUbYbVO5SKAz0+rPKVqg5N0lE8VqkCLOizjJiwADACqhr7BunfI1AAAAAElFTkSuQmCC';
var png_redirector = 'data:image/png;base64,iVBORw0KGgoAAAANSU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pPm/wSng+IrckpvRTjLI95dmylyS7e6WTz3SeATBfQHeWE+s9KtqpFzTtIyslKTfwszk/H7mWmQtUkc0gzx2bCBeA06z3K8TkB9A57FAi6AN8NKzaDYt/azdZmApDTyHxGgZmWF/ObpyzvbwJZN0ztS615PlFodw/CD+Jf4KckWoAyXR4iaRBvr1wtYVCor63QhZUlJEKBGi0PAWw08epsAxW/5YyY1fZeoyiVpqZUaOedkKzV3oyqr4FwXlZXkP6hT6xsXOCKeI92Cd2kF723C5zJ3ewLeeNxKzZAsbf+F7W6zP/ojeR4ymFeguxnB58M2Q5YWFqHuxqhaX8LKVIybqK2kxi+rzwVGU6NUo0b+XK7PgP/Ex6flGTr10g6q9PmVB/C9bdrPd4mlSx0pbHZwf8lVqUmBkxJT8Aqlq/DVUbOR030ROkLb6w7yprp9SkdtBPcJ+HkCalaEqTksoOkbaSLjBmzLzNbveYqL8LBB8gr4cXStA/DiAuLm4V1LaQWNjbTtG03N79pgtxGfZWb4KMQWzDDI9Apo8TNHa1bNo0oAnQI6deSeCnJ8V6XmLrPd3FoBmSpRqml5oEyA90nJeBCy402NrNPKHIiZmsBhyZM+iwVKIz0S+/6pMEfFUWrt/5ctBWFyjwhoveJpD12o0DP8vHoylGq0UhKXCBj+QPDn/7DbT9zNJlnKsvZTOCZLn5wX48ctbGq2UvNSCsYcU4FbTlChXqYE8Tj1tcmukciAfveGtPzUbKiV3z3DjGj5qLl4ubZ/Fwk3WxgQe+A4gWfDGzsooErxCikGCTkC7HeYeTLvxJgdpdaHv2m3haab/V0zfehPq8c8GIVz1MuiVA+nvycpLJD2Q2L56xhzw5ZUu5nhRm3xHuBpFXidlRpLkQk/VrnY0Ssewzsl3VexR07e81rWGtPd5P8brl4S1pGBp33y251MxLWsNaav/wG6GRXYoAbWagAAAABJRU5ErkJggg=='

GM_addStyle(".link_dead  {background:" + pref_link_color_dead + " url(" + png_dead + ") no-repeat scroll 100% 50%;padding-left:2px;padding-right:17px;}");
GM_addStyle(".link_live  {background:" + pref_link_color_live + " url(" + png_live + ") no-repeat scroll 100% 50%;padding-left:2px;padding-right:17px;}");
GM_addStyle(".link_maybe {background:" + pref_link_color_maybe + " url(" + png_maybe + ") no-repeat scroll 100% 50%;padding-left:2px;padding-right:17px;}");

//if (pref_linkify) linkify();
linkify();
	
var URL = window.location.toString();
	
	//Test some match strings
	//console.log("M1: " + URL.search(/nothing/gi));
	
//console.log("URL: " + URL + " = " + URL.search(allHostsMatch));
if (URL.search(allHostsMatch)== -1){				//If current page is a filehost page, do not process any links
	//console.log("	Preparing to process links...");
		
	//Try to use pure javascript to find links
	var x=document.getElementsByTagName("a");
	//console.log("Links found pure javascript: " + x.length);
	for (var i = 0; i < x.length; i++) {
		var link = x[i].href;
		if (link.search(allHostsMatch) > -1){
			//console.log("Filehost Link found: " + link);
			linkcheck_generic(x[i]);
		}
	}
}

function linkcheck_generic(dom_link){
	var link = dom_link.href;
	//console.log("	linkcheck_generic(" + link + ")");
	GM_xmlhttpRequest({
		method: "get",
		url: link,
		headers: {"Content-type": "application/x-www-form-urlencoded"},
		onload: function(result) {
		    res = result.responseText;
		    //console.log(res);
		    //console.log("------------------------------------------------------------------------------------------");
			
			//See if the link refers to a supported filehost
			//console.log("Hosts.length: " + hosts.length);
			for (var i = 0; i < hosts.length; i++){
				//console.log("		" + hosts[i][0]);
				//console.log(link + " : " + link.search(hostMatchStr));
				var hostMatchStr = new RegExp(hosts[i][1], "gi");
				if (link.search(hostMatchStr) > -1){
					//console.log("			Domain Match: " + hostMatchStr);
					//dom_link.parent().addClass("	link_maybe");									//Mark link yellow to indicate known domain and being checked
					dom_link.className = "link_maybe";		//;	// = 'link_maybe';
					//console.log("	After link_maybe");
					var link_is_live = new RegExp(hosts[i][2], "gi");
					var link_is_dead = new RegExp(hosts[i][3], "gi");
					var link_is_maybe = new RegExp(hosts[i][4], "gi");
					
					//console.log(res);
					//console.log("	link_is_live: " + link_is_live);
					//console.log("	link_is_dead: " + link_is_dead);
					//console.log("	link_is_maybe: " + link_is_maybe);
					
					//console.log("	link_is_live? " + res.search(link_is_live));
					//console.log("	link_is_dead? " + res.search(link_is_dead));

		            //if (link_is_dead != '/(?:)/gi' && res.search(link_is_dead) > -1){
		            if (hosts[i][3] != "" && res.search(link_is_dead) > -1){
		            	//console.log("			link_dead: " + link);
		                //dom_link.parent().removeClass("link_maybe").addClass("link_dead");
		                dom_link.className = "link_dead";
		            //} else if (link_is_live != '/""/gi' && link_is_live != "" && res.search(link_is_live) > -1){
		            } else if (hosts[i][2] != "" && res.search(link_is_live) > -1){
		            	//console.log("			link_live: " + link);
		                //dom_link.parent().removeClass("link_maybe").addClass("link_live");
		                dom_link.className = "link_live";
		            //} else {																	//Unknown link
		        } else if (hosts[i][4] != "" && res.search(link_is_maybe) > -1){
		            	//console.log("			maybe_link: " + link);
		            	//dom_link.parent().removeClass("link_maybe").addClass("link_dead");
		            	dom_link.className = "link_maybe";
		            }
				} else {
					//console.log("	totally unknown_link: " + link);
		            //dom_link.parent().removeClass("link_maybe").addClass("link_dead");
		            //dom_link.className = "link_dead";
				}
			}

		}
	});
}
function linkify(){
	//console.log("linkify()");
    try{
        var regex = /((?:https?|ftp):\/\/[^\s'"'<>()]*|[-\w.+]+@(?:[-\w]+\.)+[\w]{2,6})/gi;
        //var regex_exclude_html_trunc = /http:\/\/uploading\.com|http:\/\/letitbit.net|http:\/\/www\.gshare\.com|http:\/\/netload\.in/gi;
        var regex_ends = /\.rar\.html\b/gi;
        var mail_addr = /\@/;
        var altText, txt, muligtLink;
        var OKTags = ['a', 'head', 'script', 'style', 'title', 'option', 'textarea'];
        var path = "//text()[not(parent::" + OKTags.join(" or parent::") +")]";
        altText = document.evaluate(path, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
        for(var i=0;i<altText.snapshotLength;i++){
            txt = altText.snapshotItem(i);
            muligtLink = txt.nodeValue;
            
            if(regex.test(muligtLink)){            	
                var span = document.createElement('span');
                var lastLastIndex = 0;
                regex.lastIndex = 0;
                
                //GM_log("muligtLink: " + muligtLink);
                
                for(myArray = null; myArray = regex.exec(muligtLink); ){
                    var link = myArray[0];
                    
                    //GM_log("link: " + link);
                    
                    if (mail_addr.test(link)){0
						//Do Nothing
                    } else {
                        span.appendChild(document.createTextNode(muligtLink.substring(lastLastIndex, myArray.index)));
                        var href = link;	
                        
                        //GM_log("href: " + href);                        
                        
                        var prefix = '';
                        if(href.length > 7){
                            prefix = href.substring(0,7);
                            if(prefix.toLowerCase() != 'http://' && prefix.toLowerCase() != 'https:/'){
                                href = 'http://' + href;
                            }
                        }
                        //Fix links that end in .rar.html
                        //if (href.search(regex_exclude_html_trunc) == -1){
                            if (href.search(regex_ends) != -1){
                                href = href.substr(0, href.length - 5);
                            }
                        //}
                        var a = document.createElement('a');
                        a.setAttribute('href', href);
                        var orig_href = href;
                        a.appendChild(document.createTextNode(href));
                        span.appendChild(a);
                        lastLastIndex = regex.lastIndex;
                    }
                }
                span.appendChild(document.createTextNode(muligtLink.substring(lastLastIndex)));
                txt.parentNode.replaceChild(span, txt);
            }
        }
    } catch(e){alert(e);}
}