[原]JavaScript 获得 Google PageRank
Posted | archive
<script>
alert(GetPageRank("http://www.dormforce.net"));
function GetPageRank(strUrl)
{
sURL="http://toolbarqueries.google.com/search?client=navclient-auto&ch=" + GetPR(strUrl) + "&ie=UTF-8&oe=UTF-8&features=Rank&q=info:" + encodeURIComponent(strUrl);
var xmlHttp = new ActiveXObject("msxml2.xmlhttp")
xmlHttp.open("GET",sURL,0);
xmlHttp.setRequestHeader("User-Agent","Mozilla\/4.0 (compatible; GoogleToolbar 2.0.110.4-big; Windows 2000 5.0)");
xmlHttp.send();
return(xmlHttp.responseText);
}
function GetPR(url)
{
url ="info:" + url;
ch = GoogleCH(str_asc(url));
ch = "6" + ch
return ch;
}
function str_asc(string)
{
result = new Array();
lin = string.length;
for(i=0;i<lin;i++)
{
result[i] = string.substring(i).charCodeAt(0);
}
return result;
}
function yiweitwo(a, b)
{
z = 0x80000000;
if (z & a)
{
a = (a>>1);
a &= (~z);
a |= 0x40000000;
a = (a>>(b-1));
}
else
{
a = (a>>b);
}
return a;
}
function yiwei(a,b,c)
{
a -= b; a -= c; a ^= (yiweitwo(c,13));
b -= c; b -= a; b ^= (a<<8);
c -= a; c -= b; c ^= (yiweitwo(b,13));
a -= b; a -= c; a ^= (yiweitwo(c,12));
b -= c; b -= a; b ^= (a<<16);
c -= a; c -= b; c ^= (yiweitwo(b,5));
a -= b; a -= c; a ^= (yiweitwo(c,3));
b -= c; b -= a; b ^= (a<<10);
c -= a; c -= b; c ^= (yiweitwo(b,15));
var myarray = new Array (a,b,c);
return myarray;
}
function GoogleCH(url)
{
length = url.length;
a = b = 0x9E3779B9;
c = 0xE6359A60;
k = 0;
len = length;
while(len >= 12)
{
a += (url[k+0] +(url[k+1]<<8) +(url[k+2]<<16) +(url[k+3]<<24));
b += (url[k+4] +(url[k+5]<<8) +(url[k+6]<<16) +(url[k+7]<<24));
c += (url[k+8] +(url[k+9]<<8) +(url[k+10]<<16)+(url[k+11]<<24));
mid = yiwei(a,b,c);
a = mid[0]; b = mid[1]; c = mid[2];
k += 12;
len -= 12;
}
c += length;
switch(len)
{
case 11:
{
c+=(url[k+10]<<24);
c+=(url[k+9]<<16);
c+=(url[k+8]<<8);
b+=(url[k+7]<<24);
b+=(url[k+6]<<16);
b+=(url[k+5]<<8);
b+=(url[k+4]);
a+=(url[k+3]<<24);
a+=(url[k+2]<<16);
a+=(url[k+1]<<8);
a+=(url[k+0]);
break;
}
case 10:
{
c+=(url[k+9]<<16);
c+=(url[k+8]<<8);
b+=(url[k+7]<<24);
b+=(url[k+6]<<16);
b+=(url[k+5]<<8);
b+=(url[k+4]);
a+=(url[k+3]<<24);
a+=(url[k+2]<<16);
a+=(url[k+1]<<8);
a+=(url[k+0]);
break;
}
case 9 :
{
c+=(url[k+8]<<8);
b+=(url[k+7]<<24);
b+=(url[k+6]<<16);
b+=(url[k+5]<<8);
b+=(url[k+4]);
a+=(url[k+3]<<24);
a+=(url[k+2]<<16);
a+=(url[k+1]<<8);
a+=(url[k+0]);
break;
}
case 8 :
{
b+=(url[k+7]<<24);
b+=(url[k+6]<<16);
b+=(url[k+5]<<8);
b+=(url[k+4]);
a+=(url[k+3]<<24);
a+=(url[k+2]<<16);
a+=(url[k+1]<<8);
a+=(url[k+0]);
break;
}
case 7 :
{
b+=(url[k+6]<<16);
b+=(url[k+5]<<8);
b+=(url[k+4]);
a+=(url[k+3]<<24);
a+=(url[k+2]<<16);
a+=(url[k+1]<<8);
a+=(url[k+0]);
break;
}
case 6 :
{
b+=(url[k+5]<<8);
b+=(url[k+4]);
a+=(url[k+3]<<24);
a+=(url[k+2]<<16);
a+=(url[k+1]<<8);
a+=(url[k+0]);
break;
}
case 5 :
{
b+=(url[k+4]);
a+=(url[k+3]<<24);
a+=(url[k+2]<<16);
a+=(url[k+1]<<8);
a+=(url[k+0]);
break;
}
case 4 :
{
a+=(url[k+3]<<24);
a+=(url[k+2]<<16);
a+=(url[k+1]<<8);
a+=(url[k+0]);
break;
}
case 3 :
{
a+=(url[k+2]<<16);
a+=(url[k+1]<<8);
a+=(url[k+0]);
break;
}
case 2 :
{
a+=(url[k+1]<<8);
a+=(url[k+0]);
break;
}
case 1 :
{
a+=(url[k+0]);
break;
}
}
mid = yiwei(a,b,c);
return mid[2];
}
</script>
其中ch效俭算法是参考网上ASP版的。
Comments