User:Bradv/AjaxPatrolLinks.js

From OpenWetWare

Jump to: navigation, search

Note - After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

function ajaxPatrolLinks() {
    var a = document.evaluate('//div[@class="patrollink"]/a', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;
    if (a) {
        var div = a.parentNode;
        var url = a.href;
        a.onclick = function (event) {
            var aj = sajax_init_object();
            if (aj) {
                while (div.firstChild) { div.removeChild(div.firstChild) };
                div.appendChild(document.createTextNode('[Marking as patrolled...]'));
                aj.onreadystatechange = function () {
                    if (aj.readyState == 4 && aj.status == 200) {
                        while (div.firstChild) { div.removeChild(div.firstChild) };
                        div.appendChild(document.createTextNode('[Marked as patrolled]'));
                        aj.onreadystatechange = null;
                    }
                }                
                aj.open("GET", url, true);
                aj.send(null);
                return false;
            }
        }
    }
}
 
addOnloadHook(ajaxPatrolLinks);
Personal tools