User:John Vandenberg/since.js

//

if( typeof( SinceConfig ) == 'undefined' ) {

SinceConfig = function() {};

}

if( typeof( SinceConfig.historyRevisions ) == 'undefined' ) {

SinceConfig.historyRevisions = 0;

}

if( typeof( SinceConfig.updateWatchlist ) == 'undefined' ) {

SinceConfig.updateWatchlist = 0;

}

if( typeof( SinceConfig.growthRate ) == 'undefined' ) {

SinceConfig.growthRate = 1000;

}

if( typeof( SinceConfig.editWatchlistTalkLinks ) == 'undefined' ) {

SinceConfig.editWatchlistTalkLinks = 0;

}

function addSinceTab() {

if (window.location.href.indexOf("&action=history&gotosince=true")!=-1) {

do_since_I_last_edited()

}

else if (wgCanonicalNamespace != "Special") {

url = "/w/index.php?title="+wgPageName+"&action=history&gotosince=true";

if (SinceConfig.historyRevisions)

url += '&limit=' + SinceConfig.historyRevisions;

addPortletLink("p-cactions", url, 'since', '', "since");

}

}

function historyNextPageURL() {

var historyNav = document.getElementById("historysubmit").parentNode.nextSibling;

for (i=0;i<16;i++) {

if (historyNav.tagName && historyNav.tagName == 'A') {

if (historyNav.innerHTML.indexOf('next') != -1) {

return historyNav.href;

}

}

if (historyNav.nextSibling) {

historyNav = historyNav.nextSibling;

}

else {

return;

}

}

}

function do_since_I_last_edited() {

var csub=document.getElementById("contentSub");

var msg=document.createElement("p");

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

if (hists[n].getElementsByTagName("span")[0].getElementsByTagName('a')[0].innerHTML==wgUserName) {

document.location=hists[n].childNodes[1].href;

return;

}

}

var url = historyNextPageURL();

var offset;

var limit;

if (url) {

offset = /offset=([0-9]*)/.exec(url);

limit = /limit=([0-9]*)/.exec(url);

}

if (offset) offset = offset[1];

if (limit) limit = limit[1];

text = "You have not edited this page";

if (!url) {

text += ' since it was created!';

}

else if (limit) {

text += ' in the last ' + limit + ' revisions.';

}

else {

text += ' (recently)!';

}

msg.replaceChild(document.createTextNode(text), msg.firstChild);

if (!url) return;

if (!limit) limit = SinceConfig.growthRate;

msg.appendChild(document.createTextNode(' Click '));

var n = document.createElement("A");

n.href = url;

n.innerHTML = 'next';

msg.appendChild(n);

var url = wgServer + '/w/index.php?title=' + wgPageName +

'&action=history&gotosince=true' +

'&offset='+offset;

msg.appendChild(document.createTextNode(', or increase search to '));

var lookharderA = document.createElement("A");

lookharderA.href = url + '&limit=' + (limit * 2);

lookharderA.innerHTML = (limit * 2);

msg.appendChild(lookharderA);

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

lookharderA = document.createElement("A");

lookharderA.href = url + '&limit=' + (limit * 4);

lookharderA.innerHTML = (limit * 4);

msg.appendChild(lookharderA);

msg.appendChild(document.createTextNode(' revisions.'));

}

$(addSinceTab);

function addSinceWatchlistLinks()

{

if (wgCanonicalNamespace == 'Special' &&

wgCanonicalSpecialPageName == 'Watchlist' &&

SinceConfig.updateWatchlist == 1) {

var bodyContent = document.getElementById('bodyContent');

var as = bodyContent.getElementsByTagName('a');

var currentNode;

var k = 0;

var text;

var tn;

var link;

for (n=0; n < as.length; n++) {

currentNode = as[n];

text=currentNode.innerHTML;

if (text == 'hist' || text == 'Page history' || text == 'History') {

k++;

tn = document.createTextNode(text == 'History' ? ' | ' : '; ');

link = document.createElement('a');

link.href = currentNode.href + '&gotosince=true';

if (SinceConfig.historyRevisions)

link.href += '&limit=' + SinceConfig.historyRevisions;

link.appendChild(document.createTextNode(text == 'History' ? 'Since' : 'since'));

currentNode.parentNode.insertBefore(link , currentNode);

/* as is extended when we add a "A" element, so skip it */

n++;

currentNode.parentNode.insertBefore(tn , currentNode);

if (text == 'Page history') {

currentNode.innerHTML = 'hist';

}

if (SinceConfig.editWatchlistTalkLinks && text == 'History') {

currentNode.parentNode.appendChild( document.createTextNode( ' (' ) );

// Move the Talk: link

var mn = link.previousSibling.previousSibling;

currentNode.parentNode.appendChild( mn );

currentNode.parentNode.removeChild( link.previousSibling );

currentNode.parentNode.appendChild( document.createTextNode( ': ' ) );

// Create a Talk: 'History' link

var history = document.createElement('a');

text = currentNode.href;

history.href = text.replace(/title=/,'title=Talk:');

history.appendChild(document.createTextNode('History'));

// Create a Talk: 'Since' link

var since = document.createElement('a');

since.href = history.href + '&gotosince=true';

if (SinceConfig.historyRevisions)

since.href += '&limit=' + SinceConfig.historyRevisions;

since.appendChild(document.createTextNode('Since'));

currentNode.parentNode.appendChild( since);

currentNode.parentNode.appendChild( document.createTextNode( ' | ' ) );

currentNode.parentNode.appendChild( history );

currentNode.parentNode.appendChild( document.createTextNode( ')' ) );

n+=2; // skip newly added Since and History links

}

}

}

}

}

$(addSinceWatchlistLinks);

//