Utilisateur:Delhovlyn/testExist.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.var A = new XMLHttpRequest();
A.onreadystatechange = function(e)
{
if (!e) var e = window.event;
if (this.readyState == 4)
{
document.body.style.cursor = "default";
if (this.status == 200)
{
var docXML = this.responseXML;
var texteTitre = document.getElementById('textIfExist');
if (docXML.getElementsByTagName('page')[0].getAttribute('missing') == '')
{
texteTitre.style.color='red';
texteTitre.style.fontWeight='normal';
texteTitre.style.fontStyle='normal';
texteTitre.title="Cet article n'existe pas";
}
else
{
document.getElementById('textIfExist').style.color='green';
if (docXML.getElementsByTagName('redirects').length > 0)
{
texteTitre.style.fontStyle='italic';
texteTitre.style.fontWeight='normal';
texteTitre.title='Cet article est une redirection';
if (e.keyCode == 13)
{
texteTitre.value = docXML.getElementsByTagName('r')[0].to;
A.open(mw.config.get('wgServer') + '/w/api.php?action=query&format=xml&redirects&titles=',texteTitre.value);
A.send(null);
}
}
else
{
texteTitre.style.fontStyle='normal';
texteTitre.style.fontWeight='bold';
texteTitre.title='Cet article existe';
}
}
}
} else
{
document.body.style.cursor = "progress";
}
}
function keyUp(e)
{
if (!e) var e = window.event;
if (this.value !== '') // && e.keyCode == 13
{
A.open('GET', mw.config.get('wgServer')+'/w/api.php?action=query&format=xml&redirects&titles='+document.getElementById('textIfExist').value, true);
A.send(null);
}
}
function a()
{
var li = document.createElement("li");
li.innerHTML = '<input id="textIfExist" title="Rouge : article inexistant ; Vert italique : redirection ; Vert gras : article existant." '
+ 'type="text" style="width:95%; font-size:90%; font-weight:normal; color:gray;" value="Titre d’article" '
+ 'onfocus="if(this.value==\'Titre d’article\') this.value=\'\';" '
+ 'onblur="if(this.value==\'\') {this.value=\'Titre d’article\'; this.style.color = \'grey\'; this.style.fontWeight = \'normal\'; this.style.fontStyle = \'normal\';}"/></li>';
document.getElementById('p-tb').getElementsByTagName('ul')[0].appendChild(li);
document.getElementById('textIfExist').onkeyup = keyUp;
}
addOnloadHook(a);