在Div下使用Greasemonkey添加新链接

时间:2012-11-07 10:35:30

标签: javascript greasemonkey userscripts

我想添加一个类似这些的新链接:

<a href="/profile/viewallthread/2323">More Threads by Username</a> 

添加到:

<div class="author vcard" itemscope="" itemtype="http://schema.org/Person" itemprop="author">
  <div class="user-details open" itemprop="name">
     <a href="/profile/2323" class="nickname url tools"> Username </a>
       <div class="user-info">
         <a href="/profile/2323">View Public Profile</a> 
         <a href="/profile/beafriend/2323">Add Friend</a> 
         <a href="/pm/compose/2323">Send a private message</a> 
         <a href="/profile/viewallposts/2323">More Posts by Username</a>\

         //add link here

      </div>
  </div>
</div>

userscript.js(参考:Update page to add new link using Greasemonkey

// ==UserScript==
// @name       My Fancy New Userscript
// @namespace  http://use.i.E.your.homepage/
// @version    0.1
// @description  enter something useful
// @include *.domain.com/*
// @copyright  2012+, You
// ==/UserScript==

var adduserinfo  = $("div.author vcard div.user-info > a");

adduserinfo.each (function () {
    var jThis       = $(this);
    var UserID     = jThis.attr ('href').replace (/\D+(\d+)$/, '$1');
    jThis.parent ().append ('<a href="/profile/viewallthreads/' + UserID + ' ">More Threads by ' + Username +'</a>');

} );

但没有工作.. 任何解决方案THX

1 个答案:

答案 0 :(得分:0)

multiple类的jQuery选择器是.class1.class2

即。尝试

var adduserinfo = $("div.author.vcard  div.user-info > a");

jsFiddle here

我不太确定为什么你会想foreach所有现有的a元素呢?