User:Elsendero/uwlmodified.js

// test mod version of Tra script

function uwdownload(bundle) {

// mandatory: bundle.url

// optional: bundle.onSuccess (xmlhttprequest, bundle)

// optional: bundle.onFailure (xmlhttprequest, bundle)

// optional: bundle.otherStuff OK too, passed to onSuccess and onFailure

var x = window.XMLHttpRequest ? new XMLHttpRequest()

: window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP")

: false;

if (x) {

x.onreadystatechange=function() {

if ( x.readyState==4 ) { uwdownloadComplete(x,bundle); }

};

x.open("GET",bundle.url,true);

x.send(null);

}

return x;

}

function uwdownloadComplete(x,bundle) {

if (x.status==200) { bundle.onSuccess(x,bundle); } else { bundle.onFailure(x,bundle); alert(x.statusText);}

}

function uwgetstartdate(uwdate) {

var tempvar = ''

if (navigator.userAgent.indexOf("Firefox")!=-1){

tempvar = uwdate.getYear() + 1900

} else {

tempvar = uwdate.getYear()

}

tempvar += ''

if ((uwdate.getMonth() + 1) < 10 ) {

tempvar += '0'

}

tempvar += (uwdate.getMonth() + 1)

tempvar += ''

// mod

if ((uwdate.getDate() - 1) < 10 ) {

tempvar += '0'

}

tempvar += (uwdate.getDate() - 1) // mod

tempvar += '000000'

return tempvar

}

window.gettingWatchlist=false;

uwwatchlist=null;

function uwgetWatchlist() {

window.gettingWatchlist=true;

uwdownload({url: 'http://' + document.location.hostname + '/wiki/Special:Watchlist?action=raw',

onSuccess: uwprocessWatchlist, onFailure: function () {

setTimeout(uwgetWatchlist, 15000); return true; }});

}

function uwprocessWatchlist(req, bundle) {

var watchlist={};

var lines=req.responseText.split('\n');

var h1=document.getElementsByTagName('h1')[0]

var myinfo=document.createElement('ul');

h1.parentNode.appendChild(myinfo);

var uwnspg = ''

var uwinlist = 'no'

var uwpropline = ''

var uwdonestart = 'no'

var uwquerystring = ''

var uwcountusers = 0

var uwnow = new Date()

var h1=document.getElementsByTagName('h1')[0]

var uwoutput=document.createElement('div');

h1.parentNode.appendChild(uwoutput);

uwoutput.innerHTML = '';

for (var i=0; i

//myinfo.innerHTML += 'one'

if (lines[i].indexOf(' -1) { uwinlist = 'yes'; }

if (lines[i].indexOf(' -1) { uwinlist = 'no'; }

if (uwinlist == 'yes') {

uwpropline = lines[i];

uwnspg=uwpropline.split(':');

// eliminate all but user or user talk pages

if ((uwnspg[0] == 'User' || uwnspg[0] == 'User talk') && uwpropline.split('/')[0]==uwpropline && uwcountusers <25) {

if (uwdonestart == 'yes') {uwquerystring += '|'}

uwdonestart = 'yes'

uwquerystring += 'User:' + uwnspg[1]

uwcountusers += 1

if (uwcountusers == 25) {

//send and process stuff

uwquerystring += '&uclimit=20&ucstart=' + uwgetstartdate(uwnow) + '&uccomments&format=json&dummy=' + parseInt(Math.random()*99999999)

//myinfo.innerHTML += ('http://' + document.location.hostname + '/w/query.php?what=usercontribs&titles=' + uwquerystring + 'stop');

uwdownload({url: 'http://' + document.location.hostname + '/w/query.php?what=usercontribs&titles=' + uwquerystring,

onSuccess: function (req, bundle) { uwoutput.innerHTML += uwprocessuserwatchlist(req.responseText) ; if (typeof(window.setupTooltips)!='undefined') { setupTooltips(uwoutput); } }});

uwcountusers = 0

uwquerystring = ''

uwdonestart = 'no'

}

}

}

}

uwquerystring += '&uclimit=20&ucstart=' + uwgetstartdate(uwnow) + '&uccomments&format=json&dummy=' + parseInt(Math.random()*99999999)

// myinfo.innerHTML += '

  • ' + uwquerystring + '
  • '

    //myinfo.innerHTML += ('http://' + document.location.hostname + '/w/query.php?what=usercontribs&titles=' + uwquerystring);

    //if (uwcountusers == 25) {myinfo.innerHTML += 'For performance reasons, only the first 25 users on your watchlist are shown.';}

    uwdownload({url: 'http://' + document.location.hostname + '/w/query.php?what=usercontribs&titles=' + uwquerystring,

    onSuccess: function (req, bundle) { uwoutput.innerHTML += uwprocessuserwatchlist(req.responseText) ; if (typeof(window.setupTooltips)!='undefined') { setupTooltips(uwoutput); } ; uwloadingmsg.innerHTML = ''; }});

    // at very end

    // uwoutput.innerHTML = uwtempoutput;

    // if (typeof(window.setupTooltips)!='undefined') { setupTooltips(uwoutput); }

    // uwloadingmsg.innerHTML = ''

    }

    function uwmid(str, start, len)

    /***

    IN: str - the string we are LEFTing

    start - our string's starting position (0 based!!)

    len - how many characters from start we want to get

    RETVAL: The substring from start to start+len

    ***/

    {

    // Make sure start and len are within proper bounds

    if (start < 0 || len < 0) return "";

    var iEnd, iLen = String(str).length;

    if (start + len > iLen)

    iEnd = iLen;

    else

    iEnd = start + len;

    return String(str).substring(start,iEnd);

    }

    function uwtimefromdate(uwdate) {

    return uwmid(uwdate, 11, 5)

    }

    // function uwuwprocessuserwatchlist

    function uwprocessuserwatchlist(uwrsp) {

    // alert(uwrsp);

    // uwoutput.innerHTML += uwrsp

    var uwtempoutput = ''

    var uwdata = eval('(' + uwrsp + ')');

    var uwusernum = Math.random()*99999999;

    var uwcontribnum = 0;

    var uwobjcontrib

    var uwusername

    uwtempoutput += '';

    // uwtempoutput += uwdata.pages.length;

    // uwtempoutput += uwdata.pages.items[0].title;

    for (prop in uwdata.pages) {

    if (uwdata.pages[prop].contributions.length > 0) {

    uwusername = uwdata.pages[prop].title.split(':')[1]

    uwtempoutput += '

    uwtempoutput += ' width="12" height="12" alt="+" />

    uwtempoutput += '

    uwtempoutput += ' height="12" alt="-" />           '

    uwtempoutput += '' + uwusername

    uwtempoutput += ' (Talk | contribs)' + '
    ';

    uwtempoutput += '

    '

    ++uwusernum

    }

    }

    uwtempoutput += '';

    return uwtempoutput

    }

    // **************************************************

    // Installation

    // **************************************************

    function uwaddlilink(tabs, url, name, id, title, key){

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

    na.href = url;

    na.appendChild(document.createTextNode(name));

    var li = document.createElement('li');

    if(id) li.id = id;

    li.appendChild(na);

    tabs.appendChild(li);

    if(id) {

    if(key && title) ta[id] = [key, title];

    else if(key) ta[id] = [key, ''];

    else if(title) ta[id] = ['', title];

    }

    // re-render the title and accesskeys from existing code in wikibits.js

    akeytt();

    return li;

    }

    function uwaddToolboxLink(url, name, id){

    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];

    uwaddlilink(tb, url, name, id);

    }

    var uwloadingmsg

    function uwloadapp() {

    //var h1=document.getElementsByTagName('h1')[0]

    // var uwoutput=document.createElement('div');

    //h1.innerHTML = 'User watchlist (mod)';

    uwaddToolboxLink('http://' + document.location.hostname + '/wiki/' + 'User:Elsendero/uwlmodified', 'User watchlist (mod)', 'uw_link_mod');

    if (wgPageName == 'User:Elsendero/uwlmodified') { //

    var h1=document.getElementsByTagName('h1')[0]

    uwloadingmsg=document.createElement('div');

    h1.parentNode.appendChild(uwloadingmsg);

    uwloadingmsg.innerHTML = 'Loading...'

    uwgetWatchlist()

    } //

    }

    addOnloadHook(uwloadapp)