Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9312519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:39:01+00:00 2026-06-19T01:39:01+00:00

I’m having real difficulties using Greasemonkey and Firefox javascript to inject a button that,

  • 0

I’m having real difficulties using Greasemonkey and Firefox javascript to inject a button that, when selected, will execute a function.

For example, I am trying to place the button right after the “Unanswered” button on the SO “Ask a Question” page.

I wish it to run a function that will do anything, say alert ("Hello World") or console.log('TEST start'), for example.

Can someone please post up some sample code to make this work? Once I have a working sample, then I should be able to go from there.

Many thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T01:39:02+00:00Added an answer on June 19, 2026 at 1:39 am

    The process for this kind of thing is:

    1. Determine the HTML structure of the content you want to modify.
    2. Add or change your new content. Note that jQuery makes it so much easier.
    3. Add, modify, and/or delete javascript event listeners for your new content.
    4. if the target content is added via AJAX methods, use AJAX-compensating techniques.

    For your example page:

    Inspecting with Firebug shows that the Unanswered “button” HTML looks like this:

    <div class="nav mainnavs">
      <ul>
        ...
        <li>
          <a href="/unanswered" id="nav-unanswered">Unanswered</a>
        </li>
      </ul>
    </div>
    

    So we will add a “button” like this:

    <div class="nav mainnavs">
      <ul>
        ...
        <li>
          <a href="/unanswered" id="nav-unanswered">Unanswered</a>
        </li>
        <li>
          <a href="#" id="gmOurFirstButton">Log something</a>
        </li>
      </ul>
    </div>
    

    We’ll activate it with jQuery’s .click().

    For this page and this button, we do not need to worry about AJAX.

    Putting it all together, a complete working script looks like:

    // ==UserScript==
    // @name     _Add a simple button to a page
    // @include  https://stackoverflow.com/questions/ask*
    // @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
    // @grant    GM_addStyle
    // ==/UserScript==
    /*- The @grant directive is needed to work around a design change
        introduced in GM 1.0.   It restores the sandbox.
    */
    var unansweredBtn   = $("#nav-unanswered");
    
    //-- Add our button.
    unansweredBtn.parent ().after (
        '<li><a href="#" id="gmOurFirstButton">Log something</a></li>'
    );
    
    //-- Activate the button.
    $("#gmOurFirstButton").click ( function () {
        console.log ("Something.");
    } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am using JSon response to parse title,date content and thumbnail images and place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.