2012-11-07 58 views
1

我想添加類似於這些新的一個鏈接:添加新的鏈接在股利使用Greasemonkey的

<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

回答

0

jQuery選擇爲multiple類是.class1.class2

即嘗試

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

的jsfiddle here

我不太知道你爲什麼會想foreach在所有現有a元素,然而?

+0

它不工作,jsfiddle [這裏](http://jsfiddle.net/fauzi/LtwRz/) – GeekToL

+0

@KapanjadiMomod你需要選擇左側面板的jQuery工具:) - 更新小提琴[here](http ://jsfiddle.net/4gRdZ/) – StuartLC

+0

很好,它的工作,thx兄弟..:D – GeekToL