User:Ilmari Karonen/whatlinkshere2checkusage.js

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
if (wgCanonicalNamespace == "Special" && wgCanonicalSpecialPageName.toLowerCase() == "whatlinkshere") {
    addOnloadHook(function () {
        var target = document.getElementById("mw-whatlinkshere-target")
        if (!target || !/^(Image|File):/i.test(target.value)) return

        var imageName = target.value.replace(/^(Image|File):/i, "")

        var link = document.createElement("a")
        link.href = "http://toolserver.org/~daniel/WikiSense/CheckUsage.php?i=" + encodeURIComponent(imageName) + "&w=_100000"
        link.appendChild(document.createTextNode("check usage on other wikis"))

        var para = target.parentNode.parentNode;
        while (para.nextSibling && !/^p$/i.test(para.tagName))
            para = para.nextSibling

        para.appendChild(document.createTextNode(" ("))
        para.appendChild(link)
        para.appendChild(document.createTextNode(")"))
    })
}