Wikipedia:WikiProject User scripts/Scripts/Changes since I last edited

/* Description and credits:

This script adds a "since" tab to your view. Clicking on this will call up a DIFF showing all edits since you last edited the page. The number of revisions to check back can be set, and if ignored, will default to the number of revisions in your history view.

From http://en.wikipedia.org/w/index.php?title=User:JesseW/monobook.js&oldid=20755510
with updates for IE compatibility and functionality.


Usage:

To use the default number of revisions:

importScript('Wikipedia:WikiProject User scripts/Scripts/Changes since I last edited'); 

or to set your own default number of revisions to check:

defaultdiffs = 1000;    // or whatever number, see script for details
importScript('Wikipedia:WikiProject User scripts/Scripts/Changes since I last edited'); 

Copy to → your monobook.js


The script:

*/

function addSinceTab() {

    // Default number of revisions to check. Set to 0 to use your usual default for a history page.
    // Sensible options might be 300, 500 or 750. Values up to 5000 are valid, but will be quite slow.

    if (!window.defaultdiffs) defaultdiffs = 0;

    if (window.location.href.indexOf("&action=history&gotosince=true") != -1) {
        do_since_I_last_edited()
    } else if (mw.config.get('wgCanonicalNamespace') != "Special") {
        mw.util.addPortletLink("p-cactions", mw.config.get('wgScript') + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=history&gotosince=true" + ((defaultdiffs <= 0) ? "" : "&limit=" + defaultdiffs), 'since', '', "all changes since your last edit");
    }
}

function do_since_I_last_edited() {
    var csub = document.getElementById("contentSub");
    var msg = document.createElement("p");
    if (!csub || !msg) return;

    msg.appendChild(document.createTextNode("Parsing history... please wait..."));
    msg.className = "error";
    csub.insertBefore(msg, csub.firstChild)

    var hists = document.getElementById("pagehistory").getElementsByTagName('li');
    for (n = 0; n < hists.length; n++) {
        var userlink = $(hists[n]).find('.mw-userlink');
        if (userlink.length > 0 && userlink[0].innerHTML == mw.config.get('wgUserName')) {
            var histlinks = $(hists[n]).find('.mw-history-histlinks');
            if (histlinks.length > 0) {
                var histlinkas = histlinks[0].getElementsByTagName("a");
                if (histlinkas.length > 1) {
                    document.location = histlinkas[0].href;
                } else {
                    msg.replaceChild(document.createTextNode("You are the last editor. "), msg.firstChild);
                }
            }

            return;
        }
    }

    msg.replaceChild(document.createTextNode("You have not edited this page! (recently).  Look at more edits? "), msg.firstChild);

    var lookharderA = document.createElement("A");
    lookharderA.href = mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=history&gotosince=true&limit=1000';
    lookharderA.innerHTML = '1000';

    msg.appendChild(lookharderA);

    msg.appendChild(document.createTextNode(" "));

    lookharderA = document.createElement("A");
    lookharderA.href = mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=history&gotosince=true&limit=2500';
    lookharderA.innerHTML = '2500';

    msg.appendChild(lookharderA);

    msg.appendChild(document.createTextNode(" "));

    lookharderA = document.createElement("A");
    lookharderA.href = mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=history&gotosince=true&limit=5000';
    lookharderA.innerHTML = '5000';

    msg.appendChild(lookharderA);
}

$(addSinceTab);

// 

//