nbanews Short Links Elongator

Elongates all nbanews short links to their direct links

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==

// @name          nbanews Short Links Elongator

// @namespace     DevelopmentSimplyPut(developmentsimplyput.blogspot.com)

// @description   Elongates all nbanews short links to their direct links

// @include       *

// @version 0.0.1.20141015205344
// ==/UserScript==

String.prototype.ReplaceAll = function(stringToFind,stringToReplace){
    var temp = this;
    var index = temp.indexOf(stringToFind);

        while(index != -1)
		{
            temp = temp.replace(stringToFind,stringToReplace);
            index = temp.indexOf(stringToFind);
        }
        return temp;
    }

Array.prototype.unique = function () {
	var r = new Array();
	o:for(var i = 0, n = this.length; i < n; i++)
	{
		for(var x = 0, y = r.length; x < y; x++)
		{
			if(r[x]==this[i])
			{
				continue o;
			}
		}
		r[r.length] = this[i];
	}
	return r;
}

function GetDirectLink(strArray)
{
	if(strArray.length > 0)
	{
		if(strArray[0].indexOf('dualmarket') != -1)
		{
			GM_xmlhttpRequest
			({
				method: "GET",
				url: strArray[0] + '==',
				headers:{'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey', 'Content-type':'application/x-www-form-urlencoded'},
				onload:function(result)
				{
					var link = result.responseText.split('Click Here To Get Download Link')[0];
					var temp = new Array();
					temp = link.split('<a ');
					link = temp[(temp.length)-1].replace('href=','').replace('"','').replace('"','').replace('>','');
					GetDirectLink2(strArray, link, strArray[0] + '==');
				}
			});
		}
		else
		{
			GetDirectLink2(strArray, strArray[0], strArray[0]);
		}
	}
}

function GetDirectLink2(strArray, str, strToReplace)
{
	GM_xmlhttpRequest
	({
		method: "GET",
		url: 'http://www.nbanews.us/m1.php?id=' + str.replace('http://www.nbanews.us/',""),
		headers:{'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey', 'Content-type':'application/x-www-form-urlencoded'},
		onload:function(result)
		{
			var link = result.responseText.split('onclick="NewWindow(')[1].split(',')[0].replace("'","").replace("'","");
			fromToArray.push(strToReplace + '  -->  ' + link);
			strArray.shift();
			
			if(strArray.length > 0)
			{
				GetDirectLink(strArray);
			}
			else
			{
				var doc = (document.getElementsByTagName("body"))[0].innerHTML;
				var fromStr;
				var toStr;
				for(var i=0; i< fromToArray.length; i++)
				{
					fromStr = fromToArray[i].split('  -->  ')[0];
					toStr = fromToArray[i].split('  -->  ')[1];
					doc = doc.ReplaceAll(fromStr,toStr);
				}
				(document.getElementsByTagName("body"))[0].innerHTML = doc;
			}
		}
	});
}
						
var Urls1 = new Array();
var Urls2 = new Array();
var UrlsPattern = /http:\/\/www\.nbanews\.us\/(?:\w*)/g;
Urls1 = (document.getElementsByTagName("body"))[0].innerHTML.match(UrlsPattern);
UrlsPattern = /http:\/\/www\.dualmarket\.info\/link\.php\?url=(?:\w*)/g;
Urls2 = (document.getElementsByTagName("body"))[0].innerHTML.match(UrlsPattern);
Urls1 = Urls1.concat(Urls2);
Urls1 = Urls1.unique();
var fromToArray = new Array();
GetDirectLink(Urls1);