URL Stripper

Takes offsite links that stick the original URL into an onsite link with extra parameters and changes the href to that original URL.

2015-10-11 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

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

You will need to install an extension such as Tampermonkey 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.

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

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

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          URL Stripper
// @namespace     DoomTay
// @description   Takes offsite links that stick the original URL into an onsite link with extra parameters and changes the href to that original URL.
// @version       1.0.2

// ==/UserScript==

var links = document.links;

var isInArchive = window.location.hostname == "web.archive.org";

for(var l = 0; l < links.length; l++)
{
	if(URLToObject(links[l].href) == null) continue;
	var archivePrefix = isInArchive ? /http:\/\/web\.archive\.org\/web\/\d{1,14}\//.exec(window.location.href) : "";
	if(URLToObject(links[l].href).hasOwnProperty("url")) links[l].href = archivePrefix + URLToObject(links[l].href)["url"];
	else if(URLToObject(links[l].href).hasOwnProperty("URL")) links[l].href = archivePrefix + URLToObject(links[l].href)["URL"];
}

function URLToObject(url)
{
	var URLBits = new Object();

	var splitURL = url.split("?");

	if(splitURL[1] == undefined) return null;
	var params = splitURL[1].split("&");

	for(var i = 0; i < params.length; i++)
	{
		var splitParameter = params[i].split("=");
		if(ArrayOccurence(params,splitParameter[0]).length > 1)
		{
			var keyList = [];
			for(var o = 0; o < ArrayOccurence(params,splitParameter[0]).length; o++)
			{
				var newValue = ArrayOccurence(params,splitParameter[0])[o].split("=")[1];
				keyList.push(newValue);
			}
			URLBits[splitParameter[0]] = keyList;
		}
		else
		{
			if(!isNaN(parseInt(params[i][1]))) URLBits[splitParameter[0]] = parseInt(splitParameter[1]);
			else URLBits[splitParameter[0]] = splitParameter[1];
		}
	}

	return URLBits;
}

function ArrayOccurence(array,key)
{
	var newArray = [];
	for(var i = 0; i < array.length; i++)
	{
		if(array[i].indexOf(key) > -1) newArray.push(array[i])
	}
	return newArray;
}