Utilisateur:Loiseaulybre/userwatchlist.js
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5. ///////////////////////////////////////
// User watchlist //
// by Martial75 //
///////////////////////////////////////
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 += ''
if (uwdate.getDate() < 10 ) {
tempvar += '0'
}
tempvar += uwdate.getDate()
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<lines.length; ++i) {
//myinfo.innerHTML += 'one'
if (lines[i].indexOf('<textarea') > -1) { uwinlist = 'yes'; }
if (lines[i].indexOf('</textarea') > -1) { uwinlist = 'no'; }
if (uwinlist == 'yes') {
uwpropline = lines[i];
uwnspg=uwpropline.split(':');
// eliminate all but user or user talk pages
if ((uwnspg[0] == 'Utilisateur' || uwnspg[0] == 'Discussion_Utilisateur') && 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 + '<b>stop</b>');
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 += '<li>' + uwquerystring + '</li>'
//myinfo.innerHTML += ('http://' + document.location.hostname + '/w/query.php?what=usercontribs&titles=' + uwquerystring);
//if (uwcountusers == 25) {myinfo.innerHTML += 'Pour des raisons techniques, seuls les 25 premiers utilisateurs de votre liste de suivi sont affichés';}
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 += '<span id="RCM' + uwusernum + '"><a href="javascript:toggleVisibility(\'RCI' + uwusernum + '\',\'RCM'
uwtempoutput += uwusernum + '\',\'RCL' + uwusernum + '\')"><img src="https://fr.m.wikipedia.org/skins-1.5/common/images/Arr_r.png"'
uwtempoutput += ' width="12" height="12" alt="+" /></a></span><span id="RCL' + uwusernum + '" style="display:none">'
uwtempoutput += '<a href="javascript:toggleVisibility(\'RCI' + uwusernum + '\',\'RCM' + uwusernum
uwtempoutput += '\',\'RCL' + uwusernum + '\')"><img src="https://fr.m.wikipedia.org/skins-1.5/common/images/Arr_d.png" width="12"'
uwtempoutput += ' height="12" alt="-" /></a></span><tt> </tt>'
uwtempoutput += '<a href="https://fr.m.vvikipidea.org/wiki/Utilisateur:' + uwusername + '" title="Utilisateur:' + uwusername + '">' + uwusername
uwtempoutput += '</a> (<a href="https://fr.m.vvikipidea.org/wiki/Discussion_Utilisateur:' + uwusername + '" title="Discussion_Utilisateur:' + uwusername
uwtempoutput += '">Talk</a> | <a href="https://fr.m.vvikipidea.org/w/index.php?title=Special:Contributions&target=' + uwusername
uwtempoutput += '" title="Special:Contributions">contribs</a>)' + '<br />';
uwtempoutput += '<div id="RCI' + uwusernum + '" style="display:none">'
for (uwcontribnum = 0; uwcontribnum < uwdata.pages[prop].contributions.length; ++uwcontribnum){
uwobjcontrib = uwdata.pages[prop].contributions[uwcontribnum]
uwtempoutput += '<img src="https://fr.m.wikipedia.org/skins-1.5/common/images/Arr_.png" width="12" height="12" alt=" " />'
uwtempoutput += '<tt> </tt>'
uwtempoutput += '<tt><a href="https://fr.m.vvikipidea.org/w/index.php?title=' + uwobjcontrib['*'] + '&oldid=' + uwobjcontrib.revid
uwtempoutput += '" title="' + uwobjcontrib['*'] + '">' + uwtimefromdate(uwobjcontrib.timestamp) + '</a></tt> '
uwtempoutput +='(<a href="https://fr.m.vvikipidea.org/w/index.php?title=' + uwobjcontrib['*']
uwtempoutput += '&action=history" title="' + uwobjcontrib['*'] + '">hist</a>) (<a href="https://fr.m.vvikipidea.org/w/index.php?title='
uwtempoutput += uwobjcontrib['*'] + '&diff=prev&oldid=' + uwobjcontrib.revid + '" title="' + uwobjcontrib['*']
uwtempoutput += '">diff</a>) <a href="https://fr.m.vvikipidea.org/wiki/' + uwobjcontrib['*'] + '" title="' + uwobjcontrib['*'] + '">'
uwtempoutput += uwobjcontrib['*'] + '</a> <span class="comment">(' + uwobjcontrib.comment + ')</span>' + '<br />'
}
uwtempoutput += '</div>'
++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';
uwaddToolboxLink('http://' + document.location.hostname + '/wiki/' + 'User:Martial75/watchlist', 'Suivi utilisateurs', 'uw_link');
if (mw.config.get('wgPageName') == 'Utilisateur:Martial75/watchlist') { //
var h1=document.getElementsByTagName('h1')[0]
uwloadingmsg=document.createElement('div');
h1.parentNode.appendChild(uwloadingmsg);
uwloadingmsg.innerHTML = 'Chargement...'
uwgetWatchlist()
} //
}
$(uwloadapp)