用于自动添加Digg This!按钮的JavaScript

      2020-08-01 20:55      编程语言
复制代码 代码如下:
varmain=document.getElementById("main");
varsinglepost=false;
varfirstpost;
varanchor;
for(vari=0;i<main.childNodes.length;i++)
{
if(main.childNodes[i].className&&main.childNodes[i].className=="post")
{
varpost=main.childNodes[i];
if(!firstpost)
{
firstpost=post;
}
for(varj=0;j<post.childNodes.length;j++)
{
if(post.childNodes[j].className&&post.childNodes[j].className=="posthead")
{
varposthead=post.childNodes[j];
if(posthead.childNodes[1]&&posthead.childNodes[1].tagName&&posthead.childNodes[1].tagName=="H2")
{
if(posthead.childNodes[1].childNodes[1]&&posthead.childNodes[1].childNodes[1].tagName&&posthead.childNodes[1].childNodes[1].tagName=="A")
{
anchor=posthead.childNodes[1].childNodes[1];
}
else
{
anchor=posthead.childNodes[1].childNodes[0];
}
}
else
{
anchor=posthead.childNodes[0].childNodes[0];
}
anchor.style.fontSize="14pt";
if(anchor.className&&anchor.className=="singleposttitle")
{
singlepost=true;
}
}
}
}
}
if(singlepost)
{
varpostfoot=document.createElement("div");
firstpost.appendChild(postfoot);
postfoot.className="postfoot";
postfoot.innerHTML="<ahref=\"http://del.icio.us/post?v=4&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)+"\"><imgsrc=\http://del.icio.us/favicon.ico\alt=\"Addtodel.icio.us\"border=\"0\"/><span>Addtodel.icio.us</span></a>";
postfoot.innerHTML+="<ahref=\"http://digg.com/submit?phase=2&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)+"\"><imgsrc=\http://digg.com/favicon.ico\alt=\"DiggThis!\"border=\"0\"/><span>DiggThis!</span></a>";
postfoot.innerHTML+="<ahref=\"http://www.facebook.com/share.php?u="+encodeURIComponent(location.href)+"\"><imgsrc=\http://www.facebook.com/favicon.ico\alt=\"ShareonFacebook\"border=\"0\"/><span>ShareonFacebook</span></a>";
postfoot.innerHTML+="<ahref=\"http://www.google.com/bookmarks/mark?op=edit&bkmk="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)+"\"><imgsrc=\http://www.google.com/favicon.ico\alt=\"GoogleBookmarkThis\"border=\"0\"/><span>GoogleBookmarkThis</span></a>";
}