Jump to content

User:Quarl/show diff since.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Quarl (talk | contribs) at 22:54, 16 January 2006 (url). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// User:Quarl/show_diff_since.js - add 'since' tab to show change since I last edited
//    Compared to JesseW's, this is an asynchronous version that doesn't first open the history page

// requires: wikipage.js

// idea based on http://en.wikipedia.org/wiki/Wikipedia:WikiProject_User_scripts/Scripts/Changes_since_I_last_edited
// from http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510

// but rewritten using AJAX

// <pre><nowiki>

function addTab_DiffSince() {
    if (wikiPage.nsSpecialP) return;

    addTab('javascript:show_diff_since()', 'since', 'ca-since', "Changes since I last edited");
}

function show_diff_since() {
    var url = wikiPage.qurl + '&action=history';
    var req = new XMLHttpRequest();
    // using onload instead of onreadystatechange allows multiple asynchronous requests
    req.onload = show_diff_since_handleHistoryPage;
    req.open("GET", url, true);
    req.send(null);
}

// <li>(<a href="/w/index.php?title=ARTICLETITLE&amp;diff=35459147&amp;oldid=35392123" title="ARTICLETITLE">cur</a>) ... <span class='history-user'><a href="/wiki/User:Quarl" title="User:Quarl">Quarl</a></span>

function show_diff_since_handleHistoryPage(event) {
    var req = event.target;
    if (req.readyState == 4) {
        if ((req.status == 200)) {

            var re = '<li><a href="(/w/index.php?title=[^&"]+&amp;diff=[0-9]+&amp;oldid=[0-9]+)" title="[^"]+">cur</a>.*<span class=\'history-user\'><a href="[^"]+" title="[^"]+">'+username+'</a></span>';

            if (req.responseText.match(new RegExp(re))) {
                var url = RegExp.$1;
                document.location = url;
            } else {
                alert("Couldn't find your entry in the history page");
                // TODO: perhaps retry with a larger limit
            }
        } else {
            alert("Error downloading history page");
        }
    }
}

addOnloadHook(addTab_DiffSince);

// </nowiki></pre>