August 2012 Archives

Marrying MetaCPAN to the search engine

I generally like MetaCPAN better than, but as fREW mentioned in Using AND metacpan, the latter’s search result ranking algorithm is far superior to the former’s. So fREW’s idea was to use GreaseMonkey – or actually not GreaseMonkey – to rewrite the links in search results so that he could use that site for searching, but go to MetaCPAN for everything else. In fact though, he used dotjs and took advantage of the built-in jQuery it ships with. Thus his script does not work with vanilla GreaseMonkey.

Here is a version that does. As a bonus, above and beyond fREW’s version, it also only rewrites the distribution and author links rather than just the module links.

// ==UserScript==
// @name        Marry MetaCPAN to the search engine
// @namespace
// @include*
// @version     1
// ==/UserScript==

var _rx = new RegExp('^/~([^/]+)(.*)');
var urx = new RegExp('^[^/]+)/$');
var rrx = new RegExp('^[^/]+/[^/]+)/$');
var anchors ='a[href^="/~"]'));
    var href = anchor.getAttribute('href');
    href = href.replace(_rx, function (m,p1,p2) { return '' + p1.toUpperCase() + p2 });
    href = href.replace(urx, '$1');
    href = href.replace(rrx, '$1');
    anchor.href = href;

And here it is ready to install on Share and enjoy.

About Aristotle

user-pic Waxing philosophical