Javascript Link Fixer

Converts Javascript links that open new windows into regular old links

Version vom 10.01.2016. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name          Javascript Link Fixer
// @namespace     DoomTay
// @description   Converts Javascript links that open new windows into regular old links
// @version       1.1.0
// @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 arguments = /\((\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 < arguments.length; a++)
			{
				statementParams = statementParams.replace(new RegExp(" ?\\+ ?" + arguments[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 == arguments[p]) return params[p];
			}
		}
	}
	return null;
}