User:AoV2/fix image links.js

function fix_image_links { //to-do: properly discern which parts of image-page to ignore if(wgNamespaceNumber == 6) return; img = document.getElementsByTagName("img"); for(i = 0; i < img.length; i++) { pn = img[i].parentNode; // if we have no “a” element of which to change the href, create one now if(pn.nodeName != "A") { a = document.createElement("a"); a.appendChild(img[i].cloneNode(true)); pn.replaceChild(a, img[i]); }		a = img[i].parentNode; if(m = img[i].src.match(/\/[a-f0-9]\/[a-f0-9]{2}\/([^\/]+)/)) a.href = wgArticlePath.replace("$1", wgFormattedNamespaces[6] + ":" + m[1]); }	}

addOnloadHook(fix_image_links);