首页 > 开发 > JS > 正文

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

2024-09-06 12:44:10
字体:
来源:转载
供稿:网友
代码如下:
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>";
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表