Javascript Link Fixer

Converts Javascript links that open new windows into regular old links

Stan na 10-01-2016. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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;
}