Results tagged “meta.search.cpan.org”

MetaCPAN-on-search.cpan.org update

I’ve uploaded a new version of the GreaseMonkey script I introduced in my last entry (to let you use search.cpan.org for searching but with links to MetaCPAN in the search results).

This version is updated for GreaseMonkey 1.0, and also includes a small link at the top right of a search results page which links to the same search on MetaCPAN:

var query = document.querySelector('input[type=text]').value;
if (query) {
    document.querySelector('.t4 small').insertAdjacentHTML('beforeend',' <a id="goto-metacpan">&#x2192; MetaCPAN</a>');
    var link = document.getElementById('goto-metacpan');
    var href = 'https://metacpan.org/search?q=' + encodeURIComponent(query);
    link.href = href.replace(/%20/g,'+');
    link.style.setProperty('float','right');
    link.style.setProperty('padding-right','.4em');
    link.style.setProperty('color','inherit');
}

Easily installable from userscripts.org. Share and enjoy.

Marrying MetaCPAN to the search.cpan.org search engine

I generally like MetaCPAN better than search.cpan.org, but as fREW mentioned in Using search.cpan.org 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.cpan.org 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.cpan.org search engine
// @namespace   http://plasmasturm.org/
// @include     http://search.cpan.org/search?*
// @version     1
// ==/UserScript==

var _rx = new RegExp('^/~([^/]+)(.*)');
var urx = new RegExp('^https://metacpan.org/module/([^/]+)/$');
var rrx = new RegExp('^https://metacpan.org/module/([^/]+/[^/]+)/$');
var anchors = Array.prototype.slice.call(document.querySelectorAll('a[href^="/~"]'));
anchors.forEach(function(anchor){
    var href = anchor.getAttribute('href');
    href = href.replace(_rx, function (m,p1,p2) { return 'https://metacpan.org/module/' + p1.toUpperCase() + p2 });
    href = href.replace(urx, 'https://metacpan.org/author/$1');
    href = href.replace(rrx, 'https://metacpan.org/release/$1');
    anchor.href = href;
});

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

1

About Aristotle

user-pic Waxing philosophical