Utilisateur:Dr Brains/LiveContribs.js
Apparence
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.if(
(mw.config.get('wgCanonicalSpecialPageName')=="Contributions")
||
(mw.config.get('wgCanonicalSpecialPageName')=="Recentchanges")
||
((mw.config.get('wgCanonicalSpecialPageName')=="Watchlist")&&(document.URL.indexOf('edit')==-1)&&(document.URL.indexOf('raw')==-1))
){
addOnloadHook(LiveContribs);
}
if(typeof(LiveContribs_Timeout)=="undefined")
var LiveContribs_Timeout = 15;
function LiveContribs(){
var Fieldset = document.getElementsByTagName('fieldset')[0];
if(!Fieldset) return;
var InputChecked = '';
var LiveContribsCookieDelay = LiveContribs_getCookie("LiveContribsDelay");
if((!LiveContribsCookieDelay)||(LiveContribsCookieDelay=="false")||(LiveContribsCookieDelay=="NaN")){
//alert('Pas Cookie délai : ' + LiveContribsCookieDelay);
LiveContribs_setCookie("LiveContribsDelay", LiveContribs_Timeout);
LiveContribsCookieDelay = LiveContribs_Timeout;
}
var LiveContribsCookie = LiveContribs_getCookie("LiveContribs");
if(LiveContribsCookie=="true"){
InputChecked = ' checked="checked" ';
var All = Fieldset.getElementsByTagName('*');
for(var a=0;a<All.length;a++){
if(All[a].tagName.toLowerCase()!="legend") All[a].style.display = 'none';
}
}
var NewP = document.createElement('p');
NewP.innerHTML = '<input id="LiveContribs_On" type="checkbox" ' + InputChecked + ' ></input>'
+ ' <label for"LiveContribs_On" >Activer ou désactiver le rafraichissement automatique</label> ';
NewP.innerHTML += '<input id="LiveContribs_Delay" type="text" value="' + parseInt(LiveContribsCookieDelay) + '" size="3" ></input>'
+ ' <label for"LiveContribs_Delay" >Délai de rafraichissement (en secondes, mini = 5)</label> ';
Fieldset.appendChild(NewP);
setTimeout("LiveContribs_Update();", LiveContribs_Timeout * 1000);
}
function LiveContribs_Update(){
var Input = document.getElementById('LiveContribs_On');
var InputDelay = document.getElementById('LiveContribs_Delay');
if((!Input)||(!InputDelay)) return;
var Delay = parseInt(InputDelay.value);
if(Delay<5) Delay=5;
LiveContribs_setCookie("LiveContribsDelay", Delay);
if(Input.checked){
LiveContribs_setCookie("LiveContribs", "true");
document.location = document.URL;
return;
}else{
LiveContribs_setCookie("LiveContribs", "false");
}
setTimeout("LiveContribs_Update();", Delay * 1000);
}
// * Mise à jour du cookie *
function LiveContribs_setCookie (cookieName, cookieValue) {
var now = new Date();
var nextYear = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 365 );
document.cookie = escape(cookieName) + '=' + escape(cookieValue) + '; EXPIRES=' + nextYear.toGMTString() + "; PATH=/" ;
}
// * Interrogation du cookie *
function LiveContribs_getCookie(cookieName) {
var cookieValue = "false";
var posName = document.cookie.indexOf(escape(cookieName) + '=' );
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=' ).length;
var endPos = document.cookie.indexOf(';', posValue) ;
if (endPos != -1) {
cookieValue = unescape(document.cookie.substring(posValue, endPos));
} else {
cookieValue = unescape(document.cookie.substring(posValue));
}
}
return cookieValue;
}