Search code examples
javascriptgreasemonkeyuserscripts

Add new link Under Div using Greasemonkey


i want add one new link similar to these:

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

add to :

<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 (references : 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>');

} );

but not working.. any solutions? thx


Solution

  • The jQuery selector for multiple classes is .class1.class2

    i.e. try

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

    jsFiddle here

    I'm not quite sure why you would want to foreach over all existing a elements, however?