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 6201627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:35:22+00:00 2026-05-24T04:35:22+00:00

I have the following simple Greasemonkey script: // ==UserScript== // @name MetaCPAN Everywhere //

  • 0

I have the following simple Greasemonkey script:

// ==UserScript==
// @name MetaCPAN Everywhere
// @description Add to every link to CPAN a link to MetaCPAN on a Google results page.
// @namespace http://ajct.info
// @match http://*/*
// @version 0.1
// ==/UserScript==

(function() {

    var page_links = document.links;
    for (var i=0; i<page_links.length; i++){
        if (page_links[i].href.match(/http:\/\/search\.cpan\.org\/perldoc\?(.*?)$/i)) {
            var match = page_links[i].href.match(/http:\/\/search\.cpan\.org\/perldoc\?(.*?)$/i);
            var span = document.createElement("span");
            span.innerHTML = "&nbsp; <a href=\"http://www.metacpan.org/module/"+match[1]+"\">MetaCPAN</a>";
            page_links[i].parentNode.insertBefore(span, page_links[i].nextSibling);
        }
    }

})();

If I run the JavaScript snippet through firebug it does the right thing but if I install it and visit the search results page it doesn’t seem to execute the script.

It’s presumably something trivial but can anyone point out what I missed?

  • 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-05-24T04:35:23+00:00Added an answer on May 24, 2026 at 4:35 am

    The main thing is that Google ajaxes-in just about all of its results, so you need a way to wait for the first batch and to check for later batches.

    There are numerous techniques. A simple one is to use a timer:

    //--- This handles both page-load delays, and AJAX changes.
    var chkInterval = setInterval (checkForResultsLinks, 500);
    
    function checkForResultsLinks () {
        var links = document.querySelectorAll ('#search a');
        if (links) {
    
            for (var J = links.length - 1;  J >= 0;  --J) {
                var link    = links[J];
    
                if (link.weHaveProcessed) 
                    continue;
    
                if (link.href.match (/http:\/\/search\.cpan\.org\/perldoc\?(.*?)$/i) ) {
                    var match   = link.href.match (/http:\/\/search\.cpan\.org\/perldoc\?(.*?)$/i);
                    var span    = document.createElement("span");
                    span.innerHTML = "&nbsp; <a href=\"http://www.metacpan.org/module/"+match[1]+"\">MetaCPAN</a>";
                    link.parentNode.insertBefore (span, link.nextSibling);
                    link.weHaveProcessed = true;
                }
            }
        }
    }
    

    Notes:

    1. Google search results appear inside a div with the id, “search”.
    2. Best add the // @run-at document-end directive to this kind of script.
    3. The current script’s@match directive is overly broad, the script will fire on every web page!
      You probably want to restrict it to:

      // @match http://www.google.com/*
      // @match http://google.com/*
      
    4. There is no need or point to wrapping the code in an anonymous function, like: (function() { ... })(); .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following (fairly) simple JavaScript snippet that I have wired into Greasemonkey.
I have the following very simple Javascript-compatible regular expression: <script type=text/javascript id=(.+) src=([^]+)> I
I have the following simple script. <script> SPC = { a : [10], b
I have the following simple NodeJS script and want to modify it slightly.... var
I have the following simple script to make an element of my webpage fade
I have the following simple script on a page <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I have the following very simple Ext JS 4 script which is supposed to
We have the following simple Stored Procedure that runs as an overnight SQL server
I have the following simple button with an image as the template. The problem
Let's say I have the following simple enum: enum Response { Yes = 1,

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.