User:LOL/nontopcontrib.js

/** * Highlights any contributions on articles whose last edit may not have been * made by you. */

var ntc = ntc || {}; ntc.TOP = 1; ntc.NONTOP = 2;

ntc.highlighted = []; ntc.highlightColor1 = 'red'; ntc.highlightColor2 = 'purple'; ntc.yourColor = 'dodgerblue';

$(function {    // Check if this page is a list of user contributions    if (/Special(?:%3A|:)Contributions/.test(location.href)) {        /** A list of titles that we've seen. */        var status = [];        /** A list of nodes for articles that may not be (top) for you. */        var nonTop = [];

var li = document.getElementById('bodyContent') .getElementsByTagName('li'); for (var i in li) { if (!!li[i].firstChild && !!li[i].firstChild.title) { var title = li[i].firstChild.title; var isTop = false; // Search for a '(top)' node for (var j in li[i].childNodes) { if (li[i].childNodes[j].className == 'mw-uctop') { isTop = true; break; }               }

if (isTop) { status[title] = ntc.TOP; } else { if (!status[title]) { nonTop.push({node: li[i], color: ntc.highlightColor1}); status[title] = ntc.NONTOP; } else if (status[title] == ntc.NONTOP) { nonTop.push({node: li[i], color: ntc.highlightColor2}); }               }            }        }

for (var i in nonTop) { // Find history link and highlight it           for (var j in nonTop[i].node.childNodes) { var child = nonTop[i].node.childNodes[j]; if (child.tagName == 'A'                       && /&action=history$/.test(child.href)) { child.style.color = nonTop[i].color; ntc.highlighted.push(child); break; }           }        }

// Add to toolbox mw.util.addPortletLink('p-tb', 'javascript:ntc.getRecentHistory', 'Get non-top history', 't-nontophistory', 'Show recent edits to articles in the title attribute of highlighted history links', , ); } });

ntc.getRecentHistory = function { for (var i = 0; i < ntc.highlighted.length; i++) { if (ntc.highlighted[i].style.color === ntc.highlightColor1) { var url = decodeURI(ntc.highlighted[i].href).replace(/&amp;/g, '&') + '&limit=1'; var xmlhttp; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest; } else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }           xmlhttp.onreadystatechange = (function(j) {                return function {                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {                        var src = xmlhttp.responseText;                        var ph = src.indexOf('id="pagehistory">');                        var lastEdit = src.substring(ph, src.indexOf('', ph));                        var iUser = lastEdit.indexOf(' class="mw-userlink">') + 21;                        var user = lastEdit.substring(iUser, lastEdit.indexOf('', iUser));                        var iCmt = lastEdit.indexOf(' class="comment">') + 17;                        var cmt;                        if (iCmt > 15) {                            cmt = lastEdit.substring(iCmt, lastEdit.indexOf(' ', iCmt)).replace(/^\((.+?)\)$/, '$1')                                    .replace(/<\/?a[^>]*>/g, '');                        } else { cmt = ''; }                       ntc.highlighted[j].title = user + ' # ' + cmt; }               }            }(i));            xmlhttp.open('GET', url, true);            xmlhttp.send;        }    } }