欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-17 13:06:40
复制代码 代码如下:var main=document.getelementbyid("main"); var singlepost=false; va...
复制代码 代码如下:

var main=document.getelementbyid("main");
var singlepost=false;
var firstpost;
var anchor;
for(var i=0;i<main.childnodes.length;i++)
{
  if(main.childnodes[i].classname&&main.childnodes[i].classname=="post")
  {
    var post=main.childnodes[i];
    if(!firstpost)
    {
      firstpost=post;
    }
    for(var j=0;j<post.childnodes.length;j++)
    {
      if(post.childnodes[j].classname&&post.childnodes[j].classname=="posthead")
      {
        var posthead=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)
{
  var postfoot=document.createelement("div");
  firstpost.appendchild(postfoot);
  postfoot.classname="postfoot";
  postfoot.innerhtml="<a href=\"http://del.icio.us/post?v=4&url="+encodeuricomponent(location.href)+"&title="+encodeuricomponent(document.title)+"\"><img src=\http://del.icio.us/favicon.ico\ alt=\"add to del.icio.us\" border=\"0\"/><span>add to del.icio.us</span></a>";
  postfoot.innerhtml+="<a href=\"http://digg.com/submit?phase=2&url="+encodeuricomponent(location.href)+"&title="+encodeuricomponent(document.title)+"\"><img src=\http://digg.com/favicon.ico\ alt=\"digg this!\" border=\"0\"/><span>digg this!</span></a>";
  postfoot.innerhtml+="<a href=\"http://www.facebook.com/share.php?u="+encodeuricomponent(location.href)+"\"><img src=\http://www.facebook.com/favicon.ico\ alt=\"share on facebook\" border=\"0\"/><span>share on facebook</span></a>";
  postfoot.innerhtml+="<a href=\"http://www.google.com/bookmarks/mark?op=edit&bkmk="+encodeuricomponent(location.href)+"&title="+encodeuricomponent(document.title)+"\"><img src=\http://www.google.com/favicon.ico\ alt=\"google bookmark this\" border=\"0\"/><span>google bookmark this</span></a>";