Posted by: Brian de Alwis | October 23, 2009

Restoring workflow sanity: Working around Merx’s new “improved” linking style

Merx unhelpfully changed their linking style to use an onClick event. Such a helpful change: what used to take me a few minutes of navigating and clicking now takes four times as long. Way to go Merx!

Fortunately a bit of JavaScript, rolled up into a bookmarklet, can work around most of their damage. Just drag the “bookmarklet” link to your browser’s toolbar.

The text of the bookmarklet is here. We can’t simply rewrite every anchor as some, particularly the page count links, have to be performed using their broken NavigatePage() function.

javascript:(function(){
    var rewrite = function(node) {
	var arrLinks = node.getElementsByTagName('a');
	for(var i = 0; i < arrLinks.length; i++) {
	    var oLink = arrLinks[i];
	    if(oLink.onclick == null) { continue; }
	    var funcText = oLink.onclick.toString();
	    var start = funcText.indexOf('NavigatePage(');
	    if(oLink.href != "" || start < 0) { continue; }
	    start = funcText.indexOf('/', start);
	    var end = funcText.indexOf(')', start) - 1;
	    if(start < 0 || end < 0) { continue; }
	    oLink.href = funcText.substring(start, end);
	    oLink.onclick = null;
	}
    };
    var tbls = document.getElementsByTagName('td');
    for(var i = 0; i < tbls.length; i++) {
	if(tbls[i].className == "ContentListOdd"
	|| tbls[i].className == "ContentListEven") {
	    rewrite(tbls[i]);
	}
    }
})()

Score one for Firefox: I had a syntax error that I had great difficulty finding in Safari, whereas Firefox pointed it out immediately. But Safari’s error console has much more functionality.

Advertisements

Categories