Jump to content

User:Quarl/newmessages.js

From Wikipedia, the free encyclopedia
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/newmessages.js]] - annotate the "You have new messages" alert
// to add "diff since" and "hist" links.

// requires: wikipage.js, diffsince.js, util.js

// quarl 2006-01-16 initial version

// <pre><nowiki>

var newmessages = new Object();

newmessages._load = function() {
    var talkmessagebox = getElementsByClass('usermessage',document.getElementById('bodyContent'),'div')[0];
    if (!talkmessagebox || talkmessagebox.textContent != "You have new messages (diff).") return;

    newmessages.wpTalk = new WikiPage(null,'User talk:' + wikiDoc.username);
    var histUrl = newmessages.wpTalk.qurl + '&action=history';
    var diffSinceUrl = diffsince.makeUrl(newmessages.wpTalk);

    talkmessagebox.className += ' plainlinks';

    var t = (' (<span id="newmessages-diffsince">' +
             '<a onclick="javascript:return newmessages.diffSince()" href="'+diffSinceUrl+'">' +
             'diff since</a></span>)' +
             ' (<a href="'+histUrl+'">history</a>)');

    // insert before final period
    talkmessagebox.innerHTML = talkmessagebox.innerHTML.replace(/(?=[.]$)/, t);
}

newmessages.diffSince = function() {
    return diffsince.diffPageAsync(newmessages.wpTalk,
                            document.getElementById('newmessages-diffsince'),
                            '<b>diff since...</b>');
}

$(newmessages._load);

// </nowki></pre></nowiki></pre>