Utilisateur:Jules*/Gadget-recentchangesbox.js
Apparence
(Redirigé depuis Utilisateur:Jules78120/Gadget-recentchangesbox.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./* New changes box */
var rcp_http;
var rcp_enabled;
var rcp_num_pages;
var rcp_refresh;
/* initalise */
function rcp_init() {
if( !document.getElementById('p-logo') ) return;
// allow user settings through
if(rcp_enabled == null) {
rcp_enabled = false;
}
if(rcp_num_pages == null) {
rcp_num_pages = 10;
}
if(rcp_refresh == null) {
rcp_refresh = 5;
}
// A few limits to be nice to the servers
if (rcp_num_pages > 50) {
rcp_num_pages = 50;
}
if (rcp_num_pages < 1) {
rcp_num_pages = 1;
}
if (rcp_refresh < 2) {
rcp_refresh = 2;
}
// get our cookie
if (document.cookie.length > 0) {
var c_start = document.cookie.indexOf("rcp_show_box=");
if (c_start != -1) {
c_start = c_start + 13;
var c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) {
c_end = document.cookie.length;
}
if (document.cookie.substring(c_start, c_end) == "yes") {
rcp_enabled = true;
} else {
rcp_enabled = false;
}
}
}
// Either make a request or show nothing
if (rcp_enabled == true) {
rcp_ajax_request();
} else {
rcp_draw_disabled_box();
}
}
/* init ajax */
function rcp_create_request() {
try {
rcp_http = new XMLHttpRequest();
} catch (e) {
try {
rcp_http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
rcp_http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser does not support AJAX");
return false;
}
}
}
rcp_http.onreadystatechange = function() {
if(rcp_http.readyState == 4) rcp_ajax_response();
}
return true;
}
/* make a request */
function rcp_ajax_request() {
// check we are enabled
if (rcp_enabled == false) return;
// firstly, inform the user
var cur_box = document.getElementById('p-recentchanges');
if (cur_box != null) {
cur_box.firstChild.firstChild.data = 'Recent Changes (updating)';
}
if (rcp_create_request () == false) {
if (cur_box != null) {
cur_box.firstChild.firstChild.data = 'Recent Changes (update failed)';
} else {
alert ("There seems to be a problem using the RecentChangePatrol script. It can't make AJAX objects.");
}
}
// Then make the request
rcp_http.open("GET", mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/api.php?action=query&list=recentchanges" +
"&format=xml&rcnamespace=0&rcshow=!patrolled|anon&rclimit=" + rcp_num_pages, true);
rcp_http.send(null);
}
/* we have received a response */
function rcp_ajax_response() {
var items = rcp_http.responseXML.getElementsByTagName('rc');
// create the div that holds all the recentchanges links
var link_div = document.createElement('div');
link_div.className = 'body pBody';
var list = document.createElement('ul');
link_div.appendChild(list);
// populate the list with 10 links.
for (var i = 0; i < items.length; i++) {
var item_name = items[i].getAttribute('title');
var item_url = mw.config.get('wgServer') + mw.config.get('wgScript') + '?diff=cur&oldid=prev&title=' + escape(item_name);
a = document.createElement('a');
a.setAttribute('href', item_url);
a.appendChild(document.createTextNode(item_name));
var li = document.createElement('li');
li.appendChild(a);
list.appendChild(li);
}
// Container div
var div = document.createElement('div');
div.setAttribute('id', 'p-recentchanges');
div.className = 'portal portlet';
div.setAttribute('role', 'navigation');
var heading = document.createElement('h3');
if( mw.config.get('skin') == 'vector' ) heading.setAttribute('style', 'display: block');
heading.appendChild(document.createTextNode('Modifications récentes'));
div.appendChild(heading);
div.appendChild(link_div);
// disable link
var p = document.createElement('p');
p.style.fontSize = 'x-small';
p.style.margin = '0px';
p.style.textAlign = 'right';
a = document.createElement('a');
a.setAttribute('style', 'cursor: pointer');
a.appendChild(document.createTextNode('désactiver cette boite'));
a.onclick = rcp_disable_box;
p.appendChild(a);
link_div.appendChild(p);
// now replace the div
var old_div = document.getElementById('p-recentchanges');
if (old_div != null) {
old_div.parentNode.replaceChild(div, old_div);
} else {
var node = document.getElementById('p-logo');
node.parentNode.insertBefore(div, node.nextSibling);
}
// and do it again in some seconds
setTimeout(rcp_ajax_request, rcp_refresh * 1000);
}
function rcp_disable_box() {
rcp_enabled = false;
rcp_draw_disabled_box();
document.cookie = "rcp_show_box=no; path=/";
}
function rcp_enable_box() {
rcp_enabled = true;
document.cookie = "rcp_show_box=yes; path=/";
rcp_ajax_request();
}
function rcp_draw_disabled_box() {
// Container div
var link_div = document.createElement('div');
link_div.className = 'body pBody';
var div = document.createElement('div');
div.setAttribute('id', 'p-recentchanges');
div.className = 'portal portlet';
div.setAttribute('role', 'navigation');
var heading = document.createElement('h3');
if( mw.config.get('skin') == 'vector' ) heading.setAttribute('style', 'display: block');
heading.appendChild(document.createTextNode('Modifications récentes'));
div.appendChild(heading);
div.appendChild(link_div);
// enable link
var p = document.createElement('p');
p.style.fontSize = 'x-small';
p.style.margin = '0px';
var a = document.createElement('a');
a.setAttribute('style', 'cursor: pointer');
a.appendChild(document.createTextNode('Activer cette boite'));
a.onclick = rcp_enable_box;
p.appendChild(a);
link_div.appendChild(p);
// now replace the div
var old_div = document.getElementById('p-recentchanges');
if (old_div != null) {
old_div.parentNode.replaceChild(div, old_div);
} else {
var node = document.getElementById('p-logo');
node.parentNode.insertBefore(div, node.nextSibling);
}
}
rcp_refresh = 10;
$( rcp_init );