Javascript Link Fixer

Converts Javascript links that open new windows into regular old links

Verze ze dne 10. 01. 2016. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name          Javascript Link Fixer
// @namespace     DoomTay
// @description   Converts Javascript links that open new windows into regular old links
// @version       1.1.1
// @grant         none

// ==/UserScript==

var links = document.querySelectorAll("a[href *= 'javascript:']");

var paramTable = {};
	paramTable["open"] = 0;

for (var l = 0; l < links.length; l++)
{
	if(links[l].href.indexOf("void") > -1) continue;
	var hrefSplitter = /javascript:(\S+)\((\S+(?:,(?: )\S+)*)?\)/.exec(links[l].href);
	if(hrefSplitter == null) continue;
	var functionName = hrefSplitter[1];
	var params = hrefSplitter[2].split(",");
	if(deconstructFunction(functionName,params) != null) links[l].href = deconstructFunction(functionName,params);
}

function deconstructFunction(functionName,params)
{
	var sourceCode = uneval(window[functionName]);
	var functionBody = sourceCode.substring(sourceCode.indexOf("{") + 1,sourceCode.indexOf("}")).trim();
	var args = /\((\S+(?:,(?: )\S+)*)?\)/.exec(sourceCode)[1].split(/\s*,\s*/);
	var containedFunctions = (/(\S+)\(/g.exec(functionBody));
	if(containedFunctions)
	{
		containedFunctions.shift();
		for(var s = 0; s < containedFunctions.length; s++)
		{
			var statementName = containedFunctions[s];
			var statementParams = new RegExp(statementName + "\\(((?:.+|\".+\"))\\)").exec(functionBody)[1];
			for(var a = 0; a < args.length; a++)
			{
				statementParams = statementParams.replace(new RegExp(" ?\\+ ?" + args[a],"g"), " + " + params[a]);
			}
			statementParams = eval("[" + statementParams + "]");
			if(paramTable.hasOwnProperty(statementName)) return(statementParams[paramTable[statementName]]);
			var digDeeper = deconstructFunction(statementName,statementParams);
			if(digDeeper) return digDeeper;
		}
	}
	else
	{
		if(functionBody.indexOf(".location = ") > -1)
		{
			var test = /\.location ?= ?(\S+);/.exec(functionBody)[1];
			for(var p = 0; p < params.length; p++)
			{
				if(test == args[p]) return params[p];
			}
		}
	}
	return null;
}