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-11-28 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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.1.2
// @exclude       *saucenao.com/*

// ==/UserScript==

var links = document.links;

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

var specialCases = [];
	specialCases["https://www.youtube.com/redirect"] = "q";
	
var skipList = ["http://tineye.com/search","http://saucenao.com/search.php","http://web.archive.org/web/form-submit.jsp","wayback/available"];

var archivePrefix = isInArchive ? /http:\/\/web\.archive\.org\/web\/\d{1,14}\//.exec(window.location.href) : "";

var observer = new MutationObserver(function(mutations) {
	mutations.forEach(function(mutation) {
		if(mutation.type == "attributes" && mutation.attributeName == "href") replaceURL(mutation.target);
	});    
});

var config = { attributes: true, childList: true, characterData: true };


for(var l = 0; l < links.length; l++)
{
	if(skipList.some(elem => links[l].href.indexOf(elem) > -1)) continue;
	observer.observe(links[l], config);
	replaceURL(links[l]);
}

function replaceURL(link)
{
	var testURL = URLToObject(link.href);
	if(testURL == null) return;
	if(specialCases.hasOwnProperty(testURL.base))
	{
		link.href = archivePrefix + testURL[specialCases[testURL.base]];
		return;
	}
	if(testURL.hasOwnProperty("url")) link.href = archivePrefix + testURL.url;
	else if(testURL.hasOwnProperty("URL")) link.href = archivePrefix + testURL.URL;
}

function URLToObject(url)
{
	var URLBits = {};

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

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

	for(var i = 0; i < params.length; i++)
	{
		var splitParameter = params[i].split("=");
		URLBits[splitParameter[0]] = splitParameter[1];
		while(URLBits[splitParameter[0]].indexOf("%") > -1) URLBits[splitParameter[0]] = decodeURIComponent(URLBits[splitParameter[0]]);
	}

	return URLBits;
}